Source:
private void getAndAssertSuccess() throws Exception { final CountDownLatch readCompleteLatch = new CountDownLatch(1); final AtomicReference<Exception> readCompleteException = new AtomicReference<>(null); final AtomicLong readCompleteResult = new AtomicLong(0); final AtomicReference<Exception> operationException = new AtomicReference<>(null); Callback<ReadableStreamChannel> callback = new Callback<ReadableStreamChannel>() { @Override public void onCompletion(final ReadableStreamChannel result, final Exception exception) { if (exception != null) { operationException.set(exception); readCompleteLatch.countDown(); } else { Utils.newThread(new Runnable() { @Override public void run() { assertSuccess(result, readCompleteLatch, readCompleteResult, readCompleteException); } }, false).start(); } } }; operationsCount.incrementAndGet(); GetBlobOperation op = new GetBlobOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobIdStr, operationFuture, callback, operationCompleteCallback, time); ArrayList<RequestInfo> requestListToFill = new ArrayList<>(); requestRegistrationCallback.requestListToFill = requestListToFill; while (!op.isOperationComplete()) { op.poll(requestRegistrationCallback); List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill); for (ResponseInfo response : responses) { op.handleResponse(response); } } readCompleteLatch.await(); Assert.assertTrue("Operation should be complete at this time", op.isOperationComplete()); Assert.assertNull("Operation exception should be null, was:" + operationException.get(), operationException.get()); Assert.assertNull("Read complete exception should be null", readCompleteException.get()); Assert.assertEquals("Size read must equal size written", blobSize, readCompleteResult.get()); }

Target:
private void getAndAssertSuccess() throws Exception { final CountDownLatch readCompleteLatch = new CountDownLatch(1); final AtomicReference<Exception> readCompleteException = new AtomicReference<>(null); final AtomicLong readCompleteResult = new AtomicLong(0); final AtomicReference<Exception> operationException = new AtomicReference<>(null); Callback<ReadableStreamChannel> callback = new Callback<ReadableStreamChannel>() { @Override public void onCompletion(final ReadableStreamChannel result, final Exception exception) { if (exception != null) { operationException.set(exception); readCompleteLatch.countDown(); } else { Utils.newThread(new Runnable() { @Override public void run() { assertSuccess(result, readCompleteLatch, readCompleteResult, readCompleteException); } }, false).start(); } } }; operationsCount.incrementAndGet(); GetBlobOperation op = new GetBlobOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobIdStr, operationFuture, callback, operationCompleteCallback, blobIdFactory, time); ArrayList<RequestInfo> requestListToFill = new ArrayList<>(); requestRegistrationCallback.requestListToFill = requestListToFill; while (!op.isOperationComplete()) { op.poll(requestRegistrationCallback); List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill); for (ResponseInfo response : responses) { op.handleResponse(response); } } readCompleteLatch.await(); Assert.assertTrue("Operation should be complete at this time", op.isOperationComplete()); if (operationException.get() != null) { throw operationException.get(); } if (readCompleteException.get() != null) { throw readCompleteException.get(); } Assert.assertEquals("Size read must equal size written", blobSize, readCompleteResult.get()); }