Search in sources :

Example 91 with Server

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

the class XdsServerWrapperTest method shutdown_pendingRetry.

@Test
public void shutdown_pendingRetry() throws Exception {
    final SettableFuture<Server> start = SettableFuture.create();
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                start.set(xdsServerWrapper.start());
            } catch (Exception ex) {
                start.setException(ex);
            }
        }
    });
    xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    when(mockServer.start()).thenThrow(new IOException("error!"));
    FilterChain filterChain = createFilterChain("filter-chain-1", createRds("rds"));
    SslContextProviderSupplier sslSupplier = filterChain.sslContextProviderSupplier();
    xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
    xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
    xdsClient.deliverRdsUpdate("rds", Collections.singletonList(createVirtualHost("virtual-host-1")));
    try {
        start.get(5000, TimeUnit.MILLISECONDS);
        fail("Start should throw exception");
    } catch (ExecutionException ex) {
        assertThat(ex.getCause()).isInstanceOf(IOException.class);
    }
    assertThat(executor.getPendingTasks().size()).isEqualTo(1);
    verify(mockServer).start();
    verify(mockServer, never()).shutdown();
    xdsServerWrapper.shutdown();
    verify(mockServer).shutdown();
    when(mockServer.isTerminated()).thenReturn(true);
    assertThat(sslSupplier.isShutdown()).isTrue();
    assertThat(executor.getPendingTasks().size()).isEqualTo(0);
    verify(listener, never()).onNotServing(any(Throwable.class));
    verify(listener, never()).onServing();
    xdsServerWrapper.awaitTermination();
    assertThat(xdsServerWrapper.isTerminated()).isTrue();
}
Also used : Server(io.grpc.Server) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 92 with Server

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

the class AbstractServerImplBuilderTest method buildReturnsDelegateBuildByDefault.

@Test
public void buildReturnsDelegateBuildByDefault() {
    Server server = mock(Server.class);
    doReturn(server).when(mockDelegate).build();
    assertThat(testServerBuilder.build()).isSameInstanceAs(server);
}
Also used : Server(io.grpc.Server) Test(org.junit.Test)

Example 93 with Server

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

the class InProcessTransportTest method methodNotFound.

@Test
public void methodNotFound() throws Exception {
    server = null;
    ServerServiceDefinition definition = ServerServiceDefinition.builder("service_foo").addMethod(TestMethodDescriptors.voidMethod(), new ServerCallHandler<Void, Void>() {

        @Override
        public Listener<Void> startCall(ServerCall<Void, Void> call, Metadata headers) {
            return null;
        }
    }).build();
    Server failingServer = InProcessServerBuilder.forName("nocall-service").addService(definition).directExecutor().build().start();
    grpcCleanupRule.register(failingServer);
    ManagedChannel channel = InProcessChannelBuilder.forName("nocall-service").propagateCauseWithStatus(true).build();
    grpcCleanupRule.register(channel);
    MethodDescriptor<Void, Void> nonMatchMethod = MethodDescriptor.<Void, Void>newBuilder().setType(MethodDescriptor.MethodType.UNKNOWN).setFullMethodName("Waiter/serve").setRequestMarshaller(TestMethodDescriptors.voidMarshaller()).setResponseMarshaller(TestMethodDescriptors.voidMarshaller()).build();
    ClientCall<Void, Void> call = channel.newCall(nonMatchMethod, CallOptions.DEFAULT);
    try {
        ClientCalls.futureUnaryCall(call, null).get(5, TimeUnit.SECONDS);
        fail("Call should fail.");
    } catch (ExecutionException ex) {
        StatusRuntimeException s = (StatusRuntimeException) ex.getCause();
        assertEquals(s.getStatus().getCode(), Code.UNIMPLEMENTED);
    }
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) InternalServer(io.grpc.internal.InternalServer) Server(io.grpc.Server) ServerCall(io.grpc.ServerCall) ServerServiceDefinition(io.grpc.ServerServiceDefinition) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) ExecutionException(java.util.concurrent.ExecutionException) AbstractTransportTest(io.grpc.internal.AbstractTransportTest) Test(org.junit.Test)

Example 94 with Server

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

the class InProcessTransportTest method causeShouldBePropagatedWithStatus.

@Test
public void causeShouldBePropagatedWithStatus() throws Exception {
    server = null;
    String failingServerName = "server_foo";
    String serviceFoo = "service_foo";
    final Status s = Status.INTERNAL.withCause(new Throwable("failing server exception"));
    ServerServiceDefinition definition = ServerServiceDefinition.builder(serviceFoo).addMethod(TestMethodDescriptors.voidMethod(), new ServerCallHandler<Void, Void>() {

        @Override
        public ServerCall.Listener<Void> startCall(ServerCall<Void, Void> call, Metadata headers) {
            call.close(s, new Metadata());
            return new ServerCall.Listener<Void>() {
            };
        }
    }).build();
    Server failingServer = InProcessServerBuilder.forName(failingServerName).addService(definition).directExecutor().build().start();
    grpcCleanupRule.register(failingServer);
    ManagedChannel channel = InProcessChannelBuilder.forName(failingServerName).propagateCauseWithStatus(true).build();
    grpcCleanupRule.register(channel);
    try {
        ClientCalls.blockingUnaryCall(channel, TestMethodDescriptors.voidMethod(), CallOptions.DEFAULT, null);
        fail("exception should have been thrown");
    } catch (StatusRuntimeException e) {
        // When propagateCauseWithStatus is true, the cause should be sent forward
        assertEquals(s.getCause(), e.getCause());
    }
}
Also used : Status(io.grpc.Status) Listener(io.grpc.ServerCall.Listener) ServerCallHandler(io.grpc.ServerCallHandler) InternalServer(io.grpc.internal.InternalServer) Server(io.grpc.Server) ServerCall(io.grpc.ServerCall) ServerServiceDefinition(io.grpc.ServerServiceDefinition) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) AbstractTransportTest(io.grpc.internal.AbstractTransportTest) Test(org.junit.Test)

Example 95 with Server

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

the class HealthCheckingLoadBalancerFactoryTest method teardown.

@After
public void teardown() throws Exception {
    // All scheduled tasks have been accounted for
    assertThat(clock.getPendingTasks()).isEmpty();
    // faked.  Force closing for clean up.
    for (Server server : servers) {
        server.shutdownNow();
        assertThat(server.awaitTermination(1, TimeUnit.SECONDS)).isTrue();
    }
    for (ManagedChannel channel : channels) {
        channel.shutdownNow();
        assertThat(channel.awaitTermination(1, TimeUnit.SECONDS)).isTrue();
    }
    for (HealthImpl impl : healthImpls) {
        assertThat(impl.checkCalled).isFalse();
    }
}
Also used : Server(io.grpc.Server) ManagedChannel(io.grpc.ManagedChannel) After(org.junit.After)

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