Skip to content

Commit

Permalink
Moves gRPC tracing support into a new module. Creates a new module fo…
Browse files Browse the repository at this point in the history
…r testing gRPC.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas committed Jul 5, 2024
1 parent 7b69f5f commit efb4400
Show file tree
Hide file tree
Showing 34 changed files with 373 additions and 67 deletions.
4 changes: 4 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-server</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.metrics</groupId>
<artifactId>helidon-metrics</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
<artifactId>helidon-microprofile-grpc-server</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-tracing</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- Micronaut integrations -->
<dependency>
<groupId>io.helidon.integrations.micronaut</groupId>
Expand Down
2 changes: 2 additions & 0 deletions microprofile/grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<module>api</module>
<module>core</module>
<module>server</module>
<module>tracing</module>
<module>tests</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.helidon.microprofile.server.ServerCdiExtension;
import io.helidon.webserver.grpc.GrpcRouting;
import io.helidon.webserver.grpc.GrpcService;
import io.helidon.webserver.grpc.GrpcTracingConfig;

import io.grpc.BindableService;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -122,8 +121,7 @@ private boolean hasGrpcQualifier(Bean<?> bean) {
private void register(Object service, GrpcRouting.Builder builder, Class<?> cls, BeanManager beanManager) {
GrpcServiceBuilder serviceBuilder = GrpcServiceBuilder.create(cls, () -> service, beanManager);
if (serviceBuilder.isAnnotatedService()) {
GrpcTracingConfig tracingConfig = GrpcTracingConfig.create(config.get("tracing.grpc"));
builder.service(serviceBuilder.build(), tracingConfig);
builder.service(serviceBuilder.build());
} else {
LOGGER.log(Level.WARNING,
() -> "Discovered type is not a properly annotated gRPC service " + service.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/

/**
* Microprofile 1.0 gRPC server implementation.
* Microprofile gRPC server implementation.
*/
package io.helidon.microprofile.grpc.server;
2 changes: 1 addition & 1 deletion microprofile/grpc/server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* gRPC microprofile server module
*/
@Feature(value = "gRPC",
description = "Helidon MP gRPC implementation",
description = "Helidon gRPC MP server",
in = HelidonFlavor.MP,
path = "gRPC"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.helidon.microprofile.grpc.server.spi.GrpcMpContext;
import io.helidon.microprofile.grpc.server.spi.GrpcMpExtension;
import io.helidon.microprofile.testing.junit5.AddBean;
import io.helidon.microprofile.testing.junit5.AddExtension;
import io.helidon.microprofile.testing.junit5.HelidonTest;

Expand All @@ -32,6 +33,8 @@

@HelidonTest
@AddExtension(GrpcMpCdiExtension.class)
@AddBean(GrpcMpExtensionTest.Extension1.class)
@AddBean(GrpcMpExtensionTest.Extension2.class)
public class GrpcMpExtensionTest {

private static final Set<Class<?>> EXTENSIONS_LOADED = new HashSet<>();
Expand Down
103 changes: 103 additions & 0 deletions microprofile/grpc/tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2024 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-project</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>helidon-microprofile-grpc-tests</artifactId>
<name>Helidon Microprofile gRPC Tests</name>

<dependencies>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.grpc</groupId>
<artifactId>helidon-grpc-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-tracing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5-grpc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<!--
need to use this version to work around the same groupId/artifactId and
different package names in Jakarta
This is needed for the Generated annotation in grpc sources
-->
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${version.plugin.os}</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
<goal>test-compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* gRPC tests module.
*/
package io.helidon.microprofile.grpc.tests;
18 changes: 18 additions & 0 deletions microprofile/grpc/tests/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module helidon.microprofile.grpc.tests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*/

package io.helidon.microprofile.grpc.server;
package io.helidon.microprofile.grpc.tests;

import io.helidon.common.configurable.Resource;
import io.helidon.common.tls.Tls;
import io.helidon.microprofile.grpc.server.GrpcMpCdiExtension;
import io.helidon.microprofile.testing.junit5.AddExtension;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import io.helidon.webclient.grpc.GrpcClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.helidon.microprofile.grpc.server;
package io.helidon.microprofile.grpc.tests;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
Expand All @@ -27,8 +27,8 @@
import io.helidon.microprofile.grpc.api.GrpcInterceptorBinding;
import io.helidon.microprofile.grpc.api.GrpcInterceptors;
import io.helidon.microprofile.grpc.api.Unary;
import io.helidon.microprofile.grpc.server.test.Echo;
import io.helidon.microprofile.grpc.server.test.EchoServiceGrpc;
import io.helidon.microprofile.grpc.tests.test.Echo;
import io.helidon.microprofile.grpc.tests.test.EchoServiceGrpc;
import io.helidon.tracing.Tracer;

import io.grpc.Context;
Expand Down Expand Up @@ -79,8 +79,8 @@ private Echo.EchoRequest fromString(String value) {
}

/**
* A service that is annotated by {@link Grpc}. Should be discovered by
* {@link GrpcMpCdiExtension}. References two interceptors, one directly
* A service that is annotated by {@link io.helidon.microprofile.grpc.api.Grpc}. Should be discovered by
* {@link io.helidon.microprofile.grpc.server.GrpcMpCdiExtension}. References two interceptors, one directly
* and one via an interceptor binding.
*/
@Grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
* limitations under the License.
*/

package io.helidon.microprofile.grpc.server;
package io.helidon.microprofile.grpc.tests;

import io.helidon.microprofile.grpc.server.test.Hash;
import io.helidon.microprofile.grpc.server.test.HashServiceGrpc;
import io.helidon.grpc.core.ResponseHelper;
import io.helidon.microprofile.grpc.tests.test.Hash;
import io.helidon.microprofile.grpc.tests.test.HashServiceGrpc;
import io.helidon.webserver.grpc.GrpcService;

import com.google.protobuf.Descriptors;
import io.grpc.stub.StreamObserver;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.client.WebTarget;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;

import static io.helidon.grpc.core.ResponseHelper.complete;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;

class HashServiceTest extends BaseServiceTest {
Expand All @@ -42,12 +42,12 @@ public HashServiceTest(WebTarget webTarget) {
void testHash() {
HashServiceGrpc.HashServiceBlockingStub service = HashServiceGrpc.newBlockingStub(grpcClient().channel());
Hash.Value res = service.hash(Hash.Message.newBuilder().setText("hello world").build());
assertThat(res.getText(), is(String.valueOf("hello world".hashCode())));
MatcherAssert.assertThat(res.getText(), is(String.valueOf("hello world".hashCode())));
}

/**
* A service that implements the {@link GrpcService} interface. Should be
* discovered by {@link GrpcMpCdiExtension}.
* discovered by {@link io.helidon.microprofile.grpc.server.GrpcMpCdiExtension}.
*/
@ApplicationScoped
public static class HashService implements GrpcService {
Expand All @@ -62,7 +62,7 @@ public void update(Routing routing) {
}

public void hash(Hash.Message request, StreamObserver<Hash.Value> observer) {
complete(observer, Hash.Value.newBuilder().setText(
ResponseHelper.complete(observer, Hash.Value.newBuilder().setText(
String.valueOf(request.getText().hashCode())).build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
* limitations under the License.
*/

package io.helidon.microprofile.grpc.server;
package io.helidon.microprofile.grpc.tests;

import io.grpc.stub.StreamObserver;

import io.helidon.microprofile.grpc.server.test.Random;
import io.helidon.microprofile.grpc.server.test.RandomServiceGrpc;
import io.helidon.grpc.core.ResponseHelper;
import io.helidon.microprofile.grpc.tests.test.Random;
import io.helidon.microprofile.grpc.tests.test.RandomServiceGrpc;

import io.grpc.stub.StreamObserver;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.client.WebTarget;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;

import static io.helidon.grpc.core.ResponseHelper.complete;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.MatcherAssert.assertThat;

class RandomServiceTest extends BaseServiceTest {

Expand All @@ -43,13 +42,12 @@ void testRandom() {
RandomServiceGrpc.RandomServiceBlockingStub service = RandomServiceGrpc.newBlockingStub(grpcClient().channel());
int seed = (int) System.currentTimeMillis();
Random.IntValue res = service.random(Random.Seed.newBuilder().setN(seed).build());
;
assertThat(res.getN(), is(lessThan(1000)));
MatcherAssert.assertThat(res.getN(), is(lessThan(1000)));
}

/**
* A service that implements the {@link io.grpc.BindableService} interface. Should be
* discovered by {@link GrpcMpCdiExtension}.
* discovered by {@link io.helidon.microprofile.grpc.server.GrpcMpCdiExtension}.
*/
@ApplicationScoped
public static class RandomService implements io.grpc.BindableService, RandomServiceGrpc.AsyncService {
Expand All @@ -64,7 +62,7 @@ public void random(Random.Seed request, StreamObserver<Random.IntValue> observer
int seed = request.getN();
java.util.Random random = new java.util.Random();
random.setSeed(seed);
complete(observer, Random.IntValue.newBuilder().setN(random.nextInt(1000)).build());
ResponseHelper.complete(observer, Random.IntValue.newBuilder().setN(random.nextInt(1000)).build());
}
}
}
Loading

0 comments on commit efb4400

Please sign in to comment.