use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class LastInboundHandler method writeOutbound.
public void writeOutbound(Object... msgs) throws Exception {
for (Object msg : msgs) {
ctx.write(msg);
}
ctx.flush();
EmbeddedChannel ch = (EmbeddedChannel) ctx.channel();
ch.runPendingTasks();
ch.checkException();
checkException();
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class BinaryMemcacheDecoderTest method shouldRetainCurrentMessageWhenSendingItOut.
@Test
public void shouldRetainCurrentMessageWhenSendingItOut() {
channel = new EmbeddedChannel(new BinaryMemcacheRequestEncoder(), new BinaryMemcacheRequestDecoder());
ByteBuf key = Unpooled.copiedBuffer("Netty", CharsetUtil.UTF_8);
ByteBuf extras = Unpooled.copiedBuffer("extras", CharsetUtil.UTF_8);
BinaryMemcacheRequest request = new DefaultBinaryMemcacheRequest(key, extras);
assertTrue(channel.writeOutbound(request));
for (; ; ) {
ByteBuf buffer = channel.readOutbound();
if (buffer == null) {
break;
}
channel.writeInbound(buffer);
}
BinaryMemcacheRequest read = channel.readInbound();
read.release();
// tearDown will call "channel.finish()"
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SocksCmdResponseDecoderTest method testSocksCmdResponseDecoderWithDifferentParams.
private static void testSocksCmdResponseDecoderWithDifferentParams(SocksCmdStatus cmdStatus, SocksAddressType addressType, String host, int port) {
logger.debug("Testing cmdStatus: " + cmdStatus + " addressType: " + addressType);
SocksResponse msg = new SocksCmdResponse(cmdStatus, addressType, host, port);
SocksCmdResponseDecoder decoder = new SocksCmdResponseDecoder();
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
if (addressType == SocksAddressType.UNKNOWN) {
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
} else {
msg = embedder.readInbound();
assertEquals(((SocksCmdResponse) msg).cmdStatus(), cmdStatus);
if (host != null) {
assertEquals(((SocksCmdResponse) msg).host(), host);
}
assertEquals(((SocksCmdResponse) msg).port(), port);
}
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Socks4ClientDecoderTest method test.
private static void test(Socks4CommandStatus cmdStatus, String dstAddr, int dstPort) {
logger.debug("Testing cmdStatus: " + cmdStatus);
Socks4CommandResponse msg = new DefaultSocks4CommandResponse(cmdStatus, dstAddr, dstPort);
EmbeddedChannel embedder = new EmbeddedChannel(new Socks4ClientDecoder());
Socks4CommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
msg = embedder.readInbound();
assertEquals(msg.status(), cmdStatus);
if (dstAddr != null) {
assertEquals(msg.dstAddr(), dstAddr);
}
assertEquals(msg.dstPort(), dstPort);
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Socks4CommonTestUtils method writeMessageIntoEmbedder.
public static void writeMessageIntoEmbedder(EmbeddedChannel embedder, Socks4Message msg) {
EmbeddedChannel out;
if (msg instanceof Socks4CommandRequest) {
out = new EmbeddedChannel(Socks4ClientEncoder.INSTANCE);
} else {
out = new EmbeddedChannel(Socks4ServerEncoder.INSTANCE);
}
out.writeOutbound(msg);
embedder.writeInbound(out.readOutbound());
out.finish();
}
Aggregations