Search in sources :

Example 41 with ServiceDescriptor

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

the class MetricsConfigurerTest method shouldIgnoreSimpleTimerMetricFromInterfaceAnnotation.

@Test
public void shouldIgnoreSimpleTimerMetricFromInterfaceAnnotation() {
    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("simplyTimed");
    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 42 with ServiceDescriptor

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

the class MetricsConfigurerTest method shouldAddCounterMetricFromClassAnnotation.

@Test
public void shouldAddCounterMetricFromClassAnnotation() {
    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("counted");
    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.COUNTER));
    assertThat(updReg().getCounters().get(new MetricID(ServiceOne.class.getName() + ".counted")), 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 43 with ServiceDescriptor

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

the class GrpcServiceBuilderTest method assertSingleton.

@SuppressWarnings("unchecked")
public void assertSingleton(GrpcServiceBuilder builder) {
    ServiceDescriptor descriptor = builder.build();
    MethodDescriptor methodDescriptor = descriptor.method("unary");
    ServerCallHandler handler = methodDescriptor.callHandler();
    ServerCall<String, ServiceFive> callOne = mock(ServerCall.class);
    ServerCall<String, ServiceFive> callTwo = mock(ServerCall.class);
    when(callOne.getMethodDescriptor()).thenReturn(methodDescriptor.descriptor());
    when(callTwo.getMethodDescriptor()).thenReturn(methodDescriptor.descriptor());
    ServerCall.Listener listenerOne = handler.startCall(callOne, new Metadata());
    ServerCall.Listener listenerTwo = handler.startCall(callTwo, new Metadata());
    listenerOne.onMessage("foo");
    listenerOne.onHalfClose();
    listenerTwo.onMessage("foo");
    listenerTwo.onHalfClose();
    ArgumentCaptor<ServiceFive> captorOne = ArgumentCaptor.forClass(ServiceFive.class);
    ArgumentCaptor<ServiceFive> captorTwo = ArgumentCaptor.forClass(ServiceFive.class);
    verify(callOne).sendMessage(captorOne.capture());
    verify(callTwo).sendMessage(captorTwo.capture());
    assertThat(captorOne.getValue(), is(sameInstance(captorTwo.getValue())));
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerCall(io.grpc.ServerCall) Metadata(io.grpc.Metadata) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor)

Example 44 with ServiceDescriptor

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

the class GrpcServiceBuilderTest method shouldCreateDescriptorFoServiceWithNestedGenericParameters.

@Test
public void shouldCreateDescriptorFoServiceWithNestedGenericParameters() {
    GrpcServiceBuilder modeller = GrpcServiceBuilder.create(ServiceSix.class, beanManager);
    ServiceDescriptor descriptor = modeller.build();
    assertThat(descriptor.name(), is(ServiceSix.class.getSimpleName()));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Test(org.junit.jupiter.api.Test)

Example 45 with ServiceDescriptor

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

the class GrpcServiceBuilderTest method shouldUseDefaultServiceName.

@Test
public void shouldUseDefaultServiceName() {
    ServiceTwo service = new ServiceTwo();
    GrpcServiceBuilder modeller = GrpcServiceBuilder.create(service, beanManager);
    ServiceDescriptor descriptor = modeller.build();
    assertThat(descriptor.name(), is("ServiceTwo"));
}
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