use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project rocketmq by apache.
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 incubator-pulsar by apache.
the class ClientCnxTest method testClientCnxTimeout.
@Test
public void testClientCnxTimeout() throws Exception {
EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("testClientCnxTimeout"));
ClientConfigurationData conf = new ClientConfigurationData();
conf.setOperationTimeoutMs(10);
ClientCnx cnx = new ClientCnx(conf, eventLoop);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
ChannelFuture listenerFuture = mock(ChannelFuture.class);
when(listenerFuture.addListener(anyObject())).thenReturn(listenerFuture);
when(ctx.writeAndFlush(anyObject())).thenReturn(listenerFuture);
Field ctxField = PulsarHandler.class.getDeclaredField("ctx");
ctxField.setAccessible(true);
ctxField.set(cnx, ctx);
try {
cnx.newLookup(null, 123).get();
} catch (Exception e) {
assertTrue(e.getCause() instanceof PulsarClientException.TimeoutException);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project incubator-pulsar by apache.
the class ByteBufPairTest method testEncoder.
@Test
public void testEncoder() throws Exception {
ByteBuf b1 = Unpooled.wrappedBuffer("hello".getBytes());
ByteBuf b2 = Unpooled.wrappedBuffer("world".getBytes());
ByteBufPair buf = ByteBufPair.get(b1, b2);
assertEquals(buf.readableBytes(), 10);
assertEquals(buf.getFirst(), b1);
assertEquals(buf.getSecond(), b2);
assertEquals(buf.refCnt(), 1);
assertEquals(b1.refCnt(), 1);
assertEquals(b2.refCnt(), 1);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.write(any(), any())).then(invocation -> {
// Simulate a write on the context which releases the buffer
((ByteBuf) invocation.getArguments()[0]).release();
return null;
});
ByteBufPair.ENCODER.write(ctx, buf, null);
assertEquals(buf.refCnt(), 0);
assertEquals(b1.refCnt(), 0);
assertEquals(b2.refCnt(), 0);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project incubator-pulsar by apache.
the class ClientErrorsTest method testProducerReconnect.
// Run this test multiple times to reproduce race conditions on reconnection logic
@Test(invocationCount = 10)
public void testProducerReconnect() throws Exception {
AtomicInteger numOfConnections = new AtomicInteger();
AtomicReference<ChannelHandlerContext> channelCtx = new AtomicReference<>();
AtomicBoolean msgSent = new AtomicBoolean();
mockBrokerService.setHandleConnect((ctx, connect) -> {
channelCtx.set(ctx);
ctx.writeAndFlush(Commands.newConnected(connect.getProtocolVersion()));
if (numOfConnections.incrementAndGet() == 2) {
// close the cnx immediately when trying to conenct the 2nd time
ctx.channel().close();
}
});
mockBrokerService.setHandleProducer((ctx, produce) -> {
ctx.writeAndFlush(Commands.newProducerSuccess(produce.getRequestId(), "default-producer", SchemaVersion.Empty));
});
mockBrokerService.setHandleSend((ctx, sendCmd, headersAndPayload) -> {
msgSent.set(true);
ctx.writeAndFlush(Commands.newSendReceipt(0, 0, 1, 1));
});
PulsarClient client = PulsarClient.builder().serviceUrl("http://127.0.0.1:" + WEB_SERVICE_PORT).build();
Producer<byte[]> producer = client.newProducer().topic("persistent://prop/use/ns/t1").create();
// close the cnx after creating the producer
channelCtx.get().channel().close().get();
producer.send(new byte[0]);
assertEquals(msgSent.get(), true);
assertTrue(numOfConnections.get() >= 3);
mockBrokerService.resetHandleConnect();
mockBrokerService.resetHandleProducer();
mockBrokerService.resetHandleSend();
client.close();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project cypher-for-gremlin by opencypher.
the class CypherOpProcessor method explainQuery.
private void explainQuery(Context context, CypherAstWrapper ast, String gremlin) {
Map<String, Object> explanation = new LinkedHashMap<>();
explanation.put("translation", gremlin);
explanation.put("options", ast.getOptions().toString());
ResponseMessage explainMsg = ResponseMessage.build(context.getRequestMessage()).code(ResponseStatusCode.SUCCESS).statusMessage("OK").result(singletonList(explanation)).create();
ChannelHandlerContext ctx = context.getChannelHandlerContext();
ctx.writeAndFlush(explainMsg);
}
Aggregations