Search in sources :

Example 16 with ServiceDescriptor

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

the class MetricsConfigurerTest method shouldIgnoreTimerMetricFromInterfaceAnnotation.

@Test
public void shouldIgnoreTimerMetricFromInterfaceAnnotation() {
    Class<?> serviceClass = ServiceTwoImpl.class;
    Class<?> annotatedClass = ServiceTwo.class;
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(new ServiceTwoImpl());
    MetricsConfigurer configurer = new MetricsConfigurer();
    configurer.accept(serviceClass, annotatedClass, builder);
    ServiceDescriptor descriptor = builder.build();
    List<ServerInterceptor> serviceInterceptors = descriptor.interceptors().stream().collect(Collectors.toList());
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("timed");
    List<ServerInterceptor> methodInterceptors = methodDescriptor.interceptors().stream().collect(Collectors.toList());
    assertThat(serviceInterceptors, is(emptyIterable()));
    assertThat(methodInterceptors, is(emptyIterable()));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Example 17 with ServiceDescriptor

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

the class MetricsConfigurerTest method shouldAddTimerMetricFromClassAnnotation.

@Test
public void shouldAddTimerMetricFromClassAnnotation() {
    Class<?> serviceClass = ServiceOne.class;
    Class<?> annotatedClass = ServiceOne.class;
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(new ServiceOne());
    MetricsConfigurer configurer = new MetricsConfigurer();
    configurer.accept(serviceClass, annotatedClass, builder);
    ServiceDescriptor descriptor = builder.build();
    List<ServerInterceptor> serviceInterceptors = descriptor.interceptors().stream().collect(Collectors.toList());
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("timed");
    List<ServerInterceptor> methodInterceptors = methodDescriptor.interceptors().stream().collect(Collectors.toList());
    assertThat(serviceInterceptors, is(emptyIterable()));
    assertThat(methodInterceptors.size(), is(1));
    assertThat(methodInterceptors.get(0), is(instanceOf(GrpcMetrics.class)));
    assertThat(((GrpcMetrics) methodInterceptors.get(0)).metricType(), is(MetricType.TIMER));
    assertThat(updReg().getTimers().get(new MetricID(ServiceOne.class.getName() + ".timed")), is(notNullValue()));
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Example 18 with ServiceDescriptor

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

the class GrpcServerCdiExtensionTest method shouldStartServerAndLoadServicesAndExtensions.

@Test
public void shouldStartServerAndLoadServicesAndExtensions() {
    Instance<GrpcServerCdiExtension.ServerProducer> instance = beanManager.createInstance().select(GrpcServerCdiExtension.ServerProducer.class);
    // verify that the GrpcServerCdiExtension.ServerProducer producer bean is registered
    assertThat(instance.isResolvable(), is(true));
    // obtain the started server from the producer
    GrpcServer grpcServer = instance.get().server();
    assertThat(grpcServer, is(CoreMatchers.notNullValue()));
    assertThat(grpcServer.isRunning(), is(true));
    // verify that the services are deployed
    Map<String, ServiceDescriptor> services = grpcServer.services();
    // UnaryService should have been discovered by CDI
    assertThat(services.get("UnaryService"), is(CoreMatchers.notNullValue()));
    // ServerStreamingService loaded by ExtensionOne discovered by CDI
    assertThat(services.get("ServerStreamingService"), is(CoreMatchers.notNullValue()));
    // TestService loaded by ExtensionTwo loaded by the ServiceLoader
    assertThat(services.get("TestService"), is(CoreMatchers.notNullValue()));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) GrpcServer(io.helidon.grpc.server.GrpcServer) Test(org.junit.jupiter.api.Test)

Example 19 with ServiceDescriptor

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

the class InterceptorsTest method shouldUseSpecificServiceInterceptorBean.

@Test
public void shouldUseSpecificServiceInterceptorBean() {
    BeanManager beanManager = weld.getBeanManager();
    GrpcServiceBuilder builder = GrpcServiceBuilder.create(InterceptedServiceFive.class, beanManager);
    ServiceDescriptor descriptor = builder.build();
    PriorityBag<ServerInterceptor> interceptors = descriptor.interceptors();
    boolean hasInterceptorOne = interceptors.stream().anyMatch(interceptor -> ServerInterceptorOne.class.isAssignableFrom(interceptor.getClass()));
    boolean hasInterceptorTwo = interceptors.stream().anyMatch(interceptor -> ServerInterceptorTwo.class.isAssignableFrom(interceptor.getClass()));
    assertThat(hasInterceptorOne, is(true));
    assertThat(hasInterceptorTwo, is(true));
    assertThat(sizeOf(descriptor.method("foo").interceptors()), is(0));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Test(org.junit.jupiter.api.Test)

Example 20 with ServiceDescriptor

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

the class InterceptorsTest method shouldDiscoverServiceAndMethodInterceptor.

@Test
public void shouldDiscoverServiceAndMethodInterceptor() {
    BeanManager beanManager = weld.getBeanManager();
    GrpcServiceBuilder builder = GrpcServiceBuilder.create(InterceptedServiceThree.class, beanManager);
    ServiceDescriptor descriptor = builder.build();
    boolean hasServiceInterceptor = descriptor.interceptors().stream().anyMatch(interceptor -> ServerInterceptorOne.class.isAssignableFrom(interceptor.getClass()));
    assertThat(hasServiceInterceptor, is(true));
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("foo");
    boolean hasMethodInterceptor = methodDescriptor.interceptors().stream().anyMatch(interceptor -> ServerInterceptorTwo.class.isAssignableFrom(interceptor.getClass()));
    assertThat(hasMethodInterceptor, is(true));
    assertThat(sizeOf(descriptor.method("bar").interceptors()), is(0));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) BeanManager(jakarta.enterprise.inject.spi.BeanManager) 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