use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class ApiResultRetryAlgorithmTest method testShouldRetryWithContextWithRetryableCodes.
@Test
public void testShouldRetryWithContextWithRetryableCodes() {
ApiCallContext context = mock(ApiCallContext.class);
when(context.getRetryableCodes()).thenReturn(Sets.newHashSet(StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE));
StatusCode unavailable = mock(StatusCode.class);
when(unavailable.getCode()).thenReturn(Code.UNAVAILABLE);
StatusCode dataLoss = mock(StatusCode.class);
when(dataLoss.getCode()).thenReturn(Code.DATA_LOSS);
// The return value of isRetryable() will be ignored, as UNAVAILABLE has been added as a
// retryable code to the call context.
ApiException unavailableException = new ApiException(null, new FakeStatusCode(Code.UNAVAILABLE), /* retryable = */
false);
ApiException dataLossException = new ApiException(null, new FakeStatusCode(Code.DATA_LOSS), /* retryable = */
true);
ApiResultRetryAlgorithm<String> algorithm = new ApiResultRetryAlgorithm<>();
assertTrue(algorithm.shouldRetry(context, unavailableException, null));
assertFalse(algorithm.shouldRetry(context, dataLossException, null));
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class ApiResultRetryAlgorithmTest method testShouldRetryNoContext.
@Test
public void testShouldRetryNoContext() {
ApiException nonRetryable = new ApiException(null, new FakeStatusCode(Code.INTERNAL), /* retryable = */
false);
ApiException retryable = new ApiException(null, new FakeStatusCode(Code.UNAVAILABLE), /* retryable = */
true);
ApiResultRetryAlgorithm<String> algorithm = new ApiResultRetryAlgorithm<>();
assertFalse(algorithm.shouldRetry(nonRetryable, null));
assertTrue(algorithm.shouldRetry(retryable, null));
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class ApiResultRetryAlgorithmTest method testShouldRetryWithContextWithEmptyRetryableCodes.
@Test
public void testShouldRetryWithContextWithEmptyRetryableCodes() {
ApiCallContext context = mock(ApiCallContext.class);
// This will effectively make the RPC non-retryable.
when(context.getRetryableCodes()).thenReturn(Collections.<Code>emptySet());
ApiException unavailableException = new ApiException(null, new FakeStatusCode(Code.UNAVAILABLE), /* retryable = */
true);
ApiResultRetryAlgorithm<String> algorithm = new ApiResultRetryAlgorithm<>();
assertFalse(algorithm.shouldRetry(context, unavailableException, null));
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class ApiResultRetryAlgorithmTest method testShouldRetryWithContextWithoutRetryableCodes.
@Test
public void testShouldRetryWithContextWithoutRetryableCodes() {
ApiCallContext context = mock(ApiCallContext.class);
// No retryable codes in the call context, means that the retry algorithm should fall back to
// its default implementation.
when(context.getRetryableCodes()).thenReturn(null);
ApiException nonRetryable = new ApiException(null, new FakeStatusCode(Code.UNAVAILABLE), /* retryable = */
false);
ApiException retryable = new ApiException(null, new FakeStatusCode(Code.UNAVAILABLE), /* retryable = */
true);
ApiResultRetryAlgorithm<String> algorithm = new ApiResultRetryAlgorithm<>();
assertFalse(algorithm.shouldRetry(context, nonRetryable, null));
assertTrue(algorithm.shouldRetry(context, retryable, null));
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class OpencensusTracerTest method testRetriesExhaustedExample.
@Test
public void testRetriesExhaustedExample() {
tracer.attemptStarted(0);
tracer.connectionSelected("1");
ApiException error0 = new DeadlineExceededException("deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), false);
tracer.attemptFailedRetriesExhausted(error0);
tracer.operationFailed(error0);
verify(span).addAnnotation("Attempts exhausted", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0), "status", AttributeValue.stringAttributeValue("DEADLINE_EXCEEDED"), "status message", AttributeValue.stringAttributeValue("deadline exceeded"), "connection", AttributeValue.stringAttributeValue("1")));
verify(span).putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(1)));
verify(span).end(EndSpanOptions.builder().setStatus(Status.DEADLINE_EXCEEDED.withDescription("deadline exceeded")).build());
verifyNoMoreInteractions(span);
}
Aggregations