@Before public void setUp() { capturedCallContext = ArgumentCaptor.forClass(ApiCallContext.class); Mockito.when(mockInnerCallable.futureCall(Mockito.anyString(), capturedCallContext.capture())) .thenReturn(SettableApiFuture.<String>create()); currentAttemptSettings = TimedAttemptSettings.newBuilder() .setGlobalSettings(RetrySettings.newBuilder().build()) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) .setRetryDelay(Duration.ofSeconds(1)) .setRandomizedRetryDelay(Duration.ofSeconds(1)) .setRpcTimeout(Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) .thenAnswer( new Answer<TimedAttemptSettings>() { @Override public TimedAttemptSettings answer(InvocationOnMock invocation) throws Throwable { return currentAttemptSettings; } }); }
@Before public void setUp() { capturedCallContext = ArgumentCaptor.forClass(ApiCallContext.class); Mockito.when(mockInnerCallable.futureCall(Mockito.<String>any(), capturedCallContext.capture())) .thenReturn(SettableApiFuture.<String>create()); currentAttemptSettings = TimedAttemptSettings.newBuilder() .setGlobalSettings(RetrySettings.newBuilder().build()) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) .setRetryDelay(Duration.ofSeconds(1)) .setRandomizedRetryDelay(Duration.ofSeconds(1)) .setRpcTimeout(Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) .thenAnswer( new Answer<TimedAttemptSettings>() { @Override public TimedAttemptSettings answer(InvocationOnMock invocation) throws Throwable { return currentAttemptSettings; } }); }
.setGlobalSettings(prevSettings.getGlobalSettings()) .setRetryDelay(Duration.ofMillis(newRetryDelay)) .setRpcTimeout(Duration.ofMillis(newRpcTimeout))
.setGlobalSettings(prevSettings.getGlobalSettings()) .setRetryDelay(Duration.ofMillis(newRetryDelay)) .setRpcTimeout(Duration.ofMillis(newRpcTimeout))
/** * Creates a first attempt {@link TimedAttemptSettings}. The first attempt is configured to be * executed immediately. * * @return first attempt settings */ @Override public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) .setRetryDelay(Duration.ZERO) .setRpcTimeout(globalSettings.getInitialRpcTimeout()) .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) .build(); }
/** * Creates a first attempt {@link TimedAttemptSettings}. The first attempt is configured to be * executed immediately. * * @return first attempt settings */ @Override public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) .setRetryDelay(Duration.ZERO) .setRpcTimeout(globalSettings.getInitialRpcTimeout()) .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) .build(); }
@Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { if (prevThrowable != null && prevThrowable instanceof DeadlineExceededException) { return TimedAttemptSettings.newBuilder() .setGlobalSettings(prevSettings.getGlobalSettings()) .setRetryDelay(prevSettings.getRetryDelay()) .setRpcTimeout(prevSettings.getRpcTimeout()) .setRandomizedRetryDelay(DEADLINE_SLEEP_DURATION) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .build(); } return null; }
FakeRetryingFuture(ServerStreamingAttemptCallable<String, String> attemptCallable) { this.attemptCallable = attemptCallable; attemptSettings = TimedAttemptSettings.newBuilder() .setGlobalSettings( RetrySettings.newBuilder().setTotalTimeout(Duration.ofHours(1)).build()) .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) .setRandomizedRetryDelay(Duration.ofMillis(1)) .setRetryDelay(Duration.ofMillis(1)) .setRpcTimeout(Duration.ofMinutes(1)) .build(); }
@Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { if (prevThrowable != null && prevThrowable instanceof DeadlineExceededException) { return TimedAttemptSettings.newBuilder() .setGlobalSettings(prevSettings.getGlobalSettings()) .setRetryDelay(prevSettings.getRetryDelay()) .setRpcTimeout(prevSettings.getRpcTimeout()) .setRandomizedRetryDelay(DEADLINE_SLEEP_DURATION) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .build(); } return null; }
MockRetryingFuture(Duration totalTimeout) { this.timedAttemptSettings = TimedAttemptSettings.newBuilder() .setRpcTimeout(Duration.ofSeconds(1)) .setRetryDelay(Duration.ZERO) .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setFirstAttemptStartTimeNanos(0) .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build()) .build(); }