Search in sources :

Example 61 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class Socks5CommandRequestDecoderTest method test.

private static void test(Socks5CommandType type, Socks5AddressType dstAddrType, String dstAddr, int dstPort) {
    logger.debug("Testing type: " + type + " dstAddrType: " + dstAddrType + " dstAddr: " + dstAddr + " dstPort: " + dstPort);
    Socks5CommandRequest msg = new DefaultSocks5CommandRequest(type, dstAddrType, dstAddr, dstPort);
    EmbeddedChannel embedder = new EmbeddedChannel(new Socks5CommandRequestDecoder());
    Socks5CommonTestUtils.writeFromClientToServer(embedder, msg);
    msg = embedder.readInbound();
    assertSame(msg.type(), type);
    assertSame(msg.dstAddrType(), dstAddrType);
    assertEquals(msg.dstAddr(), IDN.toASCII(dstAddr));
    assertEquals(msg.dstPort(), dstPort);
    assertNull(embedder.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 62 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class SmtpRequestEncoderTest method testEncodeDataAndContent.

@Test
public void testEncodeDataAndContent() {
    EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder());
    assertTrue(channel.writeOutbound(SmtpRequests.data()));
    assertTrue(channel.writeOutbound(new DefaultSmtpContent(Unpooled.copiedBuffer("Subject: Test\r\n\r\n", CharsetUtil.US_ASCII))));
    assertTrue(channel.writeOutbound(new DefaultLastSmtpContent(Unpooled.copiedBuffer("Test\r\n", CharsetUtil.US_ASCII))));
    assertTrue(channel.finish());
    ByteBuf written = Unpooled.buffer();
    for (; ; ) {
        ByteBuf buffer = channel.readOutbound();
        if (buffer == null) {
            break;
        }
        written.writeBytes(buffer);
        buffer.release();
    }
    assertEquals("DATA\r\nSubject: Test\r\n\r\nTest\r\n.\r\n", written.toString(CharsetUtil.US_ASCII));
    written.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 63 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class SmtpRequestEncoderTest method testEncode.

private static void testEncode(SmtpRequest request, String expected) {
    EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder());
    assertTrue(channel.writeOutbound(request));
    assertTrue(channel.finish());
    ByteBuf buffer = channel.readOutbound();
    assertEquals(expected, buffer.toString(CharsetUtil.US_ASCII));
    buffer.release();
    assertNull(channel.readOutbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf)

Example 64 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class SmtpResponseDecoderTest method testDecodeTwoLineResponseChunked.

@Test
public void testDecodeTwoLineResponseChunked() {
    EmbeddedChannel channel = newChannel();
    assertFalse(channel.writeInbound(newBuffer("200-")));
    assertFalse(channel.writeInbound(newBuffer("Hello\r\n2")));
    assertFalse(channel.writeInbound(newBuffer("00 Ok")));
    assertTrue(channel.writeInbound(newBuffer("\r\n")));
    assertTrue(channel.finish());
    SmtpResponse response = channel.readInbound();
    assertEquals(200, response.code());
    List<CharSequence> sequences = response.details();
    assertEquals(2, sequences.size());
    assertEquals("Hello", sequences.get(0).toString());
    assertEquals("Ok", sequences.get(1).toString());
    assertNull(channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 65 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class SmtpResponseDecoderTest method testDecodeTwoLineResponse.

@Test
public void testDecodeTwoLineResponse() {
    EmbeddedChannel channel = newChannel();
    assertTrue(channel.writeInbound(newBuffer("200-Hello\r\n200 Ok\r\n")));
    assertTrue(channel.finish());
    SmtpResponse response = channel.readInbound();
    assertEquals(200, response.code());
    List<CharSequence> sequences = response.details();
    assertEquals(2, sequences.size());
    assertEquals("Hello", sequences.get(0).toString());
    assertEquals("Ok", sequences.get(1).toString());
    assertNull(channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

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