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