@Test public void testUnrecoverableFailure() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0 throws a non-IOException error, so it will be failed without retry. ImmutableMap.<String, Object>builder() .put("b0", new RuntimeException("Ouch!")) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener).onBlockFetchFailure(eq("b0"), any()); verify(listener).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testUnrecoverableFailure() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0 throws a non-IOException error, so it will be failed without retry. ImmutableMap.<String, Object>builder() .put("b0", new RuntimeException("Ouch!")) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener).onBlockFetchFailure(eq("b0"), any()); verify(listener).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testUnrecoverableFailure() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0 throws a non-IOException error, so it will be failed without retry. ImmutableMap.<String, Object>builder() .put("b0", new RuntimeException("Ouch!")) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener).onBlockFetchFailure(eq("b0"), any()); 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 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 testSingleIOExceptionOnSecond() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b1 fails, we will not retry b0. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException("Connection failed or something")) .build(), ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testSingleIOExceptionOnSecond() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b1 fails, we will not retry b0. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException("Connection failed or something")) .build(), ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testSingleIOExceptionOnSecond() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b1 fails, we will not retry b0. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException("Connection failed or something")) .build(), ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testSingleIOExceptionOnFirst() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b0 fails, we will retry both. ImmutableMap.<String, Object>builder() .put("b0", new IOException("Connection failed or something")) .put("b1", block1) .build(), ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testSingleIOExceptionOnFirst() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b0 fails, we will retry both. ImmutableMap.<String, Object>builder() .put("b0", new IOException("Connection failed or something")) .put("b1", block1) .build(), ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testSingleIOExceptionOnFirst() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // IOException will cause a retry. Since b0 fails, we will retry both. ImmutableMap.<String, Object>builder() .put("b0", new IOException("Connection failed or something")) .put("b1", block1) .build(), ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testTwoIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 returns successfully within 2 retries. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testTwoIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 returns successfully within 2 retries. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testTwoIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 returns successfully within 2 retries. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchSuccess("b1", block1); verifyNoMoreInteractions(listener); }
@Test public void testThreeIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 errors again, but this was the last retry ImmutableMap.<String, Object>builder() .put("b1", new IOException()) .build(), // This is not reached -- b1 has failed. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchFailure(eq("b1"), any()); verifyNoMoreInteractions(listener); }
@Test public void testThreeIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 errors again, but this was the last retry ImmutableMap.<String, Object>builder() .put("b1", new IOException()) .build(), // This is not reached -- b1 has failed. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchFailure(eq("b1"), any()); verifyNoMoreInteractions(listener); }
@Test public void testThreeIOExceptions() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, b1's will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new IOException()) .build(), // Next, b0 is successful and b1 errors again, so we just request that one. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new IOException()) .build(), // b1 errors again, but this was the last retry ImmutableMap.<String, Object>builder() .put("b1", new IOException()) .build(), // This is not reached -- b1 has failed. ImmutableMap.<String, Object>builder() .put("b1", block1) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchFailure(eq("b1"), any()); verifyNoMoreInteractions(listener); }
@Test public void testRetryAndUnrecoverable() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, subsequent messages will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new RuntimeException()) .put("b2", block2) .build(), // Next, b0 is successful, b1 errors unrecoverably, and b2 triggers a retry. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new RuntimeException()) .put("b2", new IOException()) .build(), // b2 succeeds in its last retry. ImmutableMap.<String, Object>builder() .put("b2", block2) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchFailure(eq("b1"), any()); verify(listener, timeout(5000)).onBlockFetchSuccess("b2", block2); verifyNoMoreInteractions(listener); }
@Test public void testRetryAndUnrecoverable() throws IOException, InterruptedException { BlockFetchingListener listener = mock(BlockFetchingListener.class); List<? extends Map<String, Object>> interactions = Arrays.asList( // b0's IOException will trigger retry, subsequent messages will be ignored. ImmutableMap.<String, Object>builder() .put("b0", new IOException()) .put("b1", new RuntimeException()) .put("b2", block2) .build(), // Next, b0 is successful, b1 errors unrecoverably, and b2 triggers a retry. ImmutableMap.<String, Object>builder() .put("b0", block0) .put("b1", new RuntimeException()) .put("b2", new IOException()) .build(), // b2 succeeds in its last retry. ImmutableMap.<String, Object>builder() .put("b2", block2) .build() ); performInteractions(interactions, listener); verify(listener, timeout(5000)).onBlockFetchSuccess("b0", block0); verify(listener, timeout(5000)).onBlockFetchFailure(eq("b1"), any()); verify(listener, timeout(5000)).onBlockFetchSuccess("b2", block2); verifyNoMoreInteractions(listener); }