Search in sources :

Example 76 with CallOptions

use of io.grpc.CallOptions 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 77 with CallOptions

use of io.grpc.CallOptions 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 78 with CallOptions

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

the class BinderChannelSmokeTest method testSingleRequestCallOptionHeaders.

@Test
public void testSingleRequestCallOptionHeaders() throws Exception {
    CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(1234, MINUTES);
    assertThat(doCall(method, "Hello", callOptions).get()).isEqualTo("Hello");
    assertThat(headersCapture.get().get(GrpcUtil.TIMEOUT_KEY)).isGreaterThan(0);
}
Also used : CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 79 with CallOptions

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

the class BinderChannelSmokeTest method testStreamingCallOptionHeaders.

@Test
public void testStreamingCallOptionHeaders() throws Exception {
    CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(1234, MINUTES);
    QueueingStreamObserver<String> responseStreamObserver = new QueueingStreamObserver<>();
    StreamObserver<String> streamObserver = ClientCalls.asyncBidiStreamingCall(channel.newCall(bidiMethod, callOptions), responseStreamObserver);
    streamObserver.onCompleted();
    assertThat(withTestTimeout(responseStreamObserver.getAllStreamElements()).get()).isEmpty();
    assertThat(headersCapture.get().get(GrpcUtil.TIMEOUT_KEY)).isGreaterThan(0);
}
Also used : CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 80 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 = 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)

Aggregations

CallOptions (io.grpc.CallOptions)81 Test (org.junit.Test)61 Metadata (io.grpc.Metadata)50 Channel (io.grpc.Channel)36 MethodDescriptor (io.grpc.MethodDescriptor)28 ClientInterceptor (io.grpc.ClientInterceptor)23 ManagedChannel (io.grpc.ManagedChannel)18 ClientStreamTracer (io.grpc.ClientStreamTracer)17 ClientCall (io.grpc.ClientCall)15 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)11 Status (io.grpc.Status)11 Context (io.grpc.Context)10 Subchannel (io.grpc.LoadBalancer.Subchannel)10 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)10 ForwardingSubchannel (io.grpc.util.ForwardingSubchannel)9 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)8 NoopClientCall (io.grpc.internal.NoopClientCall)8 SocketAddress (java.net.SocketAddress)8 SimpleForwardingClientCallListener (io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener)7 ByteString (com.google.protobuf.ByteString)6