use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.
the class MessageDeframerTest method checkStats.
private void checkStats(long wireBytesReceived, long uncompressedBytesReceived) {
statsTraceCtx.callEnded(Status.OK);
MetricsRecord record = statsCtxFactory.pollRecord();
assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_REQUEST_BYTES));
assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES));
assertEquals(wireBytesReceived, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_RESPONSE_BYTES));
assertEquals(uncompressedBytesReceived, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES));
assertNull(record.getMetric(RpcConstants.RPC_SERVER_REQUEST_BYTES));
assertNull(record.getMetric(RpcConstants.RPC_SERVER_RESPONSE_BYTES));
assertNull(record.getMetric(RpcConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES));
assertNull(record.getMetric(RpcConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES));
}
use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.
the class AbstractInteropTest method assertClientMetrics.
private void assertClientMetrics(String method, Status.Code status, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) {
MetricsRecord clientRecord = clientStatsFactory.pollRecord();
assertNotNull("clientRecord is not null", clientRecord);
checkTags(clientRecord, false, method, status);
if (requests != null && responses != null) {
checkMetrics(clientRecord, false, requests, responses);
}
}
use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.
the class RetryTest method assertRpcStartedRecorded.
private void assertRpcStartedRecorded() throws Exception {
MetricsRecord record = clientStatsRecorder.pollRecord(5, SECONDS);
assertThat(record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT)).isEqualTo(1);
}
use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.
the class AbstractInteropTest method assertServerStatsTrace.
// Failure is checked in the end by the passed flag.
@SuppressWarnings("AssertionFailureIgnored")
private void assertServerStatsTrace(String method, Status.Code code, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) {
if (server == null) {
// Server is not in the same process. We can't check server-side stats.
return;
}
if (metricsExpected()) {
MetricsRecord serverStartRecord;
MetricsRecord serverEndRecord;
try {
// On the server, the stats is finalized in ServerStreamListener.closed(), which can be
// run after the client receives the final status. So we use a timeout.
serverStartRecord = serverStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
serverEndRecord = serverStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
assertNotNull(serverStartRecord);
assertNotNull(serverEndRecord);
checkStartTags(serverStartRecord, method, false);
checkEndTags(serverEndRecord, method, code, false);
if (requests != null && responses != null) {
checkCensus(serverEndRecord, true, requests, responses);
}
}
ServerStreamTracerInfo tracerInfo;
tracerInfo = serverStreamTracers.poll();
assertNotNull(tracerInfo);
assertEquals(method, tracerInfo.fullMethodName);
assertNotNull(tracerInfo.tracer.contextCapture);
// So we use a timeout.
try {
assertTrue(tracerInfo.tracer.await(1, TimeUnit.SECONDS));
} catch (InterruptedException e) {
throw new AssertionError(e);
}
assertEquals(code, tracerInfo.tracer.getStatus().getCode());
if (requests != null && responses != null) {
checkTracers(tracerInfo.tracer, responses, requests);
}
}
use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.
the class AbstractInteropTest method deadlineInPast.
@Test
public void deadlineInPast() throws Exception {
// Test once with idle channel and once with active channel
try {
blockingStub.withDeadlineAfter(-10, TimeUnit.SECONDS).emptyCall(Empty.getDefaultInstance());
fail("Should have thrown");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
assertThat(ex.getStatus().getDescription()).startsWith("ClientCall started after deadline exceeded");
}
// deadline is exceeded before the call is created. Therefore we don't check the tracer stats.
if (metricsExpected()) {
MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
checkStartTags(clientStartRecord, "grpc.testing.TestService/EmptyCall", true);
MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
checkEndTags(clientEndRecord, "grpc.testing.TestService/EmptyCall", Status.DEADLINE_EXCEEDED.getCode(), true);
assertZeroRetryRecorded();
}
// warm up the channel
blockingStub.emptyCall(Empty.getDefaultInstance());
if (metricsExpected()) {
// clientStartRecord
clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
// clientEndRecord
clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
assertZeroRetryRecorded();
}
try {
blockingStub.withDeadlineAfter(-10, TimeUnit.SECONDS).emptyCall(Empty.getDefaultInstance());
fail("Should have thrown");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
assertThat(ex.getStatus().getDescription()).startsWith("ClientCall started after deadline exceeded");
}
if (metricsExpected()) {
MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
checkStartTags(clientStartRecord, "grpc.testing.TestService/EmptyCall", true);
MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
checkEndTags(clientEndRecord, "grpc.testing.TestService/EmptyCall", Status.DEADLINE_EXCEEDED.getCode(), true);
assertZeroRetryRecorded();
}
}
Aggregations