Search in sources :

Example 21 with ServiceDescriptor

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));
}
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 22 with ServiceDescriptor

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));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Test(org.junit.jupiter.api.Test)

Example 23 with ServiceDescriptor

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;
    });
}
Also used : StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Security(io.helidon.security.Security) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Config(io.helidon.config.Config) GrpcServer(io.helidon.grpc.server.GrpcServer) GreetService(io.helidon.grpc.examples.common.GreetService) LogConfig(io.helidon.common.LogConfig) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcSecurity(io.helidon.security.integration.grpc.GrpcSecurity) HttpBasicAuthProvider(io.helidon.security.providers.httpauth.HttpBasicAuthProvider) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) GreetService(io.helidon.grpc.examples.common.GreetService) StringService(io.helidon.grpc.examples.common.StringService) GrpcServer(io.helidon.grpc.server.GrpcServer) Security(io.helidon.security.Security) GrpcSecurity(io.helidon.security.integration.grpc.GrpcSecurity) GrpcRouting(io.helidon.grpc.server.GrpcRouting)

Example 24 with ServiceDescriptor

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'"));
}
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 25 with ServiceDescriptor

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));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Meter(org.eclipse.microprofile.metrics.Meter) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) 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