Search in sources :

Example 6 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetricsInterceptorIT method shouldHaveCorrectNameWithDotsForSlashes.

@Test
public void shouldHaveCorrectNameWithDotsForSlashes() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).name("My/Service").unary("bar", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("bar");
    GrpcMetrics metrics = GrpcMetrics.counted();
    ServerCall<String, String> call = call(metrics, descriptor, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Counter appCounter = appRegistry.get().counter("My.Service.bar");
    assertVendorMetrics();
    assertThat(appCounter.getCount(), is(1L));
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 7 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetricsInterceptorIT method shouldApplyDescription.

@Test
public void shouldApplyDescription() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barDesc", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barDesc");
    GrpcMetrics metrics = GrpcMetrics.counted().description("foo");
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Counter appCounter = appRegistry.get().counter("Foo.barDesc");
    assertVendorMetrics();
    assertThat(appCounter.toString(), containsString("description='foo'"));
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcServiceBuilderTest method shouldCreateServiceWithMethodNamesFromAnnotation.

@Test
public void shouldCreateServiceWithMethodNamesFromAnnotation() {
    ServiceTwo service = new ServiceTwo();
    GrpcServiceBuilder builder = GrpcServiceBuilder.create(service, beanManager);
    ServiceDescriptor descriptor = builder.build();
    assertThat(descriptor.name(), is("ServiceTwo"));
    assertThat(descriptor.methods().size(), is(4));
    MethodDescriptor methodDescriptor;
    io.grpc.MethodDescriptor grpcDescriptor;
    methodDescriptor = descriptor.method("One");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("One"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/One"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.UNARY));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("Two");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("Two"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Two"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("Three");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("Three"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Three"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("Four");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("Four"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Four"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 9 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcServiceBuilderTest method assertServiceOne.

public void assertServiceOne(GrpcServiceBuilder builder) {
    ServiceDescriptor descriptor = builder.build();
    assertThat(descriptor.name(), is("ServiceOne/foo"));
    assertThat(descriptor.methods().size(), is(4));
    MethodDescriptor methodDescriptor;
    io.grpc.MethodDescriptor grpcDescriptor;
    methodDescriptor = descriptor.method("unary");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("unary"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/unary"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.UNARY));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("clientStreaming");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("clientStreaming"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/clientStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("serverStreaming");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("serverStreaming"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/serverStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    methodDescriptor = descriptor.method("bidiStreaming");
    assertThat(methodDescriptor, is(notNullValue()));
    assertThat(methodDescriptor.name(), is("bidiStreaming"));
    assertThat(methodDescriptor.callHandler(), is(notNullValue()));
    grpcDescriptor = methodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/bidiStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor)

Example 10 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcServiceBuilderTest method shouldUseServiceNameFromAnnotation.

@Test
public void shouldUseServiceNameFromAnnotation() {
    ServiceOne service = new ServiceOne();
    GrpcServiceBuilder modeller = GrpcServiceBuilder.create(service, beanManager);
    ServiceDescriptor descriptor = modeller.build();
    assertThat(descriptor.name(), is("ServiceOne/foo"));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)45 Test (org.junit.jupiter.api.Test)37 ServerInterceptor (io.grpc.ServerInterceptor)17 MethodDescriptor (io.helidon.grpc.server.MethodDescriptor)14 Metadata (io.grpc.Metadata)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 BeanManager (jakarta.enterprise.inject.spi.BeanManager)8 MetricID (org.eclipse.microprofile.metrics.MetricID)7 Counter (org.eclipse.microprofile.metrics.Counter)6 LogConfig (io.helidon.common.LogConfig)4 GrpcRouting (io.helidon.grpc.server.GrpcRouting)4 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)4 Security (io.helidon.security.Security)4 Config (io.helidon.config.Config)3 GrpcServer (io.helidon.grpc.server.GrpcServer)3 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 Channel (io.grpc.Channel)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2