@Override public void onSuccess(int chunkIndex, ManagedBuffer buffer) { // On receipt of a chunk, pass it upwards as a block. listener.onBlockFetchSuccess(blockIds[chunkIndex], buffer); }
@Override public void onSuccess(int chunkIndex, ManagedBuffer buffer) { // On receipt of a chunk, pass it upwards as a block. listener.onBlockFetchSuccess(blockIds[chunkIndex], buffer); }
@Override public void onSuccess(int chunkIndex, ManagedBuffer buffer) { // On receipt of a chunk, pass it upwards as a block. listener.onBlockFetchSuccess(blockIds[chunkIndex], buffer); }
@Override public void onComplete(String streamId) throws IOException { channel.close(); ManagedBuffer buffer = new FileSegmentManagedBuffer(transportConf, targetFile, 0, targetFile.length()); listener.onBlockFetchSuccess(blockIds[chunkIndex], buffer); if (!tempShuffleFileManager.registerTempShuffleFileToClean(targetFile)) { targetFile.delete(); } }
@Override public void onComplete(String streamId) throws IOException { listener.onBlockFetchSuccess(blockIds[chunkIndex], channel.closeAndRead()); if (!downloadFileManager.registerTempFileToClean(targetFile)) { targetFile.delete(); } }
@Override public void onComplete(String streamId) throws IOException { listener.onBlockFetchSuccess(blockIds[chunkIndex], channel.closeAndRead()); if (!downloadFileManager.registerTempFileToClean(targetFile)) { targetFile.delete(); } }
@Test public void testNoFailures() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // Immediately return both blocks successfully. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener).onBlockFetchSuccess("b0", block0); verify(listener).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testNoFailures() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // Immediately return both blocks successfully. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener).onBlockFetchSuccess("b0", block0); verify(listener).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testFailureAndSuccess() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", new NioManagedBuffer(ByteBuffer.wrap(new byte[21]))); BlockFetchingListener listener = fetchBlocks(blocks); // We may call both success and failure for the same block. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(1)).onBlockFetchSuccess("b2", blocks.get("b2")); verify(listener, times(1)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFailureAndSuccess() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", new NioManagedBuffer(ByteBuffer.wrap(new byte[21]))); BlockFetchingListener listener = fetchBlocks(blocks); // We may call both success and failure for the same block. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(1)).onBlockFetchSuccess("b2", blocks.get("b2")); verify(listener, times(1)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFailure() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", null); BlockFetchingListener listener = fetchBlocks(blocks); // Each failure will cause a failure to be invoked in all remaining block fetches. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(2)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFailure() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", null); BlockFetchingListener listener = fetchBlocks(blocks); // Each failure will cause a failure to be invoked in all remaining block fetches. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(2)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFailure() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", null); BlockFetchingListener listener = fetchBlocks(blocks); // Each failure will cause a failure to be invoked in all remaining block fetches. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(2)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFailureAndSuccess() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", null); blocks.put("b2", new NioManagedBuffer(ByteBuffer.wrap(new byte[21]))); BlockFetchingListener listener = fetchBlocks(blocks); // We may call both success and failure for the same block. verify(listener, times(1)).onBlockFetchSuccess("b0", blocks.get("b0")); verify(listener, times(1)).onBlockFetchFailure(eq("b1"), any()); verify(listener, times(1)).onBlockFetchSuccess("b2", blocks.get("b2")); verify(listener, times(1)).onBlockFetchFailure(eq("b2"), any()); }
@Test public void testFetchOne() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("shuffle_0_0_0", new NioManagedBuffer(ByteBuffer.wrap(new byte[0]))); BlockFetchingListener listener = fetchBlocks(blocks); verify(listener).onBlockFetchSuccess("shuffle_0_0_0", blocks.get("shuffle_0_0_0")); }
@Test public void testFetchOne() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("shuffle_0_0_0", new NioManagedBuffer(ByteBuffer.wrap(new byte[0]))); BlockFetchingListener listener = fetchBlocks(blocks); verify(listener).onBlockFetchSuccess("shuffle_0_0_0", blocks.get("shuffle_0_0_0")); }
@Test public void testFetchOne() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("shuffle_0_0_0", new NioManagedBuffer(ByteBuffer.wrap(new byte[0]))); BlockFetchingListener listener = fetchBlocks(blocks); verify(listener).onBlockFetchSuccess("shuffle_0_0_0", blocks.get("shuffle_0_0_0")); }
@Test public void testFetchThree() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", new NioManagedBuffer(ByteBuffer.wrap(new byte[23]))); blocks.put("b2", new NettyManagedBuffer(Unpooled.wrappedBuffer(new byte[23]))); BlockFetchingListener listener = fetchBlocks(blocks); for (int i = 0; i < 3; i ++) { verify(listener, times(1)).onBlockFetchSuccess("b" + i, blocks.get("b" + i)); } }
@Test public void testFetchThree() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", new NioManagedBuffer(ByteBuffer.wrap(new byte[23]))); blocks.put("b2", new NettyManagedBuffer(Unpooled.wrappedBuffer(new byte[23]))); BlockFetchingListener listener = fetchBlocks(blocks); for (int i = 0; i < 3; i ++) { verify(listener, times(1)).onBlockFetchSuccess("b" + i, blocks.get("b" + i)); } }
@Test public void testFetchThree() { LinkedHashMap<String, ManagedBuffer> blocks = Maps.newLinkedHashMap(); blocks.put("b0", new NioManagedBuffer(ByteBuffer.wrap(new byte[12]))); blocks.put("b1", new NioManagedBuffer(ByteBuffer.wrap(new byte[23]))); blocks.put("b2", new NettyManagedBuffer(Unpooled.wrappedBuffer(new byte[23]))); BlockFetchingListener listener = fetchBlocks(blocks); for (int i = 0; i < 3; i ++) { verify(listener, times(1)).onBlockFetchSuccess("b" + i, blocks.get("b" + i)); } }