use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project pulsar by yahoo.
the class ClientErrorsTest method testConsumerReconnect.
@Test
public void testConsumerReconnect() throws Exception {
AtomicInteger numOfConnections = new AtomicInteger();
AtomicReference<ChannelHandlerContext> channelCtx = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
mockBrokerService.setHandleConnect((ctx, connect) -> {
channelCtx.set(ctx);
ctx.writeAndFlush(Commands.newConnected(connect));
if (numOfConnections.incrementAndGet() == 2) {
// close the cnx immediately when trying to conenct the 2nd time
ctx.channel().close();
}
if (numOfConnections.get() == 3) {
latch.countDown();
}
});
mockBrokerService.setHandleSubscribe((ctx, subscribe) -> {
ctx.writeAndFlush(Commands.newSuccess(subscribe.getRequestId()));
});
PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);
client.subscribe("persistent://prop/use/ns/t1", "sub");
// close the cnx after creating the producer
channelCtx.get().channel().close();
latch.await(5, TimeUnit.SECONDS);
assertEquals(numOfConnections.get(), 3);
mockBrokerService.resetHandleConnect();
mockBrokerService.resetHandleSubscribe();
client.close();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project jackrabbit-oak by apache.
the class StateConsumerTest method shouldPropagateExceptionCaughtEvent.
@Test
public void shouldPropagateExceptionCaughtEvent() throws Exception {
StateHandler handler = new StateHandler(mock(StateConsumer.class));
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
Throwable t = new Throwable();
handler.exceptionCaught(ctx, t);
verify(ctx).fireExceptionCaught(t);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project jackrabbit-oak by apache.
the class StateConsumerTest method shouldPropagateChannelActiveEvent.
@Test
public void shouldPropagateChannelActiveEvent() throws Exception {
StateHandler handler = new StateHandler(mock(StateConsumer.class));
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
handler.channelActive(ctx);
verify(ctx).fireChannelActive();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project jackrabbit-oak by apache.
the class StateConsumerTest method shouldPropagateChannelInactiveEvent.
@Test
public void shouldPropagateChannelInactiveEvent() throws Exception {
StateHandler handler = new StateHandler(mock(StateConsumer.class));
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
handler.channelInactive(ctx);
verify(ctx).fireChannelInactive();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project intellij-community by JetBrains.
the class WebSocketHandshakeHandler method handleWebSocketRequest.
private void handleWebSocketRequest(@NotNull final ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull final QueryStringDecoder uriDecoder) {
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory("ws://" + request.headers().getAsString(HttpHeaderNames.HOST) + uriDecoder.path(), null, false, NettyUtil.MAX_CONTENT_LENGTH);
WebSocketServerHandshaker handshaker = factory.newHandshaker(request);
if (handshaker == null) {
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(context.channel());
return;
}
if (!context.channel().isOpen()) {
return;
}
final Client client = new WebSocketClient(context.channel(), handshaker);
context.channel().attr(ClientManagerKt.getCLIENT()).set(client);
handshaker.handshake(context.channel(), request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue();
clientManager.addClient(client);
MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer());
BuiltInServer.replaceDefaultHandler(context, messageChannelHandler);
ChannelHandlerContext messageChannelHandlerContext = context.pipeline().context(messageChannelHandler);
context.pipeline().addBefore(messageChannelHandlerContext.name(), "webSocketFrameAggregator", new WebSocketFrameAggregator(NettyUtil.MAX_CONTENT_LENGTH));
messageChannelHandlerContext.channel().attr(ClientManagerKt.getCLIENT()).set(client);
connected(client, uriDecoder.parameters());
}
}
});
}
Aggregations