diff --git a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringService.java b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringService.java index fa6bb944a6d..046793bd5cd 100644 --- a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringService.java +++ b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringService.java @@ -21,31 +21,57 @@ import io.helidon.grpc.api.Grpc; import io.helidon.grpc.core.CollectingObserver; -import io.helidon.grpc.core.ResponseHelper; import io.grpc.stub.StreamObserver; import jakarta.enterprise.context.ApplicationScoped; +/** + * An implementation of a string service. + */ @Grpc.GrpcService @ApplicationScoped public class StringService { + /** + * Uppercase a string. + * + * @param request string message + * @return string message + */ @Grpc.Unary("Upper") public Strings.StringMessage upper(Strings.StringMessage request) { return newMessage(request.getText().toUpperCase()); } + /** + * Lowercase a string. + * + * @param request string message + * @return string message + */ @Grpc.Unary("Lower") public Strings.StringMessage lower(Strings.StringMessage request) { return newMessage(request.getText().toLowerCase()); } + /** + * Split a string using space delimiters. + * + * @param request string message + * @return stream of string messages + */ @Grpc.ServerStreaming("Split") - public void split(Strings.StringMessage request, StreamObserver observer) { + public Stream split(Strings.StringMessage request) { String[] parts = request.getText().split(" "); - ResponseHelper.stream(observer, Stream.of(parts).map(this::newMessage)); + return Stream.of(parts).map(this::newMessage); } + /** + * Join a stream of messages using spaces. + * + * @param observer stream of messages + * @return single message as a stream + */ @Grpc.ClientStreaming("Join") public StreamObserver join(StreamObserver observer) { return CollectingObserver.create( diff --git a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringServiceClient.java b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringServiceClient.java index 30994959de8..b03ee3e9089 100644 --- a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringServiceClient.java +++ b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/StringServiceClient.java @@ -16,23 +16,52 @@ package io.helidon.examples.microprofile.grpc; +import java.util.stream.Stream; + import io.helidon.grpc.api.Grpc; import io.grpc.stub.StreamObserver; +/** + * A client for a {@link StringService}. + */ @Grpc.GrpcService("StringService") @Grpc.GrpcChannel("string-channel") // see application.yaml public interface StringServiceClient { + /** + * Uppercase a string. + * + * @param request string message + * @return string message + */ @Grpc.Unary("Upper") Strings.StringMessage upper(Strings.StringMessage request); + /** + * Lowercase a string. + * + * @param request string message + * @return string message + */ @Grpc.Unary("Lower") Strings.StringMessage lower(Strings.StringMessage request); + /** + * Split a string using space delimiters. + * + * @param request string message + * @return stream of string messages + */ @Grpc.ServerStreaming("Split") - void split(Strings.StringMessage request, StreamObserver observer); + Stream split(Strings.StringMessage request); + /** + * Join a stream of messages using spaces. + * + * @param observer stream of messages + * @return single message as a stream + */ @Grpc.ClientStreaming("Join") StreamObserver join(StreamObserver observer); } diff --git a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/package-info.java b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/package-info.java index 870531c0bfe..fbf691b8081 100644 --- a/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/package-info.java +++ b/examples/microprofile/grpc/src/main/java/io/helidon/examples/microprofile/grpc/package-info.java @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.examples.microprofile.grpc; \ No newline at end of file +package io.helidon.examples.microprofile.grpc; diff --git a/examples/microprofile/grpc/src/test/java/io/helidon/examples/microprofile/grpc/StringServiceTest.java b/examples/microprofile/grpc/src/test/java/io/helidon/examples/microprofile/grpc/StringServiceTest.java index 763dfc91006..15f51306ff4 100644 --- a/examples/microprofile/grpc/src/test/java/io/helidon/examples/microprofile/grpc/StringServiceTest.java +++ b/examples/microprofile/grpc/src/test/java/io/helidon/examples/microprofile/grpc/StringServiceTest.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import io.helidon.grpc.api.Grpc; import io.helidon.microprofile.grpc.client.GrpcClientCdiExtension; @@ -57,10 +58,9 @@ void testUnaryLower() { } @Test - void testServerStreamingSplit() throws InterruptedException { - ListObserver response = new ListObserver<>(); - client.split(newMessage("hello world"), response); - List value = response.value(); + void testServerStreamingSplit() { + Stream stream = client.split(newMessage("hello world")); + List value = stream.toList(); assertThat(value, hasSize(2)); assertThat(value, contains(newMessage("hello"), newMessage("world"))); }