Subject: [PATCH] gRPC Tests --- Index: webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcStubTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcStubTest.java b/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcStubTest.java --- a/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcStubTest.java (revision 0d882d1e78301a69cdcd7ddf770c4c43b5558a4a) +++ b/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcStubTest.java (date 1713948076884) @@ -16,7 +16,9 @@ package io.helidon.webclient.grpc.tests; +import java.nio.charset.StandardCharsets; import java.util.Iterator; +import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -28,6 +30,7 @@ import io.helidon.webclient.grpc.GrpcClient; import io.helidon.webserver.WebServer; import io.helidon.webserver.testing.junit5.ServerTest; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.grpc.stub.StreamObserver; @@ -144,4 +147,34 @@ Iterator res = future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS); assertThat(res.hasNext(), is(false)); } + + @Test + void testBidirectionalEchoAsyncWithLargePayload() throws ExecutionException, InterruptedException, TimeoutException { + GrpcClient grpcClient = webClient.client(GrpcClient.PROTOCOL); + StringServiceGrpc.StringServiceStub service = StringServiceGrpc.newStub(grpcClient.channel()); + CompletableFuture> future = new CompletableFuture<>(); + StreamObserver req = service.echo(multiStreamObserver(future)); + byte[] array = new byte[2000]; + new Random().nextBytes(array); + String largeString = new String(array, StandardCharsets.UTF_8); + req.onNext(newStringMessage(largeString)); + req.onCompleted(); + Iterator res = future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS); + assertThat(res.next().getText(), is(largeString)); + assertThat(res.hasNext(), is(false)); + } + + @Test + void testReceiveServerException() { + GrpcClient grpcClient = webClient.client(GrpcClient.PROTOCOL); + StringServiceGrpc.StringServiceBlockingStub service = StringServiceGrpc.newBlockingStub(grpcClient.channel()); + Assertions.assertThrows(Throwable.class, () -> service.badMethod(newStringMessage("hello"))); + } + + @Test + void testCallingNotImplementMethodThrowsException() { + GrpcClient grpcClient = webClient.client(GrpcClient.PROTOCOL); + StringServiceGrpc.StringServiceBlockingStub service = StringServiceGrpc.newBlockingStub(grpcClient.channel()); + Assertions.assertThrows(Throwable.class, () -> service.notImplementedMethod(newStringMessage("hello"))); + } } Index: webclient/tests/grpc/src/main/proto/strings.proto IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/webclient/tests/grpc/src/main/proto/strings.proto b/webclient/tests/grpc/src/main/proto/strings.proto --- a/webclient/tests/grpc/src/main/proto/strings.proto (revision 0d882d1e78301a69cdcd7ddf770c4c43b5558a4a) +++ b/webclient/tests/grpc/src/main/proto/strings.proto (date 1713947762840) @@ -23,6 +23,8 @@ rpc Split (StringMessage) returns (stream StringMessage) {} rpc Join (stream StringMessage) returns (StringMessage) {} rpc Echo (stream StringMessage) returns (stream StringMessage) {} + rpc BadMethod (StringMessage) returns (StringMessage) {} + rpc NotImplementedMethod (StringMessage) returns (StringMessage) {} } message StringMessage { Index: webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcBaseTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcBaseTest.java b/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcBaseTest.java --- a/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcBaseTest.java (revision 0d882d1e78301a69cdcd7ddf770c4c43b5558a4a) +++ b/webclient/tests/grpc/src/test/java/io/helidon/webclient/grpc/tests/GrpcBaseTest.java (date 1713947622122) @@ -27,6 +27,7 @@ import io.grpc.ClientCall; import io.grpc.ClientInterceptor; import io.grpc.MethodDescriptor; +import io.grpc.Status; import io.grpc.stub.StreamObserver; import io.helidon.common.Weight; import io.helidon.common.configurable.Resource; @@ -74,7 +75,11 @@ .bidi(Strings.getDescriptor(), "StringService", "Echo", - GrpcStubTest::echo); + GrpcStubTest::echo) + .unary(Strings.getDescriptor(), + "StringService", + "BadMethod", + GrpcStubTest::badMethod); } @BeforeEach @@ -154,6 +159,10 @@ }; } + static void badMethod(Strings.StringMessage req, StreamObserver streamObserver) { + streamObserver.onError(Status.INTERNAL.asException()); + } + Strings.StringMessage newStringMessage(String data) { return Strings.StringMessage.newBuilder().setText(data).build(); }