Search in sources :

Example 21 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.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 22 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.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 23 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class WebSocketServerProtocolHandlerTest method testHttpUpgradeRequest.

@Test
public void testHttpUpgradeRequest() throws Exception {
    EmbeddedChannel ch = createChannel(new MockOutboundHandler());
    ChannelHandlerContext handshakerCtx = ch.pipeline().context(WebSocketServerProtocolHandshakeHandler.class);
    writeUpgradeRequest(ch);
    FullHttpResponse response = responses.remove();
    assertEquals(SWITCHING_PROTOCOLS, response.status());
    response.release();
    assertNotNull(WebSocketServerProtocolHandler.getHandshaker(handshakerCtx.channel()));
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Test(org.junit.Test)

Example 24 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project netty by netty.

the class HttpClientCodecTest method testFailsNotOnRequestResponse.

@Test
public void testFailsNotOnRequestResponse() {
    HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
    EmbeddedChannel ch = new EmbeddedChannel(codec);
    ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
    ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1));
    ch.finish();
    for (; ; ) {
        Object msg = ch.readOutbound();
        if (msg == null) {
            break;
        }
        release(msg);
    }
    for (; ; ) {
        Object msg = ch.readInbound();
        if (msg == null) {
            break;
        }
        release(msg);
    }
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 25 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project neo4j by neo4j.

the class TxPullResponseEncodeDecodeTest method shouldEncodeAndDecodePullResponseMessage.

@Test
public void shouldEncodeAndDecodePullResponseMessage() {
    // given
    EmbeddedChannel channel = new EmbeddedChannel(new TxPullResponseEncoder(), new TxPullResponseDecoder());
    TxPullResponse sent = new TxPullResponse(new StoreId(1, 2, 3, 4), newCommittedTransactionRepresentation());
    // when
    channel.writeOutbound(sent);
    channel.writeInbound(new Object[] { channel.readOutbound() });
    // then
    TxPullResponse received = (TxPullResponse) channel.readInbound();
    assertNotSame(sent, received);
    assertEquals(sent, received);
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1065 Test (org.junit.jupiter.api.Test)540 ByteBuf (io.netty.buffer.ByteBuf)371 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)88 HttpResponse (io.netty.handler.codec.http.HttpResponse)75 HttpRequest (io.netty.handler.codec.http.HttpRequest)72 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)65 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)62 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)55 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)47 ArrayList (java.util.ArrayList)47 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)39 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 Before (org.junit.Before)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32