@Test public void testBatchExample() { tracer.batchRequestSent(100, 1000); tracer.attemptStarted(0); tracer.connectionSelected(1); tracer.attemptSucceeded(); tracer.operationSucceeded(); verify(span).putAttribute("batch count", AttributeValue.longAttributeValue(100)); verify(span).putAttribute("batch size", AttributeValue.longAttributeValue(1000)); }
@Test public void testCancellationExample() { tracer.attemptStarted(0); tracer.connectionSelected(1); tracer.attemptCancelled(); tracer.operationCancelled(); verify(span) .addAnnotation( "Attempt started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); verify(span) .addAnnotation( "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(1))); verify(span) .addAnnotation( "Attempt cancelled", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); verify(span) .putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(1))); verify(span) .end( EndSpanOptions.builder() .setStatus(Status.CANCELLED.withDescription("Cancelled by caller")) .build()); verifyNoMoreInteractions(span); }
@Test public void testUnarySuccessExample() { tracer.attemptStarted(0); tracer.connectionSelected(1); ApiException error0 = new DeadlineExceededException( tracer.connectionSelected(2); tracer.attemptSucceeded(); tracer.operationSucceeded();
@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 started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); verify(span) .addAnnotation( "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(1))); verify(span) .addAnnotation( "Attempt failed, error not retryable", ImmutableMap.of( "attempt", AttributeValue.longAttributeValue(0), "status", AttributeValue.stringAttributeValue("NOT_FOUND"))); 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); }
@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( "Attempt started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); verify(span) .addAnnotation( "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(1))); verify(span) .addAnnotation( "Attempts exhausted", ImmutableMap.of( "attempt", AttributeValue.longAttributeValue(0), "status", AttributeValue.stringAttributeValue("DEADLINE_EXCEEDED"))); 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); }