Search in sources :

Example 96 with Server

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);
}
Also used : Server(io.grpc.Server) ManagedChannel(io.grpc.ManagedChannel) Before(org.junit.Before)

Example 97 with Server

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;
    }
}
Also used : Server(io.grpc.Server) InternalServer(io.grpc.InternalServer) ProtoFileDescriptorSupplier(io.grpc.protobuf.ProtoFileDescriptorSupplier) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServerServiceDefinition(io.grpc.ServerServiceDefinition) HashSet(java.util.HashSet)

Example 98 with Server

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();
    }
}
Also used : Server(io.grpc.Server) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 99 with Server

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));
}
Also used : Server(io.grpc.Server) Test(org.junit.Test)

Example 100 with 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();
}
Also used : InOrder(org.mockito.InOrder) Server(io.grpc.Server) Statement(org.junit.runners.model.Statement) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)76 Server (io.grpc.Server)68 IOException (java.io.IOException)27 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)24 ArrayList (java.util.ArrayList)21 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)21 ExecutionException (java.util.concurrent.ExecutionException)20 TimeoutException (java.util.concurrent.TimeoutException)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)19 Server (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server)18 StatusException (io.grpc.StatusException)17 Metadata (io.grpc.Metadata)12 List (java.util.List)12 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)12 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)11 ExecutorService (java.util.concurrent.ExecutorService)11 ParallelInstruction (com.google.api.services.dataflow.model.ParallelInstruction)10 ServerCall (io.grpc.ServerCall)10 StreamObserver (io.grpc.stub.StreamObserver)10