Search in sources :

Example 6 with FakeStatusCode

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();
}
Also used : FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) CancelledException(com.google.api.gax.rpc.CancelledException) Test(org.junit.Test)

Example 7 with FakeStatusCode

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);
}
Also used : FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) NotFoundException(com.google.api.gax.rpc.NotFoundException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Example 8 with FakeStatusCode

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);
}
Also used : Status(io.opencensus.trace.Status) FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) Test(org.junit.Test)

Example 9 with FakeStatusCode

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"));
}
Also used : FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) NotFoundException(com.google.api.gax.rpc.NotFoundException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Example 10 with FakeStatusCode

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);
}
Also used : FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Aggregations

FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)11 Test (org.junit.Test)11 ApiException (com.google.api.gax.rpc.ApiException)5 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 Status (io.opencensus.trace.Status)2 ServerStreamingAttemptException (com.google.api.gax.retrying.ServerStreamingAttemptException)1 CancelledException (com.google.api.gax.rpc.CancelledException)1 Code (com.google.api.gax.rpc.StatusCode.Code)1 CanonicalCode (io.opencensus.trace.Status.CanonicalCode)1