Search in sources :

Example 1 with DefaultGrpcClientMetadata

use of io.servicetalk.grpc.api.DefaultGrpcClientMetadata in project servicetalk by apple.

the class ProtocolCompatibilityTest method testGrpcErrorStreaming.

private static void testGrpcErrorStreaming(final CompatClient client, final TestServerContext server, final boolean withStatus, @Nullable final String compression, final GrpcStatusCode expectCode, @Nullable final String expectMessage) throws Exception {
    try {
        BufferEncoder encoder = serviceTalkCompression(compression);
        GrpcClientMetadata metadata = encoder == null ? DefaultGrpcClientMetadata.INSTANCE : new DefaultGrpcClientMetadata(encoder);
        final Publisher<CompatResponse> streamingResponse = client.bidirectionalStreamingCall(metadata, Publisher.from(CompatRequest.newBuilder().setId(3).build(), CompatRequest.newBuilder().setId(4).build(), CompatRequest.newBuilder().setId(5).build()));
        validateGrpcErrorInResponse(streamingResponse.toFuture(), withStatus, expectCode, expectMessage);
    } finally {
        closeAll(client, server);
    }
}
Also used : GrpcClientMetadata(io.servicetalk.grpc.api.GrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) BufferEncoder(io.servicetalk.encoding.api.BufferEncoder) CompatResponse(io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse)

Example 2 with DefaultGrpcClientMetadata

use of io.servicetalk.grpc.api.DefaultGrpcClientMetadata in project servicetalk by apple.

the class ProtocolCompatibilityTest method testBlockingRequestResponse.

private static void testBlockingRequestResponse(final BlockingCompatClient client, final TestServerContext server, final boolean streaming, @Nullable final String compression) throws Exception {
    try {
        final BufferEncoder compressor = serviceTalkCompression(compression);
        final GrpcClientMetadata metadata = compressor == null ? DefaultGrpcClientMetadata.INSTANCE : new DefaultGrpcClientMetadata(compressor);
        if (!streaming) {
            final CompatResponse response1 = client.scalarCall(metadata, CompatRequest.newBuilder().setId(1).build());
            assertEquals(1000001, response1.getSize());
        } else {
            // clientStreamingCall returns the "sum"
            final CompatResponse response2 = client.clientStreamingCall(metadata, asList(CompatRequest.newBuilder().setId(1).build(), CompatRequest.newBuilder().setId(2).build(), CompatRequest.newBuilder().setId(3).build()));
            assertEquals(1000006, response2.getSize());
            // serverStreamingCall returns a stream from 0 to N-1
            final BlockingIterable<CompatResponse> response3 = client.serverStreamingCall(metadata, CompatRequest.newBuilder().setId(3).build());
            final List<CompatResponse> response3List = new ArrayList<>();
            response3.forEach(response3List::add);
            assertEquals(3, response3List.size());
            assertEquals(1000000, response3List.get(0).getSize());
            assertEquals(1000001, response3List.get(1).getSize());
            assertEquals(1000002, response3List.get(2).getSize());
            // bidirectionalStreamingCall basically echos also
            final BlockingIterable<CompatResponse> response4 = client.bidirectionalStreamingCall(metadata, asList(CompatRequest.newBuilder().setId(3).build(), CompatRequest.newBuilder().setId(4).build(), CompatRequest.newBuilder().setId(5).build()));
            final List<CompatResponse> response4List = new ArrayList<>();
            response4.forEach(response4List::add);
            assertEquals(3, response4List.size());
            assertEquals(1000003, response4List.get(0).getSize());
            assertEquals(1000004, response4List.get(1).getSize());
            assertEquals(1000005, response4List.get(2).getSize());
        }
    } finally {
        closeAll(client, server);
    }
}
Also used : GrpcClientMetadata(io.servicetalk.grpc.api.GrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) BufferEncoder(io.servicetalk.encoding.api.BufferEncoder) CompatResponse(io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse) ArrayList(java.util.ArrayList)

Example 3 with DefaultGrpcClientMetadata

use of io.servicetalk.grpc.api.DefaultGrpcClientMetadata in project servicetalk by apple.

the class ProtocolCompatibilityTest method testRequestResponse.

