本文整理匯總了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");
}
示例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());
}
示例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");
}
示例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");
}
示例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);
}
}
示例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();
}
示例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());
}
示例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());
}