use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class TracedServerStreamingCallableTest method testOperationCancelled.
@Test
public void testOperationCancelled() {
tracedCallable.call("test", responseObserver, callContext);
responseObserver.getController().cancel();
MockServerStreamingCall<String, String> innerCall = innerCallable.popLastCall();
innerCall.getController().getObserver().onError(new CancelledException("fake cancel", null, new FakeStatusCode(Code.CANCELLED), false));
assertThat(responseObserver.isDone()).isTrue();
verify(tracer, times(1)).operationCancelled();
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class OpencensusTracerTest method testFailureExample.
@Test
public void testFailureExample() {
tracer.attemptStarted(0);
tracer.connectionSelected("1");
ApiException error0 = new NotFoundException("not found", null, new FakeStatusCode(Code.NOT_FOUND), false);
tracer.attemptPermanentFailure(error0);
tracer.operationFailed(error0);
verify(span).addAnnotation("Attempt failed, error not retryable", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0), "status", AttributeValue.stringAttributeValue("NOT_FOUND"), "status message", AttributeValue.stringAttributeValue("not found"), "connection", AttributeValue.stringAttributeValue("1")));
verify(span).putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(1)));
verify(span).end(EndSpanOptions.builder().setStatus(Status.NOT_FOUND.withDescription("not found")).build());
verifyNoMoreInteractions(span);
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class OpencensusTracerTest method testStreamingErrorConversion.
@Test
public void testStreamingErrorConversion() {
ServerStreamingAttemptException error = new ServerStreamingAttemptException(new DeadlineExceededException("timeout", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true), true, true);
Status opencensusStatus = OpencensusTracer.convertErrorToStatus(error);
assertThat(opencensusStatus.getDescription()).isEqualTo("timeout");
assertThat(opencensusStatus.getCanonicalCode()).isEqualTo(CanonicalCode.DEADLINE_EXCEEDED);
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class OpencensusTracerTest method testStatusCode.
@Test
public void testStatusCode() {
tracer.attemptStarted(0);
tracer.attemptFailed(new DeadlineExceededException("deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true), Duration.ofMillis(1));
tracer.attemptStarted(1);
ApiException permanentError = new NotFoundException("not found", null, new FakeStatusCode(Code.NOT_FOUND), false);
tracer.attemptPermanentFailure(permanentError);
tracer.operationFailed(permanentError);
verify(span).addAnnotation(eq("Attempt failed, scheduling next attempt"), attributeCaptor.capture());
assertThat(attributeCaptor.getValue()).containsEntry("status", AttributeValue.stringAttributeValue("DEADLINE_EXCEEDED"));
verify(span).addAnnotation(eq("Attempt failed, error not retryable"), attributeCaptor.capture());
assertThat(attributeCaptor.getValue()).containsEntry("status", AttributeValue.stringAttributeValue("NOT_FOUND"));
}
use of com.google.api.gax.rpc.testing.FakeStatusCode in project gax-java by googleapis.
the class OpencensusTracerTest method testUnarySuccessExample.
@Test
public void testUnarySuccessExample() {
tracer.attemptStarted(0);
tracer.connectionSelected("1");
ApiException error0 = new DeadlineExceededException("deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true);
tracer.attemptFailed(error0, Duration.ofMillis(5));
tracer.attemptStarted(1);
tracer.connectionSelected("2");
tracer.attemptSucceeded();
tracer.operationSucceeded();
// Attempt 0
verify(span).addAnnotation("Attempt failed, scheduling next attempt", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0), "delay ms", AttributeValue.longAttributeValue(5), "status", AttributeValue.stringAttributeValue("DEADLINE_EXCEEDED"), "status message", AttributeValue.stringAttributeValue("deadline exceeded"), "connection", AttributeValue.stringAttributeValue("1")));
// Attempt 1
verify(span).addAnnotation("Attempt succeeded", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(1), "connection", AttributeValue.stringAttributeValue("2")));
verify(span).putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(2)));
verify(span).end();
verifyNoMoreInteractions(span);
}
Aggregations