Example usage for io.netty.channel.embedded EmbeddedChannel checkException

List of usage examples for io.netty.channel.embedded EmbeddedChannel checkException

Introduction

In this page you can find the example usage for io.netty.channel.embedded EmbeddedChannel checkException.

Prototype

public void checkException() 

Source Link

Document

Check if there was any Throwable received and if so rethrow it.

Usage

From source file:com.vela.iot.active.netty.http2.server.LastInboundHandler.java

License:Apache License

public void writeOutbound(Object... msgs) throws Exception {
    for (Object msg : msgs) {
        ctx.write(msg);//from  w  ww .java 2  s .  c  o m
    }
    ctx.flush();
    EmbeddedChannel ch = (EmbeddedChannel) ctx.channel();
    ch.runPendingTasks();
    ch.checkException();
    checkException();
}

From source file:nats.codec.ClientFrameRecodeTest.java

License:Open Source License

private <T extends NatsFrame> T recode(T frame) {
    final EmbeddedChannel channel = new EmbeddedChannel(new ClientFrameEncoder(), new ClientFrameDecoder());

    // Encode/*  ww  w. j  a  v  a  2  s.  c  o m*/
    channel.write(frame);
    channel.flush();
    channel.checkException();
    final ByteBuf data = (ByteBuf) channel.readOutbound();

    // Decode
    channel.writeInbound(data);
    channel.checkException();
    final T recodedFrame = (T) channel.readInbound();

    // Ensure we got a frame
    assertNotNull(recodedFrame);

    return recodedFrame;
}

From source file:nats.codec.ServerFrameRecodeTest.java

License:Open Source License

protected <T extends NatsFrame> T recode(T frame) {
    final EmbeddedChannel channel = new EmbeddedChannel(new ServerFrameEncoder(), new ServerFrameDecoder());

    // Encode/*from ww w. j  av  a  2 s  .c o m*/
    channel.write(frame);
    channel.flush();
    channel.checkException();
    final ByteBuf data = (ByteBuf) channel.readOutbound();

    // Decode
    channel.writeInbound(data);
    channel.checkException();
    final T recodedFrame = (T) channel.readInbound();

    // Ensure we got a frame
    assertNotNull(recodedFrame);

    return recodedFrame;
}

From source file:org.apache.flink.runtime.io.network.netty.ClientTransportErrorHandlingTest.java

License:Apache License

/**
 * Verifies that {@link NettyMessage.ErrorResponse} messages are correctly wrapped in
 * {@link RemoteTransportException} instances.
 *//*from w  w w.j ava2s  .com*/
@Test
public void testWrappingOfRemoteErrorMessage() throws Exception {
    EmbeddedChannel ch = createEmbeddedChannel();

    PartitionRequestClientHandler handler = getClientHandler(ch);

    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(),
            createRemoteInputChannel() };

    for (RemoteInputChannel r : rich) {
        when(r.getInputChannelId()).thenReturn(new InputChannelID());
        handler.addInputChannel(r);
    }

    // Error msg for channel[0]
    ch.pipeline().fireChannelRead(new NettyMessage.ErrorResponse(
            new RuntimeException("Expected test exception"), rich[0].getInputChannelId()));

    try {
        // Exception should not reach end of pipeline...
        ch.checkException();
    } catch (Exception e) {
        fail("The exception reached the end of the pipeline and "
                + "was not handled correctly by the last handler.");
    }

    verify(rich[0], times(1)).onError(isA(RemoteTransportException.class));
    verify(rich[1], never()).onError(any(Throwable.class));

    // Fatal error for all channels
    ch.pipeline()
            .fireChannelRead(new NettyMessage.ErrorResponse(new RuntimeException("Expected test exception")));

    try {
        // Exception should not reach end of pipeline...
        ch.checkException();
    } catch (Exception e) {
        fail("The exception reached the end of the pipeline and "
                + "was not handled correctly by the last handler.");
    }

    verify(rich[0], times(2)).onError(isA(RemoteTransportException.class));
    verify(rich[1], times(1)).onError(isA(RemoteTransportException.class));
}

From source file:org.apache.flink.runtime.io.network.netty.ClientTransportErrorHandlingTest.java

License:Apache License

/**
 * Verifies that fired Exceptions are handled correctly by the pipeline.
 */// w ww .ja v a2s  .c o  m
@Test
public void testExceptionCaught() throws Exception {
    EmbeddedChannel ch = createEmbeddedChannel();

    PartitionRequestClientHandler handler = getClientHandler(ch);

    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(),
            createRemoteInputChannel() };

    for (RemoteInputChannel r : rich) {
        when(r.getInputChannelId()).thenReturn(new InputChannelID());
        handler.addInputChannel(r);
    }

    ch.pipeline().fireExceptionCaught(new Exception());

    try {
        // Exception should not reach end of pipeline...
        ch.checkException();
    } catch (Exception e) {
        fail("The exception reached the end of the pipeline and "
                + "was not handled correctly by the last handler.");
    }

    // ...but all the registered channels should be notified.
    for (RemoteInputChannel r : rich) {
        verify(r).onError(isA(LocalTransportException.class));
    }
}