Search in sources :

Example 1 with CompatClient

use of io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient in project servicetalk by apple.

the class ProtocolCompatibilityTest method grpcJavaToServiceTalkErrorWithStatus.

@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void grpcJavaToServiceTalkErrorWithStatus(final boolean ssl, final boolean streaming, final String compression) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS, ssl, compression, null);
    final CompatClient client = grpcJavaClient(server.listenAddress(), compression, ssl, null);
    testGrpcError(client, server, true, streaming, compression);
}
Also used : BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with CompatClient

use of io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient in project servicetalk by apple.

the class ProtocolCompatibilityTest method serviceTalkToServiceTalkErrorWithStatus.

@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void serviceTalkToServiceTalkErrorWithStatus(final boolean ssl, final boolean streaming, final String compression) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS, ssl, compression, null);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl, compression, null);
    testGrpcError(client, server, true, streaming, compression);
}
Also used : BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with CompatClient

use of io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient in project servicetalk by apple.

the class ProtocolCompatibilityTest method serviceTalkToServiceTalkError.

@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void serviceTalkToServiceTalkError(final boolean ssl, final boolean streaming, final String compression) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE, ssl, compression, null);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl, compression, null);
    testGrpcError(client, server, false, streaming, compression);
}
Also used : BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with CompatClient

use of io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient in project servicetalk by apple.

the class ProtocolCompatibilityTest method grpcJavaClient.

// Wrap grpc client in our client interface to simplify test code
private static CompatClient grpcJavaClient(final SocketAddress address, @Nullable final String compression, final boolean ssl, @Nullable Duration timeout) throws Exception {
    final NettyChannelBuilder builder = NettyChannelBuilder.forAddress(address);
    if (ssl) {
        final SslContext context = GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
        builder.sslContext(context);
    } else {
        builder.usePlaintext();
    }
    final ManagedChannel channel = builder.build();
    // stub is immutable and each builder step returns a new instance.
    CompatGrpc.CompatStub stub = CompatGrpc.newStub(channel);
    if (compression != null) {
        stub = stub.withCompression(compression);
    }
    if (null != timeout) {
        stub = stub.withDeadlineAfter(timeout.toNanos(), NANOSECONDS);
    }
    final CompatGrpc.CompatStub finalStub = stub;
    return new CompatClient() {

        @Override
        public GrpcExecutionContext executionContext() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Publisher<CompatResponse> bidirectionalStreamingCall(final Publisher<CompatRequest> request) {
            final PublisherSource.Processor<CompatResponse, CompatResponse> processor = newPublisherProcessor(3);
            sendRequest(request, finalStub.bidirectionalStreamingCall(adaptResponse(processor)));
            return fromSource(processor);
        }

        @Override
        public Publisher<CompatResponse> bidirectionalStreamingCall(final GrpcClientMetadata metadata, final Publisher<CompatRequest> request) {
            return bidirectionalStreamingCall(request);
        }

        @Deprecated
        @Override
        public Publisher<CompatResponse> bidirectionalStreamingCall(final BidirectionalStreamingCallMetadata metadata, final Publisher<CompatRequest> request) {
            return bidirectionalStreamingCall(request);
        }

        @SuppressWarnings("unchecked")
        @Override
        public Single<CompatResponse> clientStreamingCall(final Publisher<CompatRequest> request) {
            final Processor<CompatResponse, CompatResponse> processor = newSingleProcessor();
            final StreamObserver<CompatRequest> requestObserver = finalStub.clientStreamingCall(adaptResponse(processor));
            sendRequest(request, requestObserver);
            return (Single<CompatResponse>) processor;
        }

        @Deprecated
        @Override
        public Single<CompatResponse> clientStreamingCall(final ClientStreamingCallMetadata metadata, final Publisher<CompatRequest> request) {
            return clientStreamingCall(request);
        }

        @Override
        public Single<CompatResponse> clientStreamingCall(final GrpcClientMetadata metadata, final Publisher<CompatRequest> request) {
            return clientStreamingCall(request);
        }

        @SuppressWarnings("unchecked")
        @Override
        public Single<CompatResponse> scalarCall(final CompatRequest request) {
            final Processor<CompatResponse, CompatResponse> processor = newSingleProcessor();
            finalStub.scalarCall(request, adaptResponse(processor));
            return (Single<CompatResponse>) processor;
        }

        @Deprecated
        @Override
        public Single<CompatResponse> scalarCall(final ScalarCallMetadata metadata, final CompatRequest request) {
            return scalarCall(request);
        }

        @Override
        public Single<CompatResponse> scalarCall(final GrpcClientMetadata metadata, final CompatRequest request) {
            return scalarCall(request);
        }

        @Override
        public Publisher<CompatResponse> serverStreamingCall(final CompatRequest request) {
            final PublisherSource.Processor<CompatResponse, CompatResponse> processor = newPublisherProcessor(3);
            finalStub.serverStreamingCall(request, adaptResponse(processor));
            return fromSource(processor);
        }

        @Deprecated
        @Override
        public Publisher<CompatResponse> serverStreamingCall(final ServerStreamingCallMetadata metadata, final CompatRequest request) {
            return serverStreamingCall(request);
        }

        @Override
        public Publisher<CompatResponse> serverStreamingCall(final GrpcClientMetadata metadata, final CompatRequest request) {
            return serverStreamingCall(request);
        }

        @Override
        public void close() throws Exception {
            channel.shutdown().awaitTermination(DEFAULT_TIMEOUT_SECONDS, SECONDS);
        }

        @Override
        public Completable closeAsync() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Completable onClose() {
            throw new UnsupportedOperationException();
        }

        @Override
        public BlockingCompatClient asBlockingClient() {
            throw new UnsupportedOperationException();
        }

        private void sendRequest(final Publisher<CompatRequest> request, final StreamObserver<CompatRequest> requestObserver) {
            request.whenOnComplete(requestObserver::onCompleted).whenOnError(requestObserver::onError).forEach(requestObserver::onNext);
        }

        private StreamObserver<CompatResponse> adaptResponse(final Processor<CompatResponse, CompatResponse> processor) {
            return new StreamObserver<CompatResponse>() {

                @Override
                public void onNext(final CompatResponse value) {
                    processor.onSuccess(value);
                }

                @Override
                public void onError(final Throwable t) {
                    processor.onError(t);
                }

                @Override
                public void onCompleted() {
                // ignored
                }
            };
        }

        private StreamObserver<CompatResponse> adaptResponse(final PublisherSource.Processor<CompatResponse, CompatResponse> processor) {
            return new StreamObserver<CompatResponse>() {

                @Override
                public void onNext(final CompatResponse value) {
                    processor.onNext(value);
                }

                @Override
                public void onError(final Throwable t) {
                    processor.onError(t);
                }

                @Override
                public void onCompleted() {
                    processor.onComplete();
                }
            };
        }
    };
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BidirectionalStreamingCallMetadata(io.servicetalk.grpc.netty.CompatProto.Compat.BidirectionalStreamingCallMetadata) Processors.newSingleProcessor(io.servicetalk.concurrent.api.Processors.newSingleProcessor) Processor(io.servicetalk.concurrent.SingleSource.Processor) Processors.newPublisherProcessor(io.servicetalk.concurrent.api.Processors.newPublisherProcessor) PublisherSource(io.servicetalk.concurrent.PublisherSource) ScalarCallMetadata(io.servicetalk.grpc.netty.CompatProto.Compat.ScalarCallMetadata) Publisher(io.servicetalk.concurrent.api.Publisher) GrpcClientMetadata(io.servicetalk.grpc.api.GrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) ServerStreamingCallMetadata(io.servicetalk.grpc.netty.CompatProto.Compat.ServerStreamingCallMetadata) Single(io.servicetalk.concurrent.api.Single) BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) CompatResponse(io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ManagedChannel(io.grpc.ManagedChannel) CompatRequest(io.servicetalk.grpc.netty.CompatProto.RequestContainer.CompatRequest) ClientStreamingCallMetadata(io.servicetalk.grpc.netty.CompatProto.Compat.ClientStreamingCallMetadata) SslContext(io.netty.handler.ssl.SslContext)

Example 5 with CompatClient

use of io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient in project servicetalk by apple.

the class ProtocolCompatibilityTest method serviceTalkToServiceTalk.

@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void serviceTalkToServiceTalk(final boolean ssl, final boolean streaming, final String compression) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.NONE, ssl, compression, null);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl, compression, null);
    testRequestResponse(client, server, streaming, compression);
}
Also used : BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

BlockingCompatClient (io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient)35 CompatClient (io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 MethodSource (org.junit.jupiter.params.provider.MethodSource)33 ServerContext (io.servicetalk.transport.api.ServerContext)5 PublisherSource (io.servicetalk.concurrent.PublisherSource)2 CompatRequest (io.servicetalk.grpc.netty.CompatProto.RequestContainer.CompatRequest)2 ManagedChannel (io.grpc.ManagedChannel)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 StreamObserver (io.grpc.stub.StreamObserver)1 SslContext (io.netty.handler.ssl.SslContext)1 Processor (io.servicetalk.concurrent.SingleSource.Processor)1 Processors.newPublisherProcessor (io.servicetalk.concurrent.api.Processors.newPublisherProcessor)1 Processors.newSingleProcessor (io.servicetalk.concurrent.api.Processors.newSingleProcessor)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 Single (io.servicetalk.concurrent.api.Single)1 DefaultGrpcClientMetadata (io.servicetalk.grpc.api.DefaultGrpcClientMetadata)1 GrpcClientMetadata (io.servicetalk.grpc.api.GrpcClientMetadata)1 BidirectionalStreamingCallMetadata (io.servicetalk.grpc.netty.CompatProto.Compat.BidirectionalStreamingCallMetadata)1 ClientStreamingCallMetadata (io.servicetalk.grpc.netty.CompatProto.Compat.ClientStreamingCallMetadata)1