use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project baseio by generallycloud.
the class TestLoadEchoClient1 method prepare.
@Override
public void prepare() throws Exception {
eventHandleAdaptor = new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// System.out.println("_________________"+msg);
// ctx.write(msg);
addCount(1);
}
};
Bootstrap b = new Bootstrap();
b.group(group);
b.channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, false);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
pipeline.addLast("handler", eventHandleAdaptor);
}
});
f = b.connect("localhost", 5656).sync();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class DefaultRequestProcessorTest method testProcessRequest_UnregisterBroker.
@Test
public void testProcessRequest_UnregisterBroker() throws RemotingCommandException, NoSuchFieldException, IllegalAccessException {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(null);
// Register broker
RemotingCommand regRequest = genSampleRegisterCmd(true);
defaultRequestProcessor.processRequest(ctx, regRequest);
// Unregister broker
RemotingCommand unregRequest = genSampleRegisterCmd(false);
RemotingCommand unregResponse = defaultRequestProcessor.processRequest(ctx, unregRequest);
assertThat(unregResponse.getCode()).isEqualTo(ResponseCode.SUCCESS);
assertThat(unregResponse.getRemark()).isNull();
RouteInfoManager routes = namesrvController.getRouteInfoManager();
Field brokerAddrTable = RouteInfoManager.class.getDeclaredField("brokerAddrTable");
brokerAddrTable.setAccessible(true);
assertThat((Map) brokerAddrTable.get(routes)).isNotEmpty();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class DefaultRequestProcessorTest method testProcessRequest_RegisterBrokerWithFilterServer.
@Test
public void testProcessRequest_RegisterBrokerWithFilterServer() throws RemotingCommandException, NoSuchFieldException, IllegalAccessException {
RemotingCommand request = genSampleRegisterCmd(true);
// version >= MQVersion.Version.V3_0_11.ordinal() to register with filter server
request.setVersion(100);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(null);
RemotingCommand response = defaultRequestProcessor.processRequest(ctx, request);
assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
assertThat(response.getRemark()).isNull();
RouteInfoManager routes = namesrvController.getRouteInfoManager();
Field brokerAddrTable = RouteInfoManager.class.getDeclaredField("brokerAddrTable");
brokerAddrTable.setAccessible(true);
BrokerData broker = new BrokerData();
broker.setBrokerName("broker");
broker.setBrokerAddrs((HashMap) Maps.newHashMap(new Long(2333), "10.10.1.1"));
assertThat((Map) brokerAddrTable.get(routes)).contains(new HashMap.SimpleEntry("broker", broker));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project bookkeeper by apache.
the class BookieProtoEncodingTest method testV3ResponseDecoderNoFallback.
@Test
public void testV3ResponseDecoderNoFallback() throws Exception {
AddResponse v2Resp = AddResponse.create(BookieProtocol.CURRENT_PROTOCOL_VERSION, BookieProtocol.EOK, 1L, 2L);
BookkeeperProtocol.Response v3Resp = BookkeeperProtocol.Response.newBuilder().setHeader(BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setTxnId(1L).setOperation(OperationType.ADD_ENTRY).build()).setStatus(StatusCode.EOK).setAddResponse(BookkeeperProtocol.AddResponse.newBuilder().setStatus(StatusCode.EOK).setLedgerId(1L).setEntryId(2L).build()).build();
List<Object> outList = Lists.newArrayList();
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.fireChannelRead(any())).thenAnswer((iom) -> {
outList.add(iom.getArgument(0));
return null;
});
ResponseEnDeCoderPreV3 v2Encoder = new ResponseEnDeCoderPreV3(null);
ResponseEnDecoderV3 v3Encoder = new ResponseEnDecoderV3(null);
ResponseDecoder v3Decoder = new ResponseDecoder(null, false);
try {
v3Decoder.channelRead(ctx, v2Encoder.encode(v2Resp, UnpooledByteBufAllocator.DEFAULT));
fail("V3 response decoder should fail on decoding v2 response");
} catch (InvalidProtocolBufferException e) {
// expected
}
assertEquals(0, outList.size());
v3Decoder.channelRead(ctx, v3Encoder.encode(v3Resp, UnpooledByteBufAllocator.DEFAULT));
assertEquals(1, outList.size());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project bookkeeper by apache.
the class ByteBufListTest method testEncoder.
@Test
public void testEncoder() throws Exception {
ByteBuf b1 = PooledByteBufAllocator.DEFAULT.heapBuffer(128, 128);
b1.writerIndex(b1.capacity());
ByteBuf b2 = PooledByteBufAllocator.DEFAULT.heapBuffer(128, 128);
b2.writerIndex(b2.capacity());
ByteBufList buf = ByteBufList.get(b1, b2);
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBufList.ENCODER.write(ctx, buf, null);
assertEquals(buf.refCnt(), 0);
assertEquals(b1.refCnt(), 0);
assertEquals(b2.refCnt(), 0);
}
Aggregations