Search in sources :

Example 41 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.

the class GrpcLoggingServiceTest method testServerCloseHangsUpClients.

@Test
public void testServerCloseHangsUpClients() throws Exception {
    LinkedBlockingQueue<LogEntry> logs = new LinkedBlockingQueue<>();
    ExecutorService executorService = Executors.newCachedThreadPool();
    Collection<Future<Void>> futures = new ArrayList<>();
    final GrpcLoggingService service = GrpcLoggingService.forWriter(new CollectionAppendingLogWriter(logs));
    try (GrpcFnServer<GrpcLoggingService> server = GrpcFnServer.allocatePortAndCreateFor(service, InProcessServerFactory.create())) {
        for (int i = 1; i <= 3; ++i) {
            final long instructionId = i;
            futures.add(executorService.submit(() -> {
                {
                    CountDownLatch waitForServerHangup = new CountDownLatch(1);
                    ManagedChannel channel = InProcessChannelBuilder.forName(server.getApiServiceDescriptor().getUrl()).build();
                    StreamObserver<LogEntry.List> outboundObserver = BeamFnLoggingGrpc.newStub(channel).logging(TestStreams.withOnNext(messageDiscarder).withOnCompleted(new CountDown(waitForServerHangup)).build());
                    outboundObserver.onNext(createLogsWithIds(instructionId));
                    waitForServerHangup.await();
                    return null;
                }
            }));
        }
        // Wait till each client has sent their message showing that they have connected.
        for (int i = 1; i <= 3; ++i) {
            logs.take();
        }
    }
    for (Future<Void> future : futures) {
        future.get();
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ManagedChannel(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel) ArrayList(java.util.ArrayList) LogEntry(org.apache.beam.model.fnexecution.v1.BeamFnApi.LogEntry) Test(org.junit.Test)

Example 42 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class GrpcCleanupRuleTest method registerNullServerThrowsNpe.

@Test
public void registerNullServerThrowsNpe() {
    Server server = null;
    GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("server");
    grpcCleanup.register(server);
}
Also used : Server(io.grpc.Server) Test(org.junit.Test)

Example 43 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class BinderServerBuilderTest method shouldExposeListeningBinderUponBuild.

@Test
public void shouldExposeListeningBinderUponBuild() {
    ServiceController<SomeService> controller = Robolectric.buildService(SomeService.class);
    SomeService service = controller.create().get();
    AndroidComponentAddress listenAddress = AndroidComponentAddress.forContext(service);
    Server server = BinderServerBuilder.forAddress(listenAddress, binderReceiver).build();
    try {
        assertThat(binderReceiver.get()).isNotNull();
    } finally {
        server.shutdownNow();
    }
}
Also used : Server(io.grpc.Server) Test(org.junit.Test)

Example 44 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class LoggingServerProviderTest method serverBuilder_interceptorCalled.

@SuppressWarnings("unchecked")
private void serverBuilder_interceptorCalled(Supplier<ServerBuilder<?>> serverBuilderSupplier) throws IOException {
    ServerInterceptor interceptor = mock(ServerInterceptor.class, delegatesTo(new NoopInterceptor()));
    InternalLoggingServerInterceptor.Factory factory = mock(InternalLoggingServerInterceptor.Factory.class);
    when(factory.create()).thenReturn(interceptor);
    LoggingServerProvider.init(factory);
    Server server = serverBuilderSupplier.get().addService(new SimpleServiceImpl()).build().start();
    int port = cleanupRule.register(server).getPort();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", port).usePlaintext().build();
    SimpleServiceGrpc.SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(cleanupRule.register(channel));
    assertThat(unaryRpc("buddy", stub)).isEqualTo("Hello buddy");
    verify(interceptor).interceptCall(any(ServerCall.class), any(Metadata.class), anyCallHandler());
    LoggingServerProvider.finish();
}
Also used : Server(io.grpc.Server) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) InternalLoggingServerInterceptor(io.grpc.observability.interceptors.InternalLoggingServerInterceptor) Metadata(io.grpc.Metadata) ManagedChannel(io.grpc.ManagedChannel) SimpleServiceGrpc(io.grpc.testing.protobuf.SimpleServiceGrpc) InternalLoggingServerInterceptor(io.grpc.observability.interceptors.InternalLoggingServerInterceptor)

Example 45 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grpc-java by grpc.

the class ErrorHandlingClient method run.

void run() throws Exception {
    // Port 0 means that the operating system will pick an available port to use.
    Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {

        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
            responseObserver.onError(Status.INTERNAL.withDescription("Eggplant Xerxes Crybaby Overbite Narwhal").asRuntimeException());
        }
    }).build().start();
    channel = ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();
    blockingCall();
    futureCallDirect();
    futureCallCallback();
    asyncCall();
    advancedAsyncCall();
    channel.shutdown();
    server.shutdown();
    channel.awaitTermination(1, TimeUnit.SECONDS);
    server.awaitTermination();
}
Also used : Server(io.grpc.Server) HelloRequest(io.grpc.examples.helloworld.HelloRequest) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloReply(io.grpc.examples.helloworld.HelloReply)

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