Search in sources :

Example 16 with CallOptions

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

the class AbstractBlockingStubTest method defaultCallOptions.

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

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

Example 17 with CallOptions

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

the class ClientCallsTest method blockingUnaryCall_HasBlockingStubType.

@Test
public void blockingUnaryCall_HasBlockingStubType() {
    NoopClientCall<Integer, Integer> call = new NoopClientCall<Integer, Integer>() {

        @Override
        public void start(io.grpc.ClientCall.Listener<Integer> listener, Metadata headers) {
            listener.onMessage(1);
            listener.onClose(Status.OK, new Metadata());
        }
    };
    when(mockChannel.newCall(ArgumentMatchers.<MethodDescriptor<Integer, Integer>>any(), any(CallOptions.class))).thenReturn(call);
    Integer unused = ClientCalls.blockingUnaryCall(mockChannel, UNARY_METHOD, CallOptions.DEFAULT, 1);
    verify(mockChannel).newCall(methodDescriptorCaptor.capture(), callOptionsCaptor.capture());
    CallOptions capturedCallOption = callOptionsCaptor.getValue();
    assertThat(capturedCallOption.getOption(ClientCalls.STUB_TYPE_OPTION)).isEquivalentAccordingToCompareTo(StubType.BLOCKING);
}
Also used : NoopClientCall(io.grpc.internal.NoopClientCall) SimpleForwardingClientCallListener(io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 18 with CallOptions

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

the class ClientCallsTest method blockingServerStreamingCall_HasBlockingStubType.

@Test
public void blockingServerStreamingCall_HasBlockingStubType() {
    NoopClientCall<Integer, Integer> call = new NoopClientCall<Integer, Integer>() {

        @Override
        public void start(io.grpc.ClientCall.Listener<Integer> listener, Metadata headers) {
            listener.onMessage(1);
            listener.onClose(Status.OK, new Metadata());
        }
    };
    when(mockChannel.newCall(ArgumentMatchers.<MethodDescriptor<Integer, Integer>>any(), any(CallOptions.class))).thenReturn(call);
    Iterator<Integer> unused = ClientCalls.blockingServerStreamingCall(mockChannel, UNARY_METHOD, CallOptions.DEFAULT, 1);
    verify(mockChannel).newCall(methodDescriptorCaptor.capture(), callOptionsCaptor.capture());
    CallOptions capturedCallOption = callOptionsCaptor.getValue();
    assertThat(capturedCallOption.getOption(ClientCalls.STUB_TYPE_OPTION)).isEquivalentAccordingToCompareTo(StubType.BLOCKING);
}
Also used : NoopClientCall(io.grpc.internal.NoopClientCall) SimpleForwardingClientCallListener(io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 19 with CallOptions

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

the class AbstractAsyncStubTest method newStub_futureStub_throwsException.

@Test
@SuppressWarnings("AssertionFailureIgnored")
public void newStub_futureStub_throwsException() {
    try {
        NoopFutureStub unused = NoopAsyncStub.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 AbstractAsyncStub");
    }
}
Also used : NoopFutureStub(io.grpc.stub.AbstractFutureStubTest.NoopFutureStub) Channel(io.grpc.Channel) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 20 with CallOptions

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

the class AbstractAsyncStubTest method defaultCallOptions.

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

        @Override
        public NoopAsyncStub newStub(Channel channel, CallOptions callOptions) {
            return create(channel, callOptions);
        }
    }, channel, CallOptions.DEFAULT);
    assertThat(stub.getCallOptions().getOption(ClientCalls.STUB_TYPE_OPTION)).isEqualTo(StubType.ASYNC);
}
Also used : Channel(io.grpc.Channel) CallOptions(io.grpc.CallOptions) NoopAsyncStub(io.grpc.stub.AbstractAsyncStubTest.NoopAsyncStub) 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