Search in sources :

Example 86 with EmbeddedChannel

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

the class JsonObjectDecoderTest method testSingleByteStream.

@Test
public void testSingleByteStream() {
    EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
    String json = "{\"foo\" : {\"bar\" : [{},{}]}}";
    for (byte c : json.getBytes(CharsetUtil.UTF_8)) {
        ch.writeInbound(Unpooled.copiedBuffer(new byte[] { c }));
    }
    ByteBuf res = ch.readInbound();
    assertEquals(json, res.toString(CharsetUtil.UTF_8));
    res.release();
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 87 with EmbeddedChannel

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

the class JsonObjectDecoderTest method testMaxObjectLength.

@Test(expected = TooLongFrameException.class)
public void testMaxObjectLength() {
    EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder(6));
    try {
        ch.writeInbound(Unpooled.copiedBuffer("[2,4,5]", CharsetUtil.UTF_8));
    } finally {
        assertFalse(ch.finish());
    }
    fail();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 88 with EmbeddedChannel

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

the class JsonObjectDecoderTest method testNonJsonContent1.

@Test(expected = CorruptedFrameException.class)
public void testNonJsonContent1() {
    EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
    try {
        ch.writeInbound(Unpooled.copiedBuffer("  b [1,2,3]", CharsetUtil.UTF_8));
    } finally {
        assertFalse(ch.finish());
    }
    fail();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 89 with EmbeddedChannel

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

the class JsonObjectDecoderTest method testBackslashInString1.

@Test
public void testBackslashInString1() {
    EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
    // {"foo" : "bar\""}
    String json = "{\"foo\" : \"bar\\\"\"}";
    System.out.println(json);
    ch.writeInbound(Unpooled.copiedBuffer(json, CharsetUtil.UTF_8));
    ByteBuf res = ch.readInbound();
    assertEquals(json, res.toString(CharsetUtil.UTF_8));
    res.release();
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 90 with EmbeddedChannel

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

the class JsonObjectDecoderTest method testNonJsonContent2.

@Test(expected = CorruptedFrameException.class)
public void testNonJsonContent2() {
    EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
    ch.writeInbound(Unpooled.copiedBuffer("  [1,2,3]  ", CharsetUtil.UTF_8));
    ByteBuf res = ch.readInbound();
    assertEquals("[1,2,3]", res.toString(CharsetUtil.UTF_8));
    res.release();
    try {
        ch.writeInbound(Unpooled.copiedBuffer(" a {\"key\" : 10}", CharsetUtil.UTF_8));
    } finally {
        assertFalse(ch.finish());
    }
    fail();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) 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