Source:
private void fillChunksAndAssertSuccess() throws Exception { VerifiableProperties vProps = getNonBlockingRouterProperties(); MockClusterMap mockClusterMap = new MockClusterMap(); RouterConfig routerConfig = new RouterConfig(vProps); NonBlockingRouterMetrics routerMetrics = new NonBlockingRouterMetrics(mockClusterMap); ResponseHandler responseHandler = new ResponseHandler(mockClusterMap); BlobProperties putBlobProperties = new BlobProperties(blobSize, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time); Random random = new Random(); byte[] putUserMetadata = new byte[10]; random.nextBytes(putUserMetadata); putContent = new byte[blobSize]; random.nextBytes(putContent); final ReadableStreamChannel putChannel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(putContent)); FutureResult<String> futureResult = new FutureResult<String>(); MockTime time = new MockTime(); MockNetworkClientFactory networkClientFactory = new MockNetworkClientFactory(vProps, null, 0, 0, 0, null, time); PutOperation op = new PutOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, putBlobProperties, putUserMetadata, putChannel, futureResult, null, new ReadyForPollCallback(networkClientFactory.getNetworkClient()), null, time); numChunks = op.getNumDataChunks(); compositeBuffers = new ByteBuffer[numChunks]; final AtomicReference<Exception> operationException = new AtomicReference<Exception>(null); do { op.fillChunks(); for (PutOperation.PutChunk putChunk : op.putChunks) { if (putChunk.isFree()) { continue; } Assert.assertEquals("Chunk should be ready.", PutOperation.ChunkState.Ready, putChunk.getState()); ByteBuffer buf = putChunk.buf; totalSizeWritten += buf.remaining(); compositeBuffers[putChunk.getChunkIndex()] = ByteBuffer.allocate(buf.remaining()).put(buf); putChunk.clear(); } } while (!op.isChunkFillComplete()); Assert.assertEquals("total size written out should match the blob size", blobSize, totalSizeWritten); Exception exception = operationException.get(); if (exception != null) { throw exception; } assertDataIdentity(); }

Target:
private void fillChunksAndAssertSuccess() throws Exception { VerifiableProperties vProps = getNonBlockingRouterProperties(); MockClusterMap mockClusterMap = new MockClusterMap(); RouterConfig routerConfig = new RouterConfig(vProps); NonBlockingRouterMetrics routerMetrics = new NonBlockingRouterMetrics(mockClusterMap); ResponseHandler responseHandler = new ResponseHandler(mockClusterMap); BlobProperties putBlobProperties = new BlobProperties(blobSize, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time); Random random = new Random(); byte[] putUserMetadata = new byte[10]; random.nextBytes(putUserMetadata); putContent = new byte[blobSize]; random.nextBytes(putContent); final ReadableStreamChannel putChannel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(putContent)); FutureResult<String> futureResult = new FutureResult<String>(); MockTime time = new MockTime(); MockNetworkClientFactory networkClientFactory = new MockNetworkClientFactory(vProps, null, 0, 0, 0, null, time); PutOperation op = new PutOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, putBlobProperties, putUserMetadata, putChannel, futureResult, null, new ReadyForPollCallback(networkClientFactory.getNetworkClient()), null, time); op.startReadingFromChannel(); numChunks = op.getNumDataChunks(); compositeBuffers = new ByteBuffer[numChunks]; final AtomicReference<Exception> operationException = new AtomicReference<Exception>(null); do { op.fillChunks(); for (PutOperation.PutChunk putChunk : op.putChunks) { if (putChunk.isFree()) { continue; } Assert.assertEquals("Chunk should be ready.", PutOperation.ChunkState.Ready, putChunk.getState()); ByteBuffer buf = putChunk.buf; totalSizeWritten += buf.remaining(); compositeBuffers[putChunk.getChunkIndex()] = ByteBuffer.allocate(buf.remaining()).put(buf); putChunk.clear(); } } while (!op.isChunkFillComplete()); Assert.assertEquals("total size written out should match the blob size", blobSize, totalSizeWritten); Exception exception = operationException.get(); if (exception != null) { throw exception; } assertDataIdentity(); }