Search in sources :

Example 1 with Echo

use of io.helidon.grpc.server.test.Echo in project helidon by oracle.

the class SslIT method shouldConnectWithClientCertsFor2Way.

@Test
public void shouldConnectWithClientCertsFor2Way() throws Exception {
    Resource tlsCaCert = Resource.create(CA_CERT);
    Resource tlsClientCert = Resource.create(CLIENT_CERT);
    Resource tlsClientKey = Resource.create(CLIENT_KEY);
    SslContext sslContext = clientSslContext(tlsCaCert, tlsClientCert, tlsClientKey);
    Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_2WaySSL.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
    // call the gRPC Echo service
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build());
    assertThat(response.getMessage(), is("foo"));
    ((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : Echo(io.helidon.grpc.server.test.Echo) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Resource(io.helidon.common.configurable.Resource) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 2 with Echo

use of io.helidon.grpc.server.test.Echo in project helidon by oracle.

the class SslIT method shouldConnectWithoutClientCertsFor1Way.

// ----- test methods ---------------------------------------------------
@Test
public void shouldConnectWithoutClientCertsFor1Way() throws Exception {
    Resource tlsCaCert = Resource.create(CA_CERT);
    // client do not have to provide certs for 1way ssl
    SslContext sslContext = clientSslContext(tlsCaCert, null, null);
    Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_1WaySSL.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
    // call the gRPC Echo service suggestion
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build());
    assertThat(response.getMessage(), is("foo"));
    ((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : Echo(io.helidon.grpc.server.test.Echo) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Resource(io.helidon.common.configurable.Resource) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 3 with Echo

use of io.helidon.grpc.server.test.Echo in project helidon by oracle.

the class ContextIT method shouldObtainValueFromContextForThread.

@Test
public void shouldObtainValueFromContextForThread() {
    Context context = grpcServer.context();
    TestValue value = new TestValue("Foo");
    context.register(value);
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("thread").build());
    assertThat(response.getMessage(), is("Foo"));
    assertThat(context.get(TestValue.class).orElse(null), is(sameInstance(value)));
}
Also used : Context(io.helidon.common.context.Context) Echo(io.helidon.grpc.server.test.Echo) Test(org.junit.jupiter.api.Test)

Example 4 with Echo

use of io.helidon.grpc.server.test.Echo in project helidon by oracle.

the class ContextIT method shouldObtainValueFromContextForRequest.

@Test
public void shouldObtainValueFromContextForRequest() {
    Context context = grpcServer.context();
    TestValue value = new TestValue("Bar");
    context.register(value);
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("request").build());
    assertThat(response.getMessage(), is("Bar"));
    assertThat(context.get(TestValue.class).orElse(null), is(sameInstance(value)));
}
Also used : Context(io.helidon.common.context.Context) Echo(io.helidon.grpc.server.test.Echo) Test(org.junit.jupiter.api.Test)

Example 5 with Echo

use of io.helidon.grpc.server.test.Echo in project helidon by oracle.

the class MetricsIT method startGrpcServer.

// ----- helper methods -------------------------------------------------
/**
 * Start the gRPC Server listening on an ephemeral port.
 *
 * @throws Exception in case of an error
 */
private static void startGrpcServer() throws Exception {
    // Add the EchoService and enable GrpcMetrics
    GrpcRouting routing = GrpcRouting.builder().intercept(GrpcMetrics.timed()).register(new EchoService(), rules -> rules.intercept(GrpcMetrics.metered()).intercept("Echo", GrpcMetrics.counted())).build();
    // Run the server on port 0 so that it picks a free ephemeral port
    GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
    grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
    LOGGER.info("Started gRPC server at: localhost:" + grpcServer.port());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) WebClient(io.helidon.webclient.WebClient) JsonValue(jakarta.json.JsonValue) Channel(io.grpc.Channel) MediaType(io.helidon.common.http.MediaType) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) JsonpSupport(io.helidon.media.jsonp.JsonpSupport) JsonStructure(jakarta.json.JsonStructure) BeforeAll(org.junit.jupiter.api.BeforeAll) MetricsSupport(io.helidon.metrics.MetricsSupport) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LogConfig(io.helidon.common.LogConfig) EchoServiceGrpc(io.helidon.grpc.server.test.EchoServiceGrpc) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Echo(io.helidon.grpc.server.test.Echo) Logger(java.util.logging.Logger) GrpcRouting(io.helidon.grpc.server.GrpcRouting) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) WebServer(io.helidon.webserver.WebServer) GrpcServer(io.helidon.grpc.server.GrpcServer) Routing(io.helidon.webserver.Routing) EchoService(services.EchoService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) EchoService(services.EchoService) GrpcRouting(io.helidon.grpc.server.GrpcRouting)

Aggregations

Echo (io.helidon.grpc.server.test.Echo)7 Test (org.junit.jupiter.api.Test)6 Channel (io.grpc.Channel)4 ManagedChannel (io.grpc.ManagedChannel)3 Resource (io.helidon.common.configurable.Resource)3 SslContext (io.netty.handler.ssl.SslContext)3 Context (io.helidon.common.context.Context)2 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)1 LogConfig (io.helidon.common.LogConfig)1 MediaType (io.helidon.common.http.MediaType)1 GrpcRouting (io.helidon.grpc.server.GrpcRouting)1 GrpcServer (io.helidon.grpc.server.GrpcServer)1 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)1 EchoServiceGrpc (io.helidon.grpc.server.test.EchoServiceGrpc)1 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)1 MetricsSupport (io.helidon.metrics.MetricsSupport)1 SecurityContext (io.helidon.security.SecurityContext)1 WebClient (io.helidon.webclient.WebClient)1 Routing (io.helidon.webserver.Routing)1 WebServer (io.helidon.webserver.WebServer)1