private static void testRequestResponse(final CompatClient client, final TestServerContext server, final boolean streaming, @Nullable final String compression) throws Exception {
    try {
        final BufferEncoder compressor = serviceTalkCompression(compression);
        final GrpcClientMetadata metadata = compressor == null ? DefaultGrpcClientMetadata.INSTANCE : new DefaultGrpcClientMetadata(compressor);
        if (!streaming) {
            // scalarCall basically echos
            final Single<CompatResponse> response1 = client.scalarCall(metadata, CompatRequest.newBuilder().setId(1).build());
            assertEquals(1000001, response1.toFuture().get().getSize());
        } else {
            // clientStreamingCall returns the "sum"
            final Single<CompatResponse> response2 = client.clientStreamingCall(metadata, Publisher.from(CompatRequest.newBuilder().setId(1).build(), CompatRequest.newBuilder().setId(2).build(), CompatRequest.newBuilder().setId(3).build()));
            CompatResponse r = response2.toFuture().get();
            assertEquals(1000006, r.getSize());
            // serverStreamingCall returns a stream from 0 to N-1
            final Publisher<CompatResponse> response3 = client.serverStreamingCall(metadata, CompatRequest.newBuilder().setId(3).build());
            final List<CompatResponse> response3List = new ArrayList<>(response3.toFuture().get());
            assertEquals(3, response3List.size());
            assertEquals(1000000, response3List.get(0).getSize());
            assertEquals(1000001, response3List.get(1).getSize());
            assertEquals(1000002, response3List.get(2).getSize());
            // bidirectionalStreamingCall basically echos also
            final Publisher<CompatResponse> response4 = client.bidirectionalStreamingCall(metadata, Publisher.from(CompatRequest.newBuilder().setId(3).build(), CompatRequest.newBuilder().setId(4).build(), CompatRequest.newBuilder().setId(5).build()));
            final List<CompatResponse> response4List = new ArrayList<>(response4.toFuture().get());
            assertEquals(3, response4List.size());
            assertEquals(1000003, response4List.get(0).getSize());
            assertEquals(1000004, response4List.get(1).getSize());
            assertEquals(1000005, response4List.get(2).getSize());
        }
    } finally {
        closeAll(client, server);
    }
}
Also used : GrpcClientMetadata(io.servicetalk.grpc.api.GrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) BufferEncoder(io.servicetalk.encoding.api.BufferEncoder) CompatResponse(io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse) ArrayList(java.util.ArrayList)

Example 4 with DefaultGrpcClientMetadata

use of io.servicetalk.grpc.api.DefaultGrpcClientMetadata in project servicetalk by apple.

the class ProtocolCompatibilityTest method testGrpcErrorScalar.

private static void testGrpcErrorScalar(final CompatClient client, final TestServerContext server, final boolean withStatus, @Nullable final String compression, final GrpcStatusCode expectCode, @Nullable final String expectMessage) throws Exception {
    try {
        BufferEncoder encoder = serviceTalkCompression(compression);
        GrpcClientMetadata metadata = encoder == null ? DefaultGrpcClientMetadata.INSTANCE : new DefaultGrpcClientMetadata(encoder);
        final Single<CompatResponse> scalarResponse = client.scalarCall(metadata, CompatRequest.newBuilder().setId(1).build());
        validateGrpcErrorInResponse(scalarResponse.toFuture(), withStatus, expectCode, expectMessage);
    } finally {
        closeAll(client, server);
    }
}
Also used : GrpcClientMetadata(io.servicetalk.grpc.api.GrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) BufferEncoder(io.servicetalk.encoding.api.BufferEncoder) CompatResponse(io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse)

Example 5 with DefaultGrpcClientMetadata

use of io.servicetalk.grpc.api.DefaultGrpcClientMetadata in project servicetalk by apple.

the class DeadlineClient method main.

public static void main(String... args) throws Exception {
    try (GreeterClient client = GrpcClients.forAddress("localhost", 8080).defaultTimeout(ofMinutes(1)).build(new ClientFactory())) {
        // Make a request using default timeout (this will succeed)
        Single<HelloReply> respSingle1 = client.sayHello(HelloRequest.newBuilder().setName("DefaultTimeout").build()).whenOnError(System.err::println).whenOnSuccess(System.out::println);
        // Set the timeout for completion of this gRPC call to 3 seconds (this will timeout)
        Single<HelloReply> respSingle2 = client.sayHello(new DefaultGrpcClientMetadata(ofSeconds(3)), HelloRequest.newBuilder().setName("3SecondTimeout").build()).whenOnError(System.err::println).whenOnSuccess(System.out::println);
        // Issue the requests in parallel.
        collectUnorderedDelayError(respSingle1, respSingle2).toFuture().get();
    }
}
Also used : DefaultGrpcClientMetadata(io.servicetalk.grpc.api.DefaultGrpcClientMetadata) ClientFactory(io.grpc.examples.deadline.Greeter.ClientFactory) GreeterClient(io.grpc.examples.deadline.Greeter.GreeterClient) HelloReply(io.grpc.examples.deadline.HelloReply)

Aggregations

DefaultGrpcClientMetadata (io.servicetalk.grpc.api.DefaultGrpcClientMetadata)6 BufferEncoder (io.servicetalk.encoding.api.BufferEncoder)4 GrpcClientMetadata (io.servicetalk.grpc.api.GrpcClientMetadata)4 CompatResponse (io.servicetalk.grpc.netty.CompatProto.ResponseContainer.CompatResponse)4 ArrayList (java.util.ArrayList)2 ClientFactory (io.grpc.examples.compression.Greeter.ClientFactory)1 GreeterClient (io.grpc.examples.compression.Greeter.GreeterClient)1 HelloReply (io.grpc.examples.compression.HelloReply)1 ClientFactory (io.grpc.examples.deadline.Greeter.ClientFactory)1 GreeterClient (io.grpc.examples.deadline.Greeter.GreeterClient)1 HelloReply (io.grpc.examples.deadline.HelloReply)1 BufferDecoderGroupBuilder (io.servicetalk.encoding.api.BufferDecoderGroupBuilder)1