Search in sources :

Example 1 with BindableService

use of io.grpc.BindableService in project core-java by SpineEventEngine.

the class GrpcContainerShould method add_and_remove_parameters_from_builder.

@SuppressWarnings("MagicNumber")
@Test
public void add_and_remove_parameters_from_builder() {
    final GrpcContainer.Builder builder = GrpcContainer.newBuilder().setPort(8080).setPort(60);
    assertEquals(60, builder.getPort());
    int count = 3;
    final List<ServerServiceDefinition> definitions = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        final BindableService mockService = mock(BindableService.class);
        final ServerServiceDefinition mockDefinition = ServerServiceDefinition.builder(format("service-%s", i)).build();
        when(mockService.bindService()).thenReturn(mockDefinition);
        definitions.add(mockDefinition);
        builder.addService(mockService);
    }
    count--;
    // Perform removal and check that the return value is builder itself.
    assertEquals(builder, builder.removeService(definitions.get(count)));
    final Set<ServerServiceDefinition> serviceSet = builder.getServices();
    assertSize(count, serviceSet);
    final GrpcContainer container = builder.build();
    assertNotNull(container);
}
Also used : ServerServiceDefinition(io.grpc.ServerServiceDefinition) ArrayList(java.util.ArrayList) BindableService(io.grpc.BindableService) Test(org.junit.Test)

Example 2 with BindableService

use of io.grpc.BindableService in project grpc-java by grpc.

the class AdminInterface method getStandardServices.

/**
 * Returns a list of gRPC's built-in admin services.
 *
 * @return list of standard admin services
 */
public static List<ServerServiceDefinition> getStandardServices() {
    List<ServerServiceDefinition> services = new ArrayList<>();
    services.add(ChannelzService.newInstance(DEFAULT_CHANNELZ_MAX_PAGE_SIZE).bindService());
    BindableService csds = null;
    try {
        Class<?> clazz = Class.forName("io.grpc.xds.CsdsService");
        Method m = clazz.getMethod("newInstance");
        csds = (BindableService) m.invoke(null);
    } catch (ClassNotFoundException e) {
        logger.log(Level.FINE, "Unable to find CSDS service", e);
    } catch (NoSuchMethodException e) {
        logger.log(Level.FINE, "Unable to load CSDS service", e);
    } catch (IllegalAccessException e) {
        logger.log(Level.FINE, "Unable to load CSDS service", e);
    } catch (InvocationTargetException e) {
        logger.log(Level.FINE, "Unable to load CSDS service", e);
    }
    if (csds != null) {
        services.add(csds.bindService());
    }
    return Collections.unmodifiableList(services);
}
Also used : ServerServiceDefinition(io.grpc.ServerServiceDefinition) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) BindableService(io.grpc.BindableService)

Example 3 with BindableService

use of io.grpc.BindableService in project grpc-java by grpc.

the class XdsServerBuilderTest method xdsServer_2ndSetter_expectException.

@Test
public void xdsServer_2ndSetter_expectException() throws IOException {
    XdsServerBuilder.XdsServingStatusListener mockXdsServingStatusListener = mock(XdsServerBuilder.XdsServingStatusListener.class);
    buildBuilder(mockXdsServingStatusListener);
    BindableService mockBindableService = mock(BindableService.class);
    ServerServiceDefinition serverServiceDefinition = io.grpc.ServerServiceDefinition.builder("mock").build();
    when(mockBindableService.bindService()).thenReturn(serverServiceDefinition);
    builder.addService(mockBindableService);
    xdsServer = cleanupRule.register((XdsServerWrapper) builder.build());
    try {
        builder.addService(mock(BindableService.class));
        fail("exception expected");
    } catch (IllegalStateException expected) {
        assertThat(expected).hasMessageThat().contains("Server already built!");
    }
}
Also used : ServerServiceDefinition(io.grpc.ServerServiceDefinition) BindableService(io.grpc.BindableService) Test(org.junit.Test)

Example 4 with BindableService

use of io.grpc.BindableService in project grpc-java by grpc.

the class HealthStatusManagerTest method getHealthService_getterReturnsTheSameHealthRefAfterUpdate.

@Test
public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws Exception {
    BindableService health = manager.getHealthService();
    manager.setStatus(SERVICE1, ServingStatus.UNKNOWN);
    assertThat(health).isSameInstanceAs(manager.getHealthService());
}
Also used : BindableService(io.grpc.BindableService) Test(org.junit.Test)

Example 5 with BindableService

use of io.grpc.BindableService in project grpc-java by grpc.

the class MutableHandlerRegistryTest method simpleLookupWithBindable.

@Test
public void simpleLookupWithBindable() {
    BindableService bindableService = new BindableService() {

        @Override
        public ServerServiceDefinition bindService() {
            return basicServiceDefinition;
        }
    };
    assertNull(registry.addService(bindableService));
    ServerMethodDefinition<?, ?> method = registry.lookupMethod("basic/flow");
    assertSame(flowMethodDefinition, method);
}
Also used : BindableService(io.grpc.BindableService) Test(org.junit.Test)

Aggregations

BindableService (io.grpc.BindableService)7 ServerServiceDefinition (io.grpc.ServerServiceDefinition)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 BindAddress (com.navercorp.pinpoint.collector.receiver.BindAddress)1 AgentService (com.navercorp.pinpoint.collector.receiver.grpc.service.AgentService)1 MetadataService (com.navercorp.pinpoint.collector.receiver.grpc.service.MetadataService)1 PingEventHandler (com.navercorp.pinpoint.grpc.server.lifecycle.PingEventHandler)1 InternalWithLogId (io.grpc.InternalWithLogId)1 Server (io.grpc.Server)1 ServerInterceptor (io.grpc.ServerInterceptor)1 ServerTransportFilter (io.grpc.ServerTransportFilter)1 LogIdServerListenerDelegator (io.grpc.netty.LogIdServerListenerDelegator)1 PinpointNettyServerBuilder (io.grpc.netty.PinpointNettyServerBuilder)1 SslContext (io.netty.handler.ssl.SslContext)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1