Search in sources :

Example 36 with StatusException

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());
    }
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException) ExecutionException(java.util.concurrent.ExecutionException) TrackingObjectPoolForTest(io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest) Test(org.junit.Test)

Example 37 with StatusException

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());
    }
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) TimeoutException(java.util.concurrent.TimeoutException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLException(javax.net.ssl.SSLException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TrackingObjectPoolForTest(io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest) Test(org.junit.Test)

Example 38 with StatusException

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());
    }
}
Also used : Status(io.grpc.Status) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLException(javax.net.ssl.SSLException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TrackingObjectPoolForTest(io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest) Test(org.junit.Test)

Example 39 with StatusException

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();
        }
    }
}
Also used : StatusException(io.grpc.StatusException) InetSocketAddress(java.net.InetSocketAddress)

Example 40 with StatusException

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());
    }
}
Also used : StatusException(io.grpc.StatusException) FakeXdsClient(io.grpc.xds.XdsServerTestHelper.FakeXdsClient) Server(io.grpc.Server) FakeXdsClientPoolFactory(io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory) 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)

Aggregations

StatusException (io.grpc.StatusException)45 Test (org.junit.Test)20 Status (io.grpc.Status)9 IOException (java.io.IOException)9 StatusException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)9 ExecutionException (java.util.concurrent.ExecutionException)8 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)6 Metadata (io.grpc.Metadata)6 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)5 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)4 TimeoutException (java.util.concurrent.TimeoutException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)2 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)2