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);
}
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);
}
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)));
}
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)));
}
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());
}
Aggregations