use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.
the class ProtoReflectionServiceTest method setUp.
@Before
public void setUp() throws Exception {
reflectionService = ProtoReflectionService.newInstance();
Server server = InProcessServerBuilder.forName("proto-reflection-test").directExecutor().addService(reflectionService).addService(new ReflectableServiceGrpc.ReflectableServiceImplBase() {
}).fallbackHandlerRegistry(handlerRegistry).build().start();
grpcCleanupRule.register(server);
ManagedChannel channel = grpcCleanupRule.register(InProcessChannelBuilder.forName("proto-reflection-test").directExecutor().build());
stub = ServerReflectionGrpc.newStub(channel);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.
the class ProtoReflectionService method getRefreshedIndex.
/**
* Retrieves the index for services of the server that dispatches the current call. Computes
* one if not exist. The index is updated if any changes to the server's mutable services are
* detected. A change is any addition or removal in the set of file descriptors attached to the
* mutable services or a change in the service names.
*/
private ServerReflectionIndex getRefreshedIndex() {
synchronized (lock) {
Server server = InternalServer.SERVER_CONTEXT_KEY.get();
ServerReflectionIndex index = serverReflectionIndexes.get(server);
if (index == null) {
index = new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices());
serverReflectionIndexes.put(server, index);
return index;
}
Set<FileDescriptor> serverFileDescriptors = new HashSet<>();
Set<String> serverServiceNames = new HashSet<>();
List<ServerServiceDefinition> serverMutableServices = server.getMutableServices();
for (ServerServiceDefinition mutableService : serverMutableServices) {
io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor();
if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) {
String serviceName = serviceDescriptor.getName();
FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()).getFileDescriptor();
serverFileDescriptors.add(fileDescriptor);
serverServiceNames.add(serviceName);
}
}
// Replace the index if the underlying mutable services have changed. Check both the file
// descriptors and the service names, because one file descriptor can define multiple
// services.
FileDescriptorIndex mutableServicesIndex = index.getMutableServicesIndex();
if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors) || !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) {
index = new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices);
serverReflectionIndexes.put(server, index);
}
return index;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.
the class BinderServerBuilderTest method shouldExposeSpecifiedListeningAddressUponBuild.
@Test
public void shouldExposeSpecifiedListeningAddressUponBuild() throws IOException {
AndroidComponentAddress listenAddress = AndroidComponentAddress.forBindIntent(new Intent().setAction("some-action").setComponent(new ComponentName("com.foo", "com.foo.SomeService")));
Server server = BinderServerBuilder.forAddress(listenAddress, binderReceiver).build().start();
try {
assertThat(server.getListenSockets()).containsExactly(listenAddress);
} finally {
server.shutdownNow();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.
the class GrpcCleanupRuleTest method registerServerReturnSameServer.
@Test
public void registerServerReturnSameServer() {
Server server = mock(Server.class);
assertSame(server, new GrpcCleanupRule().register(server));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.
the class GrpcCleanupRuleTest method singleServerCleanup.
@Test
public void singleServerCleanup() throws Throwable {
// setup
Server server = mock(Server.class);
Statement statement = mock(Statement.class);
InOrder inOrder = inOrder(statement, server);
GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
// run
grpcCleanup.register(server);
boolean awaitTerminationFailed = false;
try {
// will throw because channel.awaitTermination(long, TimeUnit) will return false;
grpcCleanup.apply(statement, null).evaluate();
} catch (AssertionError e) {
awaitTerminationFailed = true;
}
// verify
assertTrue(awaitTerminationFailed);
inOrder.verify(statement).evaluate();
inOrder.verify(server).shutdown();
inOrder.verify(server).awaitTermination(anyLong(), any(TimeUnit.class));
inOrder.verify(server).shutdownNow();
}
Aggregations