Search in sources :

Example 1 with MotanV2Codec

use of com.weibo.api.motan.protocol.v2motan.MotanV2Codec 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 2 with MotanV2Codec

use of com.weibo.api.motan.protocol.v2motan.MotanV2Codec 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)

Aggregations

MotanV2Codec (com.weibo.api.motan.protocol.v2motan.MotanV2Codec)2 ByteBuf (io.netty.buffer.ByteBuf)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Test (org.junit.Test)2