use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method cancel_notifiesOnlyOnce.
@Test
public void cancel_notifiesOnlyOnce() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator) {
@Override
protected void sendCancel(Status errorStatus) {
transportReportStatus(errorStatus, true, /*stop delivery*/
new Metadata());
}
};
stream.start(mockListener);
stream.cancel(Status.DEADLINE_EXCEEDED);
verify(mockListener).closed(isA(Status.class), isA(Metadata.class));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method deframeFailed_notifiesListener.
@Test
public void deframeFailed_notifiesListener() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator) {
@Override
protected void sendCancel(Status errorStatus) {
transportReportStatus(errorStatus, true, /*stop delivery*/
new Metadata());
}
};
stream.start(mockListener);
stream.deframeFailed(new RuntimeException("something bad"));
verify(mockListener).closed(statusCaptor.capture(), isA(Metadata.class));
assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStreamTest method inboundHeadersReceived_acceptsGzipEncoding.
@Test
public void inboundHeadersReceived_acceptsGzipEncoding() {
AbstractClientStream stream = new BaseAbstractClientStream(allocator);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, new Codec.Gzip().getMessageEncoding());
stream.inboundHeadersReceived(headers);
verify(mockListener).headersRead(headers);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method prepareHeaders_statsCtxAdded.
@Test
public void prepareHeaders_statsCtxAdded() {
Metadata m = new Metadata();
ClientCallImpl.prepareHeaders(m, decompressorRegistry, Codec.Identity.NONE, statsTraceCtx);
assertEquals(parentStatsContext, m.get(statsTraceCtx.getStatsHeader()));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class StatsTraceContextTest method tagPropagation.
/**
* Tags that are propagated by the {@link StatsContextFactory} are properly propagated via
* the headers.
*/
@Test
public void tagPropagation() {
String methodName = MethodDescriptor.generateFullMethodName("Service1", "method3");
// EXTRA_TAG is propagated by the FakeStatsContextFactory. Note that not all tags are
// propagated. The StatsContextFactory decides which tags are to propagated. gRPC facilitates
// the propagation by putting them in the headers.
StatsContext parentCtx = statsCtxFactory.getDefault().with(StatsTestUtils.EXTRA_TAG, TagValue.create("extra-tag-value-897"));
StatsTraceContext clientCtx = StatsTraceContext.newClientContextForTesting(methodName, statsCtxFactory, parentCtx, fakeClock.getStopwatchSupplier());
Metadata headers = new Metadata();
clientCtx.propagateToHeaders(headers);
// The server gets the propagated tag from the headers, and puts it on the server-side
// StatsContext.
StatsTraceContext serverCtx = StatsTraceContext.newServerContext(methodName, statsCtxFactory, headers, fakeClock.getStopwatchSupplier());
serverCtx.callEnded(Status.OK);
clientCtx.callEnded(Status.OK);
StatsTestUtils.MetricsRecord serverRecord = statsCtxFactory.pollRecord();
assertNotNull(serverRecord);
assertNoClientContent(serverRecord);
TagValue serverMethodTag = serverRecord.tags.get(RpcConstants.RPC_SERVER_METHOD);
assertEquals(methodName, serverMethodTag.toString());
TagValue serverStatusTag = serverRecord.tags.get(RpcConstants.RPC_STATUS);
assertEquals(Status.Code.OK.toString(), serverStatusTag.toString());
assertNull(serverRecord.getMetric(RpcConstants.RPC_SERVER_ERROR_COUNT));
TagValue serverPropagatedTag = serverRecord.tags.get(StatsTestUtils.EXTRA_TAG);
assertEquals("extra-tag-value-897", serverPropagatedTag.toString());
StatsTestUtils.MetricsRecord clientRecord = statsCtxFactory.pollRecord();
assertNotNull(clientRecord);
assertNoServerContent(clientRecord);
TagValue clientMethodTag = clientRecord.tags.get(RpcConstants.RPC_CLIENT_METHOD);
assertEquals(methodName, clientMethodTag.toString());
TagValue clientStatusTag = clientRecord.tags.get(RpcConstants.RPC_STATUS);
assertEquals(Status.Code.OK.toString(), clientStatusTag.toString());
assertNull(clientRecord.getMetric(RpcConstants.RPC_CLIENT_ERROR_COUNT));
TagValue clientPropagatedTag = clientRecord.tags.get(StatsTestUtils.EXTRA_TAG);
assertEquals("extra-tag-value-897", clientPropagatedTag.toString());
}
Aggregations