use of io.grpc.internal.testing.TestClientStreamTracer in project grpc-java by grpc.
the class AbstractClientStreamTest method writeMessage_closesStream.
@Test
public void writeMessage_closesStream() throws IOException {
AbstractClientStream.Sink sink = mock(AbstractClientStream.Sink.class);
final TestClientStreamTracer tracer = new TestClientStreamTracer();
StatsTraceContext statsTraceCtx = new StatsTraceContext(new StreamTracer[] { tracer });
AbstractClientStream stream = new BaseAbstractClientStream(allocator, new BaseTransportState(statsTraceCtx, transportTracer), sink, statsTraceCtx, transportTracer, true);
stream.start(mockListener);
InputStream input = mock(InputStream.class, delegatesTo(new ByteArrayInputStream(new byte[1])));
stream.writeMessage(input);
verify(input).close();
}
use of io.grpc.internal.testing.TestClientStreamTracer in project grpc-java by grpc.
the class AbstractClientStreamTest method getRequest.
@Test
public void getRequest() {
AbstractClientStream.Sink sink = mock(AbstractClientStream.Sink.class);
final TestClientStreamTracer tracer = new TestClientStreamTracer();
StatsTraceContext statsTraceCtx = new StatsTraceContext(new StreamTracer[] { tracer });
AbstractClientStream stream = new BaseAbstractClientStream(allocator, new BaseTransportState(statsTraceCtx, transportTracer), sink, statsTraceCtx, transportTracer, true);
stream.start(mockListener);
stream.writeMessage(new ByteArrayInputStream(new byte[1]));
// writeHeaders will be delayed since we're sending a GET request.
verify(sink, never()).writeHeaders(any(Metadata.class), any(byte[].class));
// halfClose will trigger writeHeaders.
stream.halfClose();
ArgumentCaptor<byte[]> payloadCaptor = ArgumentCaptor.forClass(byte[].class);
verify(sink).writeHeaders(any(Metadata.class), payloadCaptor.capture());
assertTrue(payloadCaptor.getValue() != null);
// GET requests don't have BODY.
verify(sink, never()).writeFrame(any(WritableBuffer.class), anyBoolean(), anyBoolean(), anyInt());
assertThat(tracer.nextOutboundEvent()).isEqualTo("outboundMessage(0)");
assertThat(tracer.nextOutboundEvent()).matches("outboundMessageSent\\(0, [0-9]+, [0-9]+\\)");
assertNull(tracer.nextOutboundEvent());
assertNull(tracer.nextInboundEvent());
assertEquals(1, tracer.getOutboundWireSize());
assertEquals(1, tracer.getOutboundUncompressedSize());
}
use of io.grpc.internal.testing.TestClientStreamTracer 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();
}
}
Aggregations