当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedChannel.checkException方法代码示例

本文整理汇总了Java中io.netty.channel.embedded.EmbeddedChannel.checkException方法的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedChannel.checkException方法的具体用法?Java EmbeddedChannel.checkException怎么用?Java EmbeddedChannel.checkException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.embedded.EmbeddedChannel的用法示例。


在下文中一共展示了EmbeddedChannel.checkException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void encode() {
    IsoOnTcpMessage isoOnTcpMessage = new IsoOnTcpMessage(
        Unpooled.wrappedBuffer(new byte[]{(byte)0x01,(byte)0x02,(byte)0x03}));
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeOutbound(isoOnTcpMessage);
    channel.checkException();
    Object obj = channel.readOutbound();
    assertThat(obj).isInstanceOf(ByteBuf.class);
    ByteBuf byteBuf = (ByteBuf) obj;
    assertEquals(4 + 3, byteBuf.readableBytes(),
        "The TCP on ISO Header should add 4 bytes to the data sent");
    assertEquals(IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER, byteBuf.getByte(0));
    assertEquals(4 + 3, byteBuf.getShort(2),
        "The length value in the packet should reflect the size of the entire data being sent");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:18,代码来源:IsoOnTcpProtocolTest.java

示例2: decode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * Happy path test.
 */
@Test
@Tag("fast")
public void decode() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D,
        (byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08,(byte)0x09}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertThat(obj).isInstanceOf(IsoOnTcpMessage.class);
    IsoOnTcpMessage isoOnTcpMessage = (IsoOnTcpMessage) obj;
    assertNotNull(isoOnTcpMessage.getUserData());
    assertEquals(9, isoOnTcpMessage.getUserData().readableBytes());
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:18,代码来源:IsoOnTcpProtocolTest.java

示例3: decodeWayTooShort

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the available amount of data is so small we can't even find out how big
 * the entire package should be, nothing should be read.
 */
@Test
@Tag("fast")
public void decodeWayTooShort() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertNull(obj, "Nothing should have been decoded");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:15,代码来源:IsoOnTcpProtocolTest.java

示例4: decodeTooShort

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the available amount of data is smaller than what the packet size says
 * it should be, nothing should be read.
 */
@Test
@Tag("fast")
public void decodeTooShort() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D,
        (byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertNull(obj, "Nothing should have been decoded");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:16,代码来源:IsoOnTcpProtocolTest.java

示例5: decodeLogPacketIfTraceLogging

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If logging is set to `DEBUG` then a hexdump of the entire captured packet
 * should be logged
 */
@Test
@Tag("fast")
public void decodeLogPacketIfTraceLogging() {
    // Setup the mock logger.
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    // Save the current default logging level
    Level defaultLevel = root.getLevel();
    try {
        // Change the logging to TRACE.
        root.setLevel(Level.TRACE);

        // Do some deserialization
        EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
        channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
            (byte) 0x00, (byte) 0x00, (byte) 0x0D,
            (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09}));
        channel.checkException();
        Object obj = channel.readInbound();
        assertNotNull(obj, "Something should have been decoded");

        // Check that the packet dump was logged.
        verify(mockAppender).doAppend(argThat(argument ->
            ((LoggingEvent) argument).getFormattedMessage().contains("Got Data: 0300000d010203040506070809")));
    } finally {
        // Reset the log level to the default.
        root.setLevel(defaultLevel);
    }
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:36,代码来源:IsoOnTcpProtocolTest.java

示例6: ensureInboundTrafficDiscarded

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
private void ensureInboundTrafficDiscarded(EmbeddedChannel ch) {
    // Generate a lot of random traffic to ensure that it's discarded silently.
    byte[] data = new byte[1048576];
    rnd.nextBytes(data);

    ByteBuf buf = Unpooled.wrappedBuffer(data);
    for (int i = 0; i < 4096; i ++) {
        buf.setIndex(0, data.length);
        ch.writeInbound(buf.retain());
        ch.checkException();
        assertNull(ch.readInbound());
    }
    buf.release();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:15,代码来源:HttpInvalidMessageTest.java

示例7: testChunkedMessageInput

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testChunkedMessageInput() {

    ChunkedInput<Object> input = new ChunkedInput<Object>() {
        private boolean done;

        @Override
        public boolean isEndOfInput() throws Exception {
            return done;
        }

        @Override
        public void close() throws Exception {
            // NOOP
        }

        @Override
        public Object readChunk(ChannelHandlerContext ctx) throws Exception {
            if (done) {
                return false;
            }
            done = true;
            return 0;
        }
    };

    EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler());
    ch.writeAndFlush(input).syncUninterruptibly();
    ch.checkException();
    assertTrue(ch.finish());

    assertEquals(0, ch.readOutbound());
    assertNull(ch.readOutbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:35,代码来源:ChunkedWriteHandlerTest.java

示例8: testListenerNotifiedWhenIsEnd

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testListenerNotifiedWhenIsEnd() {
    ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1);

    ChunkedInput<ByteBuf> input = new ChunkedInput<ByteBuf>() {
        private boolean done;
        private final ByteBuf buffer = releaseLater(Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1));

        @Override
        public boolean isEndOfInput() throws Exception {
            return done;
        }

        @Override
        public void close() throws Exception {
            // NOOP
        }

        @Override
        public ByteBuf readChunk(ChannelHandlerContext ctx) throws Exception {
            if (done) {
                return null;
            }
            done = true;
            return buffer.duplicate().retain();
        }
    };

    final AtomicBoolean listenerNotified = new AtomicBoolean(false);
    final ChannelFutureListener listener = new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            listenerNotified.set(true);
        }
    };

    EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler());
    ch.writeAndFlush(input).addListener(listener).syncUninterruptibly();
    ch.checkException();
    ch.finish();

    // the listener should have been notified
    assertTrue(listenerNotified.get());

    assertEquals(releaseLater(buffer), releaseLater(ch.readOutbound()));
    assertNull(ch.readOutbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:49,代码来源:ChunkedWriteHandlerTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.checkException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。