Source:
private void getAndAssertSuccess(final boolean getChunksBeforeRead, final boolean initiateReadBeforeChunkGet) 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); final int numChunks = ((blobSize + maxChunkSize - 1) / maxChunkSize) + (blobSize > maxChunkSize ? 1 : 0); mockNetworkClient.resetProcessedResponseCount(); 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 { final ByteBufferAsyncWritableChannel asyncWritableChannel = new ByteBufferAsyncWritableChannel(); final Future<Long> preSetReadIntoFuture = initiateReadBeforeChunkGet ? result.readInto(asyncWritableChannel, null) : null; Utils.newThread(new Runnable() { @Override public void run() { if (getChunksBeforeRead) { while (mockNetworkClient.getProcessedResponseCount() < numChunks * routerConfig.routerGetRequestParallelism) { Thread.yield(); } } Future<Long> readIntoFuture = initiateReadBeforeChunkGet ? preSetReadIntoFuture : result.readInto(asyncWritableChannel, null); assertSuccess(options, readIntoFuture, asyncWritableChannel, readCompleteLatch, readCompleteResult, readCompleteException); } }, false).start(); } } }; GetBlobOperation op = createOperationAndComplete(callback); 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(); } int sizeWritten = blobSize; if (options != null && options.getRange() != null) { GetBlobRange range = options.getRange(); sizeWritten = (int) (range.getEndOffset(blobSize) - range.getStartOffset(blobSize) + 1); } Assert.assertEquals("Size read must equal size written", sizeWritten, readCompleteResult.get()); }

Target:
private void getAndAssertSuccess(final boolean getChunksBeforeRead, final boolean initiateReadBeforeChunkGet) 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); final int numChunks = ((blobSize + maxChunkSize - 1) / maxChunkSize) + (blobSize > maxChunkSize ? 1 : 0); mockNetworkClient.resetProcessedResponseCount(); 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 { final ByteBufferAsyncWritableChannel asyncWritableChannel = new ByteBufferAsyncWritableChannel(); final Future<Long> preSetReadIntoFuture = initiateReadBeforeChunkGet ? result.readInto(asyncWritableChannel, null) : null; Utils.newThread(new Runnable() { @Override public void run() { if (getChunksBeforeRead) { while (mockNetworkClient.getProcessedResponseCount() < numChunks * routerConfig.routerGetRequestParallelism) { Thread.yield(); } } Future<Long> readIntoFuture = initiateReadBeforeChunkGet ? preSetReadIntoFuture : result.readInto(asyncWritableChannel, null); assertSuccess(options, readIntoFuture, asyncWritableChannel, readCompleteLatch, readCompleteResult, readCompleteException); } }, false).start(); } } }; GetBlobOperation op = createOperationAndComplete(callback); 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(); } int sizeWritten = blobSize; if (options != null && options.getRange() != null) { ByteRange range = options.getRange().toResolvedByteRange(blobSize); sizeWritten = (int) (range.getEndOffset() - range.getStartOffset() + 1); } Assert.assertEquals("Size read must equal size written", sizeWritten, readCompleteResult.get()); }