Search in sources :

Example 36 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class GetSegmentRequestEncoderTest method encodeRequest.

@Test
public void encodeRequest() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new GetSegmentRequestEncoder());
    channel.writeOutbound(new GetSegmentRequest("clientId", "segmentId"));
    String message = (String) channel.readOutbound();
    assertEquals(newGetSegmentRequest("clientId", "segmentId"), message);
}
Also used : Messages.newGetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.Messages.newGetSegmentRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 37 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class ClientFilterHandlerTest method disallowedClientsShouldNotBeServed.

@Test
public void disallowedClientsShouldNotBeServed() {
    EmbeddedChannel channel = new EmbeddedChannel(new ClientFilterHandler(new ClientFilter() {

        @Override
        public boolean isAllowed(SocketAddress address) {
            return false;
        }
    }));
    channel.connect(new InetSocketAddress("127.0.0.2", 8080));
    assertFalse(channel.isOpen());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 38 with EmbeddedChannel

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

the class SniHandlerTest method testFallbackToDefaultContext.

@Test
public void testFallbackToDefaultContext() throws Exception {
    SslContext nettyContext = makeSslContext(provider, false);
    SslContext leanContext = makeSslContext(provider, false);
    SslContext leanContext2 = makeSslContext(provider, false);
    try {
        DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("*.LEANCLOUD.CN", leanContext).add("chat4.leancloud.cn", leanContext2).build();
        SniHandler handler = new SniHandler(mapping);
        EmbeddedChannel ch = new EmbeddedChannel(handler);
        // invalid
        byte[] message = { 22, 3, 1, 0, 0 };
        try {
            // Push the handshake message.
            ch.writeInbound(Unpooled.wrappedBuffer(message));
        } catch (Exception e) {
        // expected
        }
        assertThat(ch.finish(), is(false));
        assertThat(handler.hostname(), nullValue());
        assertThat(handler.sslContext(), is(nettyContext));
    } finally {
        releaseAll(leanContext, leanContext2, nettyContext);
    }
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DomainNameMappingBuilder(io.netty.util.DomainNameMappingBuilder) DecoderException(io.netty.handler.codec.DecoderException) Test(org.junit.Test)

Example 39 with EmbeddedChannel

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

the class SniHandlerTest method testServerNameParsing.

@Test
public void testServerNameParsing() throws Exception {
    SslContext nettyContext = makeSslContext(provider, false);
    SslContext leanContext = makeSslContext(provider, false);
    SslContext leanContext2 = makeSslContext(provider, false);
    try {
        DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("*.LEANCLOUD.CN", leanContext).add("chat4.leancloud.cn", leanContext2).build();
        SniHandler handler = new SniHandler(mapping);
        EmbeddedChannel ch = new EmbeddedChannel(handler);
        // hex dump of a client hello packet, which contains hostname "CHAT4。LEANCLOUD。CN"
        String tlsHandshakeMessageHex1 = "16030100";
        // part 2
        String tlsHandshakeMessageHex = "bd010000b90303a74225676d1814ba57faff3b366" + "3656ed05ee9dbb2a4dbb1bb1c32d2ea5fc39e0000000100008c0000001700150000164348" + "415434E380824C45414E434C4F5544E38082434E000b000403000102000a00340032000e0" + "00d0019000b000c00180009000a0016001700080006000700140015000400050012001300" + "0100020003000f0010001100230000000d0020001e0601060206030501050205030401040" + "20403030103020303020102020203000f00010133740000";
        try {
            // Push the handshake message.
            // Decode should fail because SNI error
            ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex1)));
            ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex)));
            fail();
        } catch (DecoderException e) {
        // expected
        }
        // This should produce an alert
        assertTrue(ch.finish());
        assertThat(handler.hostname(), is("chat4.leancloud.cn"));
        assertThat(handler.sslContext(), is(leanContext));
        for (; ; ) {
            Object msg = ch.readOutbound();
            if (msg == null) {
                break;
            }
            ReferenceCountUtil.release(msg);
        }
    } finally {
        releaseAll(leanContext, leanContext2, nettyContext);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DomainNameMappingBuilder(io.netty.util.DomainNameMappingBuilder) Test(org.junit.Test)

Example 40 with EmbeddedChannel

use of io.netty.channel.embedded.EmbeddedChannel in project grpc-java by grpc.

the class NettyHandlerTestBase method initChannel.

/**
   * Must be called by subclasses to initialize the handler and channel.
   */
protected final void initChannel(GrpcHttp2HeadersDecoder headersDecoder) throws Exception {
    content = Unpooled.copiedBuffer("hello world", UTF_8);
    frameWriter = spy(new DefaultHttp2FrameWriter());
    frameReader = new DefaultHttp2FrameReader(headersDecoder);
    handler = newHandler();
    channel = new EmbeddedChannel(handler);
    ctx = channel.pipeline().context(handler);
    writeQueue = initWriteQueue();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1027 Test (org.junit.jupiter.api.Test)515 ByteBuf (io.netty.buffer.ByteBuf)356 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)85 HttpResponse (io.netty.handler.codec.http.HttpResponse)73 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)64 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)55 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)50 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)46 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)38 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 ArrayList (java.util.ArrayList)34 Before (org.junit.Before)32 ChannelHandler (io.netty.channel.ChannelHandler)27