Search in sources :

Example 56 with EmbeddedChannel

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();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 57 with EmbeddedChannel

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()"
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 58 with EmbeddedChannel

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());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 59 with EmbeddedChannel

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());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 60 with EmbeddedChannel

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();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)446 Test (org.junit.Test)364 ByteBuf (io.netty.buffer.ByteBuf)162 HttpResponse (io.netty.handler.codec.http.HttpResponse)30 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)28 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)25 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)21 HttpRequest (io.netty.handler.codec.http.HttpRequest)20 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)17 InetSocketAddress (java.net.InetSocketAddress)17 BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)15 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)14 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)11 ArrayList (java.util.ArrayList)11 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)10 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)10 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)10 UUID (java.util.UUID)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 IOException (java.io.IOException)7