@Test public void testFailureOnTimeout() throws Exception { when(delegate.request(any(URI.class), anyString(), any(byte[].class), Matchers.<Map<String, List<String>>>any())) .thenReturn(Futures.<Response>immediateFailedFuture(new IOException())) .thenReturn(Futures.<Response>immediateFuture(null)); when(clock.now()).thenReturn(new Instant(0)).thenReturn(new Instant(80000)); final ListenableFuture<Response> future = dispatcher.request( new URI("http: verify(delegate, times(1)).request(any(URI.class), anyString(), any(byte[].class), Matchers.<Map<String, List<String>>>any()); exception.expect(ExecutionException.class); exception.expectCause(CoreMatchers.any(IOException.class)); future.get(); }
@Override public ListenableFuture<Response> request(final URI uri, final String method, final byte[] entityBytes, final Map<String, List<String>> headers) { final long deadline = clock.now().getMillis() + retryTimeoutMillis; final SettableFuture<Response> future = SettableFuture.create(); final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() { @Override public ListenableFuture<Response> get() { return delegate.request(uri, method, entityBytes, headers); } }; startRetry(future, code, deadline, delayMillis, uri); return future; }
RetryingRequestDispatcher implements RequestDispatcher { @Override public ListenableFuture<Response> request(final URI uri, final String method, final byte[] entityBytes, final Map<String, List<String>> headers) { final long deadline = clock.now().getMillis() + retryTimeoutMillis; final SettableFuture<Response> future = SettableFuture.create(); final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() { @Override public ListenableFuture<Response> get() { return delegate.request(uri, method, entityBytes, headers); } }; startRetry(future, code, deadline, delayMillis, uri); return future; } }
RetryingRequestDispatcher implements RequestDispatcher { @Override public ListenableFuture<Response> request(final URI uri, final String method, final byte[] entityBytes, final Map<String, List<String>> headers) { final long deadline = clock.now().getMillis() + retryTimeoutMillis; final SettableFuture<Response> future = SettableFuture.create(); final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() { @Override public ListenableFuture<Response> get() { return delegate.request(uri, method, entityBytes, headers); } }; startRetry(future, code, deadline, delayMillis, uri); return future; } private  RetryingRequestDispatcher(final RequestDispatcher delegate,
                                    final ListeningScheduledExecutorService executorService,
                                    final Clock clock,
                                    final long retryTimeoutMillis,
                                    final long delayMillis); }
RetryingRequestDispatcher implements RequestDispatcher { @Override public ListenableFuture<Response> request(final URI uri, final String method, final byte[] entityBytes, final Map<String, List<String>> headers) { final long deadline = clock.now().getMillis() + retryTimeoutMillis; final SettableFuture<Response> future = SettableFuture.create(); final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() { @Override public ListenableFuture<Response> get() { return delegate.request(uri, method, entityBytes, headers); } }; startRetry(future, code, deadline, delayMillis, uri); return future; } private  RetryingRequestDispatcher(final RequestDispatcher delegate,
                                    final ListeningScheduledExecutorService executorService,
                                    final Clock clock,
                                    final long retryTimeoutMillis,
                                    final long delayMillis); @Override ListenableFuture<Response> request(final URI uri,
                                            final String method,
                                            final byte[] entityBytes,
                                            final Map<String, List<String>> headers); @Override void close(); }
RetryingRequestDispatcher implements RequestDispatcher { @Override public ListenableFuture<Response> request(final URI uri, final String method, final byte[] entityBytes, final Map<String, List<String>> headers) { final long deadline = clock.now().getMillis() + retryTimeoutMillis; final SettableFuture<Response> future = SettableFuture.create(); final Supplier<ListenableFuture<Response>> code = new Supplier<ListenableFuture<Response>>() { @Override public ListenableFuture<Response> get() { return delegate.request(uri, method, entityBytes, headers); } }; startRetry(future, code, deadline, delayMillis, uri); return future; } private  RetryingRequestDispatcher(final RequestDispatcher delegate,
                                    final ListeningScheduledExecutorService executorService,
                                    final Clock clock,
                                    final long retryTimeoutMillis,
                                    final long delayMillis); @Override ListenableFuture<Response> request(final URI uri,
                                            final String method,
                                            final byte[] entityBytes,
                                            final Map<String, List<String>> headers); @Override void close();  }