use of com.google.api.gax.retrying.RetryingContext in project gax-java by googleapis.
the class StreamingRetryAlgorithmTest method testShouldNotRetryIfAttemptIsNonResumable.
@Test
public void testShouldNotRetryIfAttemptIsNonResumable() {
RetryingContext context = mock(RetryingContext.class);
ServerStreamingAttemptException exception = mock(ServerStreamingAttemptException.class);
when(exception.canResume()).thenReturn(false);
UnavailableException cause = mock(UnavailableException.class);
when(exception.getCause()).thenReturn(cause);
BasicResultRetryAlgorithm<String> resultAlgorithm = new BasicResultRetryAlgorithm<>();
ExponentialRetryAlgorithm timedAlgorithm = new ExponentialRetryAlgorithm(DEFAULT_RETRY_SETTINGS, mock(ApiClock.class));
StreamingRetryAlgorithm<String> algorithm = new StreamingRetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
// This should return false because the attempt exception indicates that it is non-resumable.
boolean shouldRetry = algorithm.shouldRetry(context, exception, null, mock(TimedAttemptSettings.class));
assertThat(shouldRetry).isFalse();
boolean shouldRetryWithoutContext = algorithm.shouldRetry(exception, null, mock(TimedAttemptSettings.class));
assertThat(shouldRetryWithoutContext).isFalse();
}
use of com.google.api.gax.retrying.RetryingContext in project gax-java by googleapis.
the class StreamingRetryAlgorithmTest method testShouldRetryIfAllSayYes.
@Test
public void testShouldRetryIfAllSayYes() {
RetryingContext context = mock(RetryingContext.class);
ServerStreamingAttemptException exception = mock(ServerStreamingAttemptException.class);
when(exception.canResume()).thenReturn(true);
UnavailableException cause = mock(UnavailableException.class);
when(exception.getCause()).thenReturn(cause);
BasicResultRetryAlgorithm<String> resultAlgorithm = new BasicResultRetryAlgorithm<>();
ExponentialRetryAlgorithm timedAlgorithm = mock(ExponentialRetryAlgorithm.class);
when(timedAlgorithm.shouldRetry(Mockito.eq(context), any(TimedAttemptSettings.class))).thenReturn(true);
StreamingRetryAlgorithm<String> algorithm = new StreamingRetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
boolean shouldRetry = algorithm.shouldRetry(context, exception, null, mock(TimedAttemptSettings.class));
assertThat(shouldRetry).isTrue();
}
Aggregations