Search in sources :

Example 11 with Metadata

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));
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 12 with Metadata

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());
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 13 with Metadata

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);
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 14 with Metadata

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()));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 15 with Metadata

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());
}
Also used : StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) StatsContext(com.google.instrumentation.stats.StatsContext) Metadata(io.grpc.Metadata) TagValue(com.google.instrumentation.stats.TagValue) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)701 Test (org.junit.Test)559 Status (io.grpc.Status)190 CallOptions (io.grpc.CallOptions)56 ClientStreamTracer (io.grpc.ClientStreamTracer)51 ServerCall (io.grpc.ServerCall)48 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)44 InOrder (org.mockito.InOrder)41 Subchannel (io.grpc.LoadBalancer.Subchannel)40 ByteArrayInputStream (java.io.ByteArrayInputStream)40 InputStream (java.io.InputStream)38 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 IOException (java.io.IOException)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 Context (io.grpc.Context)31 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)31 InternalMetadata (io.grpc.InternalMetadata)30 MethodDescriptor (io.grpc.MethodDescriptor)30 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)29 ManagedChannel (io.grpc.ManagedChannel)27