use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.
the class InterceptorsTest method shouldUseSpecificNonCdiMethodInterceptor.
@Test
public void shouldUseSpecificNonCdiMethodInterceptor() {
BeanManager beanManager = weld.getBeanManager();
GrpcServiceBuilder builder = GrpcServiceBuilder.create(InterceptedServiceEight.class, beanManager);
ServiceDescriptor descriptor = builder.build();
assertThat(sizeOf(descriptor.interceptors()), is(0));
PriorityBag<ServerInterceptor> interceptors = descriptor.method("foo").interceptors();
boolean hasInterceptor = interceptors.stream().anyMatch(interceptor -> ServerInterceptorFive.class.isAssignableFrom(interceptor.getClass()));
assertThat(hasInterceptor, is(true));
}
use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.
the class InterceptorsTest method shouldDiscoverServiceInterceptor.
@Test
public void shouldDiscoverServiceInterceptor() {
BeanManager beanManager = weld.getBeanManager();
GrpcServiceBuilder builder = GrpcServiceBuilder.create(InterceptedServiceOne.class, beanManager);
ServiceDescriptor descriptor = builder.build();
boolean hasInterceptor = descriptor.interceptors().stream().anyMatch(interceptor -> ServerInterceptorOne.class.isAssignableFrom(interceptor.getClass()));
assertThat(hasInterceptor, is(true));
assertThat(sizeOf(descriptor.method("foo").interceptors()), is(0));
}
use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.
the class SecureServer method main.
/**
* Main entry point.
*
* @param args the program arguments
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
Config config = Config.create();
Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
ServiceDescriptor greetService1 = ServiceDescriptor.builder(new GreetService(config)).name("GreetService").intercept(GrpcSecurity.rolesAllowed("user")).intercept("SetGreeting", GrpcSecurity.rolesAllowed("admin")).build();
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(greetService1).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.create(config.get("grpc"));
GrpcServer grpcServer = GrpcServer.create(serverConfig, grpcRouting);
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.
the class GrpcMetricsInterceptorIT method shouldApplyUnits.
@Test
public void shouldApplyUnits() throws Exception {
ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barUnits", this::dummyUnary).build();
MethodDescriptor methodDescriptor = descriptor.method("barUnits");
GrpcMetrics metrics = GrpcMetrics.counted().units(MetricUnits.BITS);
ServerCall<String, String> call = call(metrics, methodDescriptor);
call.close(Status.OK, new Metadata());
Counter appCounter = appRegistry.get().counter("Foo.barUnits");
assertVendorMetrics();
assertThat(appCounter.toString(), containsString("unit='bits'"));
}
use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.
the class GrpcMetricsInterceptorIT method shouldUseMeteredMetric.
@Test
public void shouldUseMeteredMetric() throws Exception {
ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barMetered", this::dummyUnary).build();
MethodDescriptor methodDescriptor = descriptor.method("barMetered");
GrpcMetrics metrics = GrpcMetrics.metered();
ServerCall<String, String> call = call(metrics, methodDescriptor);
call.close(Status.OK, new Metadata());
Meter appMeter = appRegistry.get().meter("Foo.barMetered");
assertVendorMetrics();
assertThat(appMeter.getCount(), is(1L));
}
Aggregations