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