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