Search in sources :

Example 86 with EmbeddedChannel

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

the class ActiveMQFrameDecoder2Test method testOrdinaryFragmentation.

@Test
public void testOrdinaryFragmentation() throws Exception {
    final EmbeddedChannel decoder = new EmbeddedChannel(new ActiveMQFrameDecoder2());
    final byte[] data = new byte[ActiveMQFrameDecoder2Test.MSG_LEN];
    ActiveMQFrameDecoder2Test.rand.nextBytes(data);
    ByteBuf src = Unpooled.buffer(ActiveMQFrameDecoder2Test.MSG_CNT * (ActiveMQFrameDecoder2Test.MSG_LEN + 4));
    while (src.writerIndex() < src.capacity()) {
        src.writeInt(ActiveMQFrameDecoder2Test.MSG_LEN);
        src.writeBytes(data);
    }
    List<ByteBuf> packets = new ArrayList<>();
    while (src.isReadable()) {
        int length = Math.min(ActiveMQFrameDecoder2Test.rand.nextInt(ActiveMQFrameDecoder2Test.FRAGMENT_MAX_LEN), src.readableBytes());
        packets.add(src.readBytes(length));
    }
    int cnt = 0;
    for (ByteBuf p : packets) {
        decoder.writeInbound(p);
        for (; ; ) {
            ByteBuf frame = (ByteBuf) decoder.readInbound();
            if (frame == null) {
                break;
            }
            Assert.assertEquals(4, frame.readerIndex());
            Assert.assertEquals(ActiveMQFrameDecoder2Test.MSG_LEN, frame.readableBytes());
            Assert.assertEquals(Unpooled.wrappedBuffer(data), frame);
            cnt++;
            frame.release();
        }
    }
    Assert.assertEquals(ActiveMQFrameDecoder2Test.MSG_CNT, cnt);
}
Also used : ActiveMQFrameDecoder2(org.apache.activemq.artemis.core.remoting.impl.netty.ActiveMQFrameDecoder2) ArrayList(java.util.ArrayList) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 87 with EmbeddedChannel

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

the class NettyDecoderTest method onlyOneDecodeInvoked.

@Test
public void onlyOneDecodeInvoked() {
    NettyNewCntDecoder nettyDecoder = new NettyNewCntDecoder(new MotanV2Codec(), nettyServer, 24);
    NettyChannelHandler handler = new NettyChannelHandler(nettyServer, messageHandler, (ThreadPoolExecutor) Executors.newFixedThreadPool(4));
    EmbeddedChannel channel = new EmbeddedChannel(nettyDecoder, handler);
    ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e' });
    channel.writeInbound(buf.copy());
    buf.release();
    assertEquals(true, 1 == nettyDecoder.getDecodeInvokeCnt());
}
Also used : MotanV2Codec(com.weibo.api.motan.protocol.v2motan.MotanV2Codec) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 88 with EmbeddedChannel

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

the class NettyDecoderTest method repeatDecodeInvokedByOldCode.

@Test
public void repeatDecodeInvokedByOldCode() {
    NettyOldFakeDecoder nettyDecoder = new NettyOldFakeDecoder(new MotanV2Codec(), nettyServer, 24);
    NettyChannelHandler handler = new NettyChannelHandler(nettyServer, messageHandler, (ThreadPoolExecutor) Executors.newFixedThreadPool(4));
    EmbeddedChannel channel = new EmbeddedChannel(nettyDecoder, handler);
    ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e' });
    channel.writeInbound(buf.copy());
    buf.release();
    assertEquals(false, 1 == nettyDecoder.getDecodeInvokeCnt());
}
Also used : MotanV2Codec(com.weibo.api.motan.protocol.v2motan.MotanV2Codec) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 89 with EmbeddedChannel

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

the class ZeroCopyStreamingBenchmark method partialStreamWriter.

@Benchmark
@BenchmarkMode(Mode.Throughput)
public void partialStreamWriter(BenchmarkState state) throws Exception {
    EmbeddedChannel channel = createMockNettyChannel();
    AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
    state.partialStreamWriter.write(out);
    out.close();
    channel.finishAndReleaseAll();
}
Also used : AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 90 with EmbeddedChannel

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

the class ZeroCopyStreamingBenchmark method createMockNettyChannel.

private EmbeddedChannel createMockNettyChannel() {
    EmbeddedChannel channel = new EmbeddedChannel();
    // avoid blocking
    channel.config().setWriteBufferHighWaterMark(STREAM_SIZE);
    return channel;
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

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)35 Before (org.junit.Before)32 ChannelHandler (io.netty.channel.ChannelHandler)27