Search in sources :

Example 16 with CallOptions

use of io.grpc.CallOptions in project grpc-java by grpc.

the class StubConfigTest method testStubCallOptionsPopulatedToNewCall.

@Test
public void testStubCallOptionsPopulatedToNewCall() {
    TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
    CallOptions options1 = stub.getCallOptions();
    SimpleRequest request = SimpleRequest.getDefaultInstance();
    stub.unaryCall(request, responseObserver);
    verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options1));
    stub = stub.withDeadlineAfter(2, NANOSECONDS);
    CallOptions options2 = stub.getCallOptions();
    assertNotSame(options1, options2);
    stub.unaryCall(request, responseObserver);
    verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options2));
}
Also used : CallOptions(io.grpc.CallOptions) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) TestServiceGrpc(io.grpc.testing.integration.TestServiceGrpc) Test(org.junit.Test)

Example 17 with CallOptions

use of io.grpc.CallOptions 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 = spy(responseListener);
                    super.start(responseListener, headers);
                }
            };
        }
    }
    SpyingClientInterceptor clientInterceptor = new SpyingClientInterceptor();
    GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(inProcessChannel).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) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) ClientInterceptor(io.grpc.ClientInterceptor) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) Test(org.junit.Test)

Example 18 with CallOptions

use of io.grpc.CallOptions in project grpc-java by grpc.

the class AbstractStubTest method withWaitForReady.

@Test()
public void withWaitForReady() {
    NoopStub stub = new NoopStub(channel);
    CallOptions callOptions = stub.getCallOptions();
    assertFalse(callOptions.isWaitForReady());
    stub = stub.withWaitForReady();
    callOptions = stub.getCallOptions();
    assertTrue(callOptions.isWaitForReady());
}
Also used : CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Aggregations

CallOptions (io.grpc.CallOptions)18 Test (org.junit.Test)12 Metadata (io.grpc.Metadata)11 MethodDescriptor (io.grpc.MethodDescriptor)8 Channel (io.grpc.Channel)5 ClientInterceptor (io.grpc.ClientInterceptor)5 Context (io.grpc.Context)4 ManagedChannel (io.grpc.ManagedChannel)4 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)3 StatsContext (com.google.instrumentation.stats.StatsContext)2 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)2 Subchannel (io.grpc.LoadBalancer.Subchannel)2 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)2 Executor (java.util.concurrent.Executor)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Matchers.anyString (org.mockito.Matchers.anyString)2 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteString (com.google.protobuf.ByteString)1 Topic (com.google.pubsub.v1.Topic)1