Search in sources :

Example 16 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class RetryTest method assertOutboundWireSizeRecorded.

private void assertOutboundWireSizeRecorded(long length) throws Exception {
    MetricsRecord record = clientStatsRecorder.pollRecord(5, SECONDS);
    assertThat(record.getMetricAsLongOrFail(RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD)).isEqualTo(length);
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 17 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class RetryTest method assertInboundWireSizeRecorded.

private void assertInboundWireSizeRecorded(long length) throws Exception {
    MetricsRecord record = clientStatsRecorder.pollRecord(5, SECONDS);
    assertThat(record.getMetricAsLongOrFail(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD)).isEqualTo(length);
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 18 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class AbstractInteropTest method deadlineExceededServerStreaming.

@Test
public void deadlineExceededServerStreaming() throws Exception {
    // warm up the channel and JVM
    blockingStub.emptyCall(Empty.getDefaultInstance());
    assertStatsTrace("grpc.testing.TestService/EmptyCall", Status.Code.OK);
    ResponseParameters.Builder responseParameters = ResponseParameters.newBuilder().setSize(1).setIntervalUs(10000);
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(responseParameters).addResponseParameters(responseParameters).addResponseParameters(responseParameters).addResponseParameters(responseParameters).build();
    StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
    asyncStub.withDeadlineAfter(30, TimeUnit.MILLISECONDS).streamingOutputCall(request, recorder);
    recorder.awaitCompletion();
    assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(recorder.getError()).getCode());
    if (metricsExpected()) {
        // Stream may not have been created when deadline is exceeded, thus we don't check tracer
        // stats.
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/StreamingOutputCall", true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED, true);
    // Do not check server-side metrics, because the status on the server side is undetermined.
    }
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) ResponseParameters(io.grpc.testing.integration.Messages.ResponseParameters) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 19 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class AbstractInteropTest method assertClientStatsTrace.

private void assertClientStatsTrace(String method, Status.Code code, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) {
    // Tracer-based stats
    TestClientStreamTracer tracer = clientStreamTracers.poll();
    assertNotNull(tracer);
    assertTrue(tracer.getOutboundHeaders());
    // but streamClosed() may be called slightly later than that.  So we need a timeout.
    try {
        assertTrue(tracer.await(5, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    }
    assertEquals(code, tracer.getStatus().getCode());
    if (requests != null && responses != null) {
        checkTracers(tracer, requests, responses);
    }
    if (metricsExpected()) {
        // CensusStreamTracerModule records final status in interceptor, which is guaranteed to be
        // done before application receives status.
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord();
        checkStartTags(clientStartRecord, method, true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord();
        checkEndTags(clientEndRecord, method, code, true);
        if (requests != null && responses != null) {
            checkCensus(clientEndRecord, false, requests, responses);
        }
        assertZeroRetryRecorded();
    }
}
Also used : TestClientStreamTracer(io.grpc.internal.testing.TestClientStreamTracer) MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Aggregations

MetricsRecord (io.grpc.internal.testing.StatsTestUtils.MetricsRecord)19 Test (org.junit.Test)6 StatusRuntimeException (io.grpc.StatusRuntimeException)4 StreamingOutputCallRequest (io.grpc.testing.integration.Messages.StreamingOutputCallRequest)3 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)2 TagValue (io.opencensus.tags.TagValue)2 ByteString (com.google.protobuf.ByteString)1 Attributes (io.grpc.Attributes)1 CallOptions (io.grpc.CallOptions)1 ClientStreamTracer (io.grpc.ClientStreamTracer)1 StreamInfo (io.grpc.ClientStreamTracer.StreamInfo)1 Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 TestClientStreamTracer (io.grpc.internal.testing.TestClientStreamTracer)1 ResponseParameters (io.grpc.testing.integration.Messages.ResponseParameters)1 StreamingInputCallRequest (io.grpc.testing.integration.Messages.StreamingInputCallRequest)1 StreamingInputCallResponse (io.grpc.testing.integration.Messages.StreamingInputCallResponse)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1