Search in sources :

Example 1 with TreeMapService

use of services.TreeMapService in project helidon by oracle.

the class ClientServiceDescriptorTest method shouldAddClientStreamingMethodWithConfigurer.

@Test
public void shouldAddClientStreamingMethodWithConfigurer() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class);
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(TreeMapService.class).clientStreaming("foo", cfg -> cfg.intercept(interceptor)).build();
    ClientMethodDescriptor method = descriptor.method("foo");
    assertThat(method, is(notNullValue()));
    assertThat(method.interceptors(), contains(interceptor));
    MethodDescriptor<Object, Object> methodDescriptor = method.descriptor();
    assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.CLIENT_STREAMING));
    assertThat(methodDescriptor.getFullMethodName(), is("TreeMapService/foo"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StringServiceGrpc(io.helidon.grpc.client.test.StringServiceGrpc) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Collection(java.util.Collection) ClientInterceptor(io.grpc.ClientInterceptor) ServerMethodDefinition(io.grpc.ServerMethodDefinition) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ServiceDescriptor(io.grpc.ServiceDescriptor) IsEmptyIterable.emptyIterable(org.hamcrest.collection.IsEmptyIterable.emptyIterable) MethodDescriptor(io.grpc.MethodDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TreeMapService(services.TreeMapService) Mockito.mock(org.mockito.Mockito.mock) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.jupiter.api.Test)

Example 2 with TreeMapService

use of services.TreeMapService in project helidon by oracle.

the class ClientServiceDescriptorTest method shouldAddBidirectionalMethodWithConfigurer.

@Test
public void shouldAddBidirectionalMethodWithConfigurer() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class);
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(TreeMapService.class).bidirectional("foo", cfg -> cfg.intercept(interceptor)).build();
    ClientMethodDescriptor method = descriptor.method("foo");
    assertThat(method, is(notNullValue()));
    assertThat(method.interceptors(), contains(interceptor));
    MethodDescriptor<Object, Object> methodDescriptor = method.descriptor();
    assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.BIDI_STREAMING));
    assertThat(methodDescriptor.getFullMethodName(), is("TreeMapService/foo"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StringServiceGrpc(io.helidon.grpc.client.test.StringServiceGrpc) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Collection(java.util.Collection) ClientInterceptor(io.grpc.ClientInterceptor) ServerMethodDefinition(io.grpc.ServerMethodDefinition) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ServiceDescriptor(io.grpc.ServiceDescriptor) IsEmptyIterable.emptyIterable(org.hamcrest.collection.IsEmptyIterable.emptyIterable) MethodDescriptor(io.grpc.MethodDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TreeMapService(services.TreeMapService) Mockito.mock(org.mockito.Mockito.mock) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.jupiter.api.Test)

Example 3 with TreeMapService

use of services.TreeMapService in project helidon by oracle.

the class ClientServiceDescriptorTest method shouldAddUnaryMethodWithConfigurer.

@Test
public void shouldAddUnaryMethodWithConfigurer() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class);
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(TreeMapService.class).unary("foo", cfg -> cfg.intercept(interceptor)).build();
    ClientMethodDescriptor method = descriptor.method("foo");
    assertThat(method, is(notNullValue()));
    assertThat(method.interceptors(), contains(interceptor));
    MethodDescriptor<Object, Object> methodDescriptor = method.descriptor();
    assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.UNARY));
    assertThat(methodDescriptor.getFullMethodName(), is("TreeMapService/foo"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StringServiceGrpc(io.helidon.grpc.client.test.StringServiceGrpc) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Collection(java.util.Collection) ClientInterceptor(io.grpc.ClientInterceptor) ServerMethodDefinition(io.grpc.ServerMethodDefinition) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ServiceDescriptor(io.grpc.ServiceDescriptor) IsEmptyIterable.emptyIterable(org.hamcrest.collection.IsEmptyIterable.emptyIterable) MethodDescriptor(io.grpc.MethodDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TreeMapService(services.TreeMapService) Mockito.mock(org.mockito.Mockito.mock) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.jupiter.api.Test)

Example 4 with TreeMapService

use of services.TreeMapService in project helidon by oracle.

the class ClientServiceDescriptorTest method shouldAddServerStreamingMethodWithConfigurer.

@Test
public void shouldAddServerStreamingMethodWithConfigurer() {
    ClientInterceptor interceptor = mock(ClientInterceptor.class);
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(TreeMapService.class).serverStreaming("foo", cfg -> cfg.intercept(interceptor)).build();
    ClientMethodDescriptor method = descriptor.method("foo");
    assertThat(method, is(notNullValue()));
    assertThat(method.interceptors(), contains(interceptor));
    MethodDescriptor<Object, Object> methodDescriptor = method.descriptor();
    assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.SERVER_STREAMING));
    assertThat(methodDescriptor.getFullMethodName(), is("TreeMapService/foo"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StringServiceGrpc(io.helidon.grpc.client.test.StringServiceGrpc) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Collection(java.util.Collection) ClientInterceptor(io.grpc.ClientInterceptor) ServerMethodDefinition(io.grpc.ServerMethodDefinition) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ServiceDescriptor(io.grpc.ServiceDescriptor) IsEmptyIterable.emptyIterable(org.hamcrest.collection.IsEmptyIterable.emptyIterable) MethodDescriptor(io.grpc.MethodDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TreeMapService(services.TreeMapService) Mockito.mock(org.mockito.Mockito.mock) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.jupiter.api.Test)

Example 5 with TreeMapService

use of services.TreeMapService in project helidon by oracle.

the class GrpcChannelsProviderIT method startGrpcServer.

/**
 * Start a gRPC server listening on the specified port and with ssl enabled (if sslEnabled is true).
 *
 * @param nPort      The server port where the server will listen.
 * @param sslEnabled true if ssl enabled.
 * @param mutual     if true then 2 way (mutual) or just one way ssl.
 * @return A reference to a {@link io.helidon.grpc.server.GrpcServer}.
 */
private static GrpcServer startGrpcServer(int nPort, boolean sslEnabled, boolean mutual) throws Exception {
    Resource tlsCert = Resource.create(SERVER_CERT);
    Resource tlsKey = Resource.create(SERVER_KEY);
    Resource tlsCaCert = Resource.create(CA_CERT);
    GrpcTlsDescriptor sslConfig = null;
    String name = "grpc.server";
    if (!sslEnabled) {
        name = name + 1;
    } else if (mutual) {
        name = name + 2;
        sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).tlsCaCert(tlsCaCert).build();
    } else {
        name = name + 3;
        sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).build();
    }
    // Add the EchoService
    GrpcRouting routing = GrpcRouting.builder().register(new TreeMapService()).build();
    GrpcServerConfiguration.Builder bldr = GrpcServerConfiguration.builder().name(name).port(nPort);
    if (sslEnabled) {
        bldr.tlsConfig(sslConfig);
    }
    return GrpcServer.create(bldr.build(), routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) TreeMapService(services.TreeMapService) Resource(io.helidon.common.configurable.Resource) GrpcTlsDescriptor(io.helidon.grpc.core.GrpcTlsDescriptor) GrpcRouting(io.helidon.grpc.server.GrpcRouting)

Aggregations

TreeMapService (services.TreeMapService)7 ClientInterceptor (io.grpc.ClientInterceptor)4 MethodDescriptor (io.grpc.MethodDescriptor)4 ServerMethodDefinition (io.grpc.ServerMethodDefinition)4 ServiceDescriptor (io.grpc.ServiceDescriptor)4 StringServiceGrpc (io.helidon.grpc.client.test.StringServiceGrpc)4 Collection (java.util.Collection)4 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)4 CoreMatchers.is (org.hamcrest.CoreMatchers.is)4 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 IsEmptyIterable.emptyIterable (org.hamcrest.collection.IsEmptyIterable.emptyIterable)4 IsIterableContainingInOrder.contains (org.hamcrest.collection.IsIterableContainingInOrder.contains)4 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)4 Test (org.junit.jupiter.api.Test)4 Mockito.mock (org.mockito.Mockito.mock)4 GrpcRouting (io.helidon.grpc.server.GrpcRouting)3 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)3 BeforeAll (org.junit.jupiter.api.BeforeAll)2