Search in sources :

Example 46 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class StreamObserversShould method return_Error_extracted_form_StatusException_metadata.

@Test
public void return_Error_extracted_form_StatusException_metadata() {
    final Error expectedError = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(expectedError);
    final StatusException statusException = INVALID_ARGUMENT.asException(metadata);
    assertEquals(expectedError, StreamObservers.fromStreamError(statusException).get());
}
Also used : StatusException(io.grpc.StatusException) Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 47 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grakn by graknlabs.

the class GrpcClient method convertStatusRuntimeException.

private static RuntimeException convertStatusRuntimeException(StatusRuntimeException error) {
    Status status = error.getStatus();
    Metadata trailers = error.getTrailers();
    ErrorType errorType = trailers.get(ErrorType.KEY);
    if (errorType != null) {
        String message = status.getDescription();
        return errorType.toException(message);
    } else {
        return error;
    }
}
Also used : Status(io.grpc.Status) ErrorType(ai.grakn.grpc.GrpcUtil.ErrorType) Metadata(io.grpc.Metadata)

Example 48 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project brave by openzipkin.

the class ITTracingServerInterceptor method usesExistingTraceId.

@Test
public void usesExistingTraceId() throws Exception {
    final String traceId = "463ac35c9f6413ad";
    final String parentId = traceId;
    final String spanId = "48485a3953bb6124";
    Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {

                @Override
                public void start(Listener<RespT> responseListener, Metadata headers) {
                    headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
                    headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
                    headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
                    headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
                    super.start(responseListener, headers);
                }
            };
        }
    });
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.traceId()).isEqualTo(traceId);
    assertThat(span.parentId()).isEqualTo(parentId);
    assertThat(span.id()).isEqualTo(spanId);
    assertThat(span.shared()).isTrue();
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Span(zipkin2.Span) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) ClientCall(io.grpc.ClientCall) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.Test)

Example 49 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project brave by openzipkin.

the class ITTracingServerInterceptor method createsChildWhenJoinDisabled.

@Test
public void createsChildWhenJoinDisabled() throws Exception {
    grpcTracing = GrpcTracing.create(tracingBuilder(NEVER_SAMPLE).supportsJoin(false).build());
    init();
    final String traceId = "463ac35c9f6413ad";
    final String parentId = traceId;
    final String spanId = "48485a3953bb6124";
    Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {

                @Override
                public void start(Listener<RespT> responseListener, Metadata headers) {
                    headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
                    headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
                    headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
                    headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
                    super.start(responseListener, headers);
                }
            };
        }
    });
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.traceId()).isEqualTo(traceId);
    assertThat(span.parentId()).isEqualTo(spanId);
    assertThat(span.id()).isNotEqualTo(spanId);
    assertThat(span.shared()).isNull();
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Span(zipkin2.Span) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) ClientCall(io.grpc.ClientCall) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.Test)

Example 50 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project incubator-skywalking by apache.

the class StreamCallClientInterceptor method start.

@Override
public void start(Listener responseListener, Metadata headers) {
    final ContextCarrier contextCarrier = new ContextCarrier();
    final AbstractSpan span = ContextManager.createExitSpan(serviceName, contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.GRPC);
    SpanLayer.asRPCFramework(span);
    CarrierItem contextItem = contextCarrier.items();
    while (contextItem.hasNext()) {
        contextItem = contextItem.next();
        Metadata.Key<String> headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER);
        headers.put(headerKey, contextItem.getHeadValue());
    }
    delegate().start(new CallListener(responseListener, ContextManager.capture()), headers);
    ContextManager.stopSpan();
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ForwardingClientCallListener(io.grpc.ForwardingClientCallListener) Metadata(io.grpc.Metadata) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

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