Search in sources :

Example 71 with Channel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project grpc-java by grpc.

the class AbstractBlockingStubTest method newStub_futureStub_throwsException.

@Test
@SuppressWarnings("AssertionFailureIgnored")
public void newStub_futureStub_throwsException() {
    try {
        NoopFutureStub unused = NoopBlockingStub.newStub(new StubFactory<NoopFutureStub>() {

            @Override
            public NoopFutureStub newStub(Channel channel, CallOptions callOptions) {
                return new NoopFutureStub(channel, callOptions);
            }
        }, channel, CallOptions.DEFAULT);
        fail("should not reach here");
    } catch (AssertionError e) {
        assertThat(e).hasMessageThat().startsWith("Expected AbstractBlockingStub");
    }
}
Also used : NoopFutureStub(io.grpc.stub.AbstractFutureStubTest.NoopFutureStub) Channel(io.grpc.Channel) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 72 with Channel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project grpc-java by grpc.

the class AbstractStubTest method defaultCallOptions.

@Test
public void defaultCallOptions() {
    NoopStub stub = NoopStub.newStub(new StubFactory<NoopStub>() {

        @Override
        public NoopStub newStub(Channel channel, CallOptions callOptions) {
            return create(channel, callOptions);
        }
    }, channel, CallOptions.DEFAULT);
    assertThat(stub.getCallOptions().getOption(ClientCalls.STUB_TYPE_OPTION)).isNull();
}
Also used : Channel(io.grpc.Channel) NoopStub(io.grpc.stub.AbstractStubTest.NoopStub) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 73 with Channel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Channel in project grpc-java by grpc.

the class HeaderServerInterceptorTest method serverHeaderDeliveredToClient.

@Test
public void serverHeaderDeliveredToClient() {
    class SpyingClientInterceptor implements ClientInterceptor {

        ClientCall.Listener<?> spyListener;

        @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) {
                    spyListener = responseListener = mock(ClientCall.Listener.class, delegatesTo(responseListener));
                    super.start(responseListener, headers);
                }
            };
        }
    }
    SpyingClientInterceptor clientInterceptor = new SpyingClientInterceptor();
    GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(channel).withInterceptors(clientInterceptor);
    ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
    blockingStub.sayHello(HelloRequest.getDefaultInstance());
    assertNotNull(clientInterceptor.spyListener);
    verify(clientInterceptor.spyListener).onHeaders(metadataCaptor.capture());
    assertEquals("customRespondValue", metadataCaptor.getValue().get(HeaderServerInterceptor.CUSTOM_HEADER_KEY));
}
Also used : GreeterBlockingStub(io.grpc.examples.helloworld.GreeterGrpc.GreeterBlockingStub) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) ClientCall(io.grpc.ClientCall) ClientInterceptor(io.grpc.ClientInterceptor) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) Test(org.junit.Test)

Example 74 with Channel

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

the class BaseITTracingServerInterceptor method createsChildWhenJoinDisabled.

@Test
public void createsChildWhenJoinDisabled() throws IOException {
    tracing = tracingBuilder(NEVER_SAMPLE).supportsJoin(false).build();
    grpcTracing = GrpcTracing.create(tracing);
    init();
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    Channel channel = clientWithB3SingleHeader(parent);
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    assertChildOf(testSpanHandler.takeRemoteSpan(Span.Kind.SERVER), parent);
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 75 with Channel

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

the class BaseITTracingServerInterceptor method reusesPropagatedSpanId.

@Test
public void reusesPropagatedSpanId() {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    Channel channel = clientWithB3SingleHeader(parent);
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    assertSameIds(testSpanHandler.takeRemoteSpan(Span.Kind.SERVER), parent);
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Aggregations

Channel (io.grpc.Channel)63 Test (org.junit.Test)55 CallOptions (io.grpc.CallOptions)38 Metadata (io.grpc.Metadata)26 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)25 MethodDescriptor (io.grpc.MethodDescriptor)21 ClientInterceptor (io.grpc.ClientInterceptor)20 ManagedChannel (io.grpc.ManagedChannel)20 CountDownLatch (java.util.concurrent.CountDownLatch)16 ClientCall (io.grpc.ClientCall)14 ArrayList (java.util.ArrayList)14 ExecutorService (java.util.concurrent.ExecutorService)12 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)10 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)10 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)9 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)9 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)8 SocketAddress (java.net.SocketAddress)8