Search in sources :

Example 56 with Channel

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

the class BinaryLogProviderTest method wrapChannel_methodDescriptor.

@Test
public void wrapChannel_methodDescriptor() throws Exception {
    final AtomicReference<MethodDescriptor<?, ?>> methodRef = new AtomicReference<>();
    Channel channel = new Channel() {

        @Override
        public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions) {
            methodRef.set(method);
            return new NoopClientCall<>();
        }

        @Override
        public String authority() {
            throw new UnsupportedOperationException();
        }
    };
    Channel wChannel = binlogProvider.wrapChannel(channel);
    ClientCall<String, Integer> unusedClientCall = wChannel.newCall(method, CallOptions.DEFAULT);
    validateWrappedMethod(methodRef.get());
}
Also used : NoopClientCall(io.grpc.internal.NoopClientCall) Channel(io.grpc.Channel) AtomicReference(java.util.concurrent.atomic.AtomicReference) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) Test(org.junit.Test)

Example 57 with Channel

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

the class ServerImplTest method binaryLogInstalled.

@Test
public void binaryLogInstalled() throws Exception {
    final SettableFuture<Boolean> intercepted = SettableFuture.create();
    final ServerInterceptor interceptor = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            intercepted.set(true);
            return next.startCall(call, headers);
        }
    };
    builder.binlog = new BinaryLog() {

        @Override
        public void close() throws IOException {
        // noop
        }

        @Override
        public <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition(ServerMethodDefinition<ReqT, RespT> oMethodDef) {
            return ServerMethodDefinition.create(oMethodDef.getMethodDescriptor(), InternalServerInterceptors.interceptCallHandlerCreate(interceptor, oMethodDef.getServerCallHandler()));
        }

        @Override
        public Channel wrapChannel(Channel channel) {
            return channel;
        }
    };
    createAndStartServer();
    basicExchangeHelper(METHOD, "Lots of pizza, please", 314, 50);
    assertTrue(intercepted.get());
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) IOException(java.io.IOException) BinaryLog(io.grpc.BinaryLog) ServerMethodDefinition(io.grpc.ServerMethodDefinition) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 58 with Channel

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

the class AbstractFutureStubTest method defaultCallOptions.

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

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

Example 59 with Channel

use of 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 60 with Channel

use of 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)

Aggregations

Channel (io.grpc.Channel)60 CallOptions (io.grpc.CallOptions)37 Test (org.junit.Test)33 Metadata (io.grpc.Metadata)25 MethodDescriptor (io.grpc.MethodDescriptor)20 ClientInterceptor (io.grpc.ClientInterceptor)19 ManagedChannel (io.grpc.ManagedChannel)17 ClientCall (io.grpc.ClientCall)14 SocketAddress (java.net.SocketAddress)8 ByteString (com.google.protobuf.ByteString)7 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)7 NoopClientCall (io.grpc.internal.NoopClientCall)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Duration (com.google.protobuf.Duration)5 ChannelLogger (io.grpc.ChannelLogger)5 Status (io.grpc.Status)5 ClientStreamTracer (io.grpc.ClientStreamTracer)4 ForwardingClientCall (io.grpc.ForwardingClientCall)4 SimpleForwardingClientCallListener (io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener)4 Subchannel (io.grpc.LoadBalancer.Subchannel)4