Search in sources :

Example 21 with CallOptions

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

the class AbstractFutureStubTest method newStub_asyncStub_throwsException.

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

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

Example 22 with CallOptions

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

the class BaseAbstractStubTest method withWaitForReady.

@Test
public void withWaitForReady() {
    T stub = create(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)

Example 23 with CallOptions

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

the class LoggingChannelProviderTest method forAddress_interceptorCalled.

@Test
public void forAddress_interceptorCalled() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class, delegatesTo(new NoopInterceptor()));
    InternalLoggingChannelInterceptor.Factory factory = mock(InternalLoggingChannelInterceptor.Factory.class);
    when(factory.create()).thenReturn(interceptor);
    LoggingChannelProvider.init(factory);
    ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress("localhost", 80);
    ManagedChannel channel = builder.build();
    CallOptions callOptions = CallOptions.DEFAULT;
    ClientCall<Void, Void> unused = channel.newCall(method, callOptions);
    verify(interceptor).interceptCall(same(method), same(callOptions), ArgumentMatchers.<Channel>any());
    channel.shutdownNow();
    LoggingChannelProvider.finish();
}
Also used : InternalLoggingChannelInterceptor(io.grpc.observability.interceptors.InternalLoggingChannelInterceptor) ClientInterceptor(io.grpc.ClientInterceptor) ManagedChannel(io.grpc.ManagedChannel) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 24 with CallOptions

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

the class LoggingChannelProviderTest method forTarget_interceptorCalled.

@Test
public void forTarget_interceptorCalled() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class, delegatesTo(new NoopInterceptor()));
    InternalLoggingChannelInterceptor.Factory factory = mock(InternalLoggingChannelInterceptor.Factory.class);
    when(factory.create()).thenReturn(interceptor);
    LoggingChannelProvider.init(factory);
    ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forTarget("localhost");
    ManagedChannel channel = builder.build();
    CallOptions callOptions = CallOptions.DEFAULT;
    ClientCall<Void, Void> unused = channel.newCall(method, callOptions);
    verify(interceptor).interceptCall(same(method), same(callOptions), ArgumentMatchers.<Channel>any());
    channel.shutdownNow();
    LoggingChannelProvider.finish();
}
Also used : InternalLoggingChannelInterceptor(io.grpc.observability.interceptors.InternalLoggingChannelInterceptor) ClientInterceptor(io.grpc.ClientInterceptor) ManagedChannel(io.grpc.ManagedChannel) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 25 with CallOptions

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

the class CronetClientStreamTest method withAnnotation.

@Test
public void withAnnotation() {
    Object annotation1 = new Object();
    Object annotation2 = new Object();
    CallOptions callOptions = CronetClientStream.withAnnotation(CallOptions.DEFAULT, annotation1);
    callOptions = CronetClientStream.withAnnotation(callOptions, annotation2);
    SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(factory);
    CronetClientStream stream = new CronetClientStream("https://www.google.com:443", "cronet", executor, metadata, transport, callback, lock, 100, false, /* alwaysUsePut */
    method, StatsTraceContext.NOOP, callOptions, transportTracer, false, false);
    callback.setStream(stream);
    when(factory.newBidirectionalStreamBuilder(any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class))).thenReturn(builder);
    stream.start(clientListener);
    verify(builder).addRequestAnnotation(annotation1);
    verify(builder).addRequestAnnotation(annotation2);
}
Also used : Executor(java.util.concurrent.Executor) CallOptions(io.grpc.CallOptions) 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