Search in sources :

Example 51 with EmbeddedChannel

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

the class SocksAuthRequestDecoderTest method testAuthRequestDecoder.

@Test
public void testAuthRequestDecoder() {
    SocksAuthRequest msg = new SocksAuthRequest(username, password);
    SocksAuthRequestDecoder decoder = new SocksAuthRequestDecoder();
    EmbeddedChannel embedder = new EmbeddedChannel(decoder);
    SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
    msg = embedder.readInbound();
    assertEquals(username, msg.username());
    assertEquals(password, msg.password());
    assertNull(embedder.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 52 with EmbeddedChannel

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

the class SocksAuthRequestDecoderTest method testAuthRequestDecoderPartialSend.

@Test
public void testAuthRequestDecoderPartialSend() {
    EmbeddedChannel ch = new EmbeddedChannel(new SocksAuthRequestDecoder());
    ByteBuf byteBuf = Unpooled.buffer(16);
    // Send username and password size
    byteBuf.writeByte(SocksSubnegotiationVersion.AUTH_PASSWORD.byteValue());
    byteBuf.writeByte(username.length());
    byteBuf.writeBytes(username.getBytes());
    byteBuf.writeByte(password.length());
    ch.writeInbound(byteBuf);
    // Check that channel is empty
    assertNull(ch.readInbound());
    // Send password
    ByteBuf byteBuf2 = Unpooled.buffer();
    byteBuf2.writeBytes(password.getBytes());
    ch.writeInbound(byteBuf2);
    // Read message from channel
    SocksAuthRequest msg = ch.readInbound();
    // Check message
    assertEquals(username, msg.username());
    assertEquals(password, msg.password());
    assertFalse(ch.finishAndReleaseAll());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 53 with EmbeddedChannel

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

the class SocksAuthResponseDecoderTest method testSocksAuthResponseDecoderWithDifferentParams.

private static void testSocksAuthResponseDecoderWithDifferentParams(SocksAuthStatus authStatus) {
    logger.debug("Testing SocksAuthResponseDecoder with authStatus: " + authStatus);
    SocksAuthResponse msg = new SocksAuthResponse(authStatus);
    SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
    EmbeddedChannel embedder = new EmbeddedChannel(decoder);
    SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
    msg = embedder.readInbound();
    assertSame(msg.authStatus(), authStatus);
    assertNull(embedder.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 54 with EmbeddedChannel

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

the class SocksCmdRequestDecoderTest method testSocksCmdRequestDecoderWithDifferentParams.

private static void testSocksCmdRequestDecoderWithDifferentParams(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
    logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host + " port: " + port);
    SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
    SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
    EmbeddedChannel embedder = new EmbeddedChannel(decoder);
    SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
    if (msg.addressType() == SocksAddressType.UNKNOWN) {
        assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
    } else {
        msg = embedder.readInbound();
        assertSame(msg.cmdType(), cmdType);
        assertSame(msg.addressType(), addressType);
        assertEquals(msg.host(), host);
        assertEquals(msg.port(), port);
    }
    assertNull(embedder.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 55 with EmbeddedChannel

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

the class BinaryMemcacheDecoderTest method shouldDecodeSeparatedValues.

@Test
public void shouldDecodeSeparatedValues() {
    String msgBody = "Not found";
    channel = new EmbeddedChannel(new BinaryMemcacheResponseDecoder());
    channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_1));
    channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_2));
    // First message
    BinaryMemcacheResponse response = channel.readInbound();
    assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
    assertThat(response.totalBodyLength(), is(msgBody.length()));
    response.release();
    // First message first content chunk
    MemcacheContent content = channel.readInbound();
    assertThat(content, instanceOf(LastMemcacheContent.class));
    assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
    content.release();
    // Second message
    response = channel.readInbound();
    assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
    assertThat(response.totalBodyLength(), is(msgBody.length()));
    response.release();
    // Second message first content chunk
    content = channel.readInbound();
    assertThat(content, instanceOf(MemcacheContent.class));
    assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(0, 7)));
    content.release();
    // Second message second content chunk
    content = channel.readInbound();
    assertThat(content, instanceOf(LastMemcacheContent.class));
    assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(7, 9)));
    content.release();
    // Third message
    response = channel.readInbound();
    assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
    assertThat(response.totalBodyLength(), is(msgBody.length()));
    response.release();
    // Third message first content chunk
    content = channel.readInbound();
    assertThat(content, instanceOf(LastMemcacheContent.class));
    assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
    content.release();
}
Also used : MemcacheContent(io.netty.handler.codec.memcache.MemcacheContent) LastMemcacheContent(io.netty.handler.codec.memcache.LastMemcacheContent) LastMemcacheContent(io.netty.handler.codec.memcache.LastMemcacheContent) 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