use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class NettyClientTransportTest method channelExceptionDuringNegotiatonPropagatesToStatus.
@Test
public void channelExceptionDuringNegotiatonPropagatesToStatus() throws Exception {
negotiator = ProtocolNegotiators.serverPlaintext();
startServer();
NoopProtocolNegotiator negotiator = new NoopProtocolNegotiator();
NettyClientTransport transport = newTransport(negotiator);
callMeMaybe(transport.start(clientTransportListener));
final Status failureStatus = Status.UNAVAILABLE.withDescription("oh noes!");
transport.channel().pipeline().fireExceptionCaught(failureStatus.asRuntimeException());
Rpc rpc = new Rpc(transport).halfClose();
try {
rpc.waitForClose();
fail("expected exception");
} catch (ExecutionException ex) {
assertSame(failureStatus, ((StatusException) ex.getCause()).getStatus());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class NettyClientTransportTest method maxHeaderListSizeShouldBeEnforcedOnClient.
@Test
public void maxHeaderListSizeShouldBeEnforcedOnClient() throws Exception {
startServer();
NettyClientTransport transport = newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, 1, null, true);
callMeMaybe(transport.start(clientTransportListener));
try {
// Send a single RPC and wait for the response.
new Rpc(transport, new Metadata()).halfClose().waitForResponse();
fail("The stream should have been failed due to client received header exceeds header list" + " size limit!");
} catch (Exception e) {
Throwable rootCause = getRootCause(e);
Status status = ((StatusException) rootCause).getStatus();
assertEquals(Status.Code.INTERNAL, status.getCode());
assertEquals("RST_STREAM closed stream. HTTP/2 error code: PROTOCOL_ERROR", status.getDescription());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class NettyClientTransportTest method handlerExceptionDuringNegotiatonPropagatesToStatus.
@Test
public void handlerExceptionDuringNegotiatonPropagatesToStatus() throws Exception {
negotiator = ProtocolNegotiators.serverPlaintext();
startServer();
final NoopProtocolNegotiator negotiator = new NoopProtocolNegotiator();
final NettyClientTransport transport = newTransport(negotiator);
callMeMaybe(transport.start(clientTransportListener));
final Status failureStatus = Status.UNAVAILABLE.withDescription("oh noes!");
transport.channel().eventLoop().execute(new Runnable() {
@Override
public void run() {
try {
negotiator.handler.exceptionCaught(transport.channel().pipeline().context(negotiator.handler), failureStatus.asRuntimeException());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
Rpc rpc = new Rpc(transport).halfClose();
try {
rpc.waitForClose();
fail("expected exception");
} catch (ExecutionException ex) {
Status actual = ((StatusException) ex.getCause()).getStatus();
assertSame(failureStatus.getCode(), actual.getCode());
assertThat(actual.getDescription()).contains(failureStatus.getDescription());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class XdsServerBuilderTest method verifyServer.
private void verifyServer(Future<Throwable> future, XdsServerBuilder.XdsServingStatusListener mockXdsServingStatusListener, Status notServingStatus) throws InterruptedException, ExecutionException, TimeoutException {
if (future != null) {
Throwable exception = future.get(5, TimeUnit.SECONDS);
assertThat(exception).isNull();
}
List<? extends SocketAddress> list = xdsServer.getListenSockets();
assertThat(list).hasSize(1);
InetSocketAddress socketAddress = (InetSocketAddress) list.get(0);
assertThat(socketAddress.getAddress().isAnyLocalAddress()).isTrue();
assertThat(socketAddress.getPort()).isGreaterThan(-1);
if (mockXdsServingStatusListener != null) {
if (notServingStatus != null) {
ArgumentCaptor<Throwable> argCaptor = ArgumentCaptor.forClass(null);
verify(mockXdsServingStatusListener, times(1)).onNotServing(argCaptor.capture());
Throwable throwable = argCaptor.getValue();
assertThat(throwable).isInstanceOf(StatusException.class);
assertThat(((StatusException) throwable).getStatus()).isEqualTo(notServingStatus);
} else {
verify(mockXdsServingStatusListener, never()).onNotServing(any(Throwable.class));
verify(mockXdsServingStatusListener, times(1)).onServing();
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class XdsServerWrapperTest method verifyBootstrapFail.
private void verifyBootstrapFail(Bootstrapper.BootstrapInfo b) throws Exception {
XdsClient xdsClient = mock(XdsClient.class);
when(xdsClient.getBootstrapInfo()).thenReturn(b);
xdsServerWrapper = new XdsServerWrapper("0.0.0.0:1", mockBuilder, listener, selectorManager, new FakeXdsClientPoolFactory(xdsClient), filterRegistry);
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);
}
}
});
try {
start.get(5000, TimeUnit.MILLISECONDS);
fail("Start should throw exception");
} catch (ExecutionException ex) {
assertThat(ex.getCause()).isInstanceOf(IOException.class);
Throwable cause = ex.getCause().getCause();
assertThat(cause).isInstanceOf(StatusException.class);
assertThat(((StatusException) cause).getStatus().getCode()).isEqualTo(Status.UNAVAILABLE.getCode());
}
}
Aggregations