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);
}
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());
}
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());
}
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();
}
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;
}
Aggregations