use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project neo4j by neo4j.
the class RequestDecoderDispatcherTest method shouldLogAWarningIfThereIsNoDecoderForTheMessageType.
@Test
public void shouldLogAWarningIfThereIsNoDecoderForTheMessageType() throws Exception {
// given
RequestDecoderDispatcher<State> dispatcher = new RequestDecoderDispatcher<>(protocol, logProvider);
ChannelInboundHandler delegateOne = mock(ChannelInboundHandler.class);
ChannelInboundHandler delegateThree = mock(ChannelInboundHandler.class);
dispatcher.register(State.one, delegateOne);
dispatcher.register(State.three, delegateThree);
// when
dispatcher.channelRead(mock(ChannelHandlerContext.class), new Object());
// then
AssertableLogProvider.LogMatcher matcher = inLog(RequestDecoderDispatcher.class).warn("Unregistered handler for protocol %s", protocol);
logProvider.assertExactly(matcher);
verifyZeroInteractions(delegateOne, delegateThree);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project traccar by tananaev.
the class BasePipelineFactory method initChannel.
@Override
protected void initChannel(Channel channel) {
final ChannelPipeline pipeline = channel.pipeline();
addTransportHandlers(pipeline::addLast);
if (timeout > 0 && !connector.isDatagram()) {
pipeline.addLast(new IdleStateHandler(timeout, 0, 0));
}
pipeline.addLast(new OpenChannelHandler(connector));
pipeline.addLast(new NetworkMessageHandler());
pipeline.addLast(new StandardLoggingHandler(protocol));
addProtocolHandlers(handler -> {
if (!(handler instanceof BaseProtocolDecoder || handler instanceof BaseProtocolEncoder)) {
if (handler instanceof ChannelInboundHandler) {
handler = new WrapperInboundHandler((ChannelInboundHandler) handler);
} else {
handler = new WrapperOutboundHandler((ChannelOutboundHandler) handler);
}
}
pipeline.addLast(handler);
});
addHandlers(pipeline, TimeHandler.class, GeolocationHandler.class, HemisphereHandler.class, DistanceHandler.class, RemoteAddressHandler.class, FilterHandler.class, GeocoderHandler.class, SpeedLimitHandler.class, MotionHandler.class, CopyAttributesHandler.class, EngineHoursHandler.class, ComputedAttributesHandler.class, WebDataHandler.class, DefaultDataHandler.class, CommandResultEventHandler.class, OverspeedEventHandler.class, BehaviorEventHandler.class, FuelDropEventHandler.class, MotionEventHandler.class, GeofenceEventHandler.class, AlertEventHandler.class, IgnitionEventHandler.class, MaintenanceEventHandler.class, DriverEventHandler.class);
pipeline.addLast(new MainEventHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method httpProxy_completes.
@Test
public void httpProxy_completes() throws Exception {
DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
// ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called
// the channel is already active.
LocalAddress proxy = new LocalAddress("httpProxy_completes");
SocketAddress host = InetSocketAddress.createUnresolved("specialHost", 314);
ChannelInboundHandler mockHandler = mock(ChannelInboundHandler.class);
Channel serverChannel = new ServerBootstrap().group(elg).channel(LocalServerChannel.class).childHandler(mockHandler).bind(proxy).sync().channel();
ProtocolNegotiator nego = ProtocolNegotiators.httpProxy(proxy, null, null, ProtocolNegotiators.plaintext());
// normally NettyClientTransport will add WBAEH which kick start the ProtocolNegotiation,
// mocking the behavior using KickStartHandler.
ChannelHandler handler = new KickStartHandler(nego.newHandler(FakeGrpcHttp2ConnectionHandler.noopHandler()));
Channel channel = new Bootstrap().group(elg).channel(LocalChannel.class).handler(handler).register().sync().channel();
pipeline = channel.pipeline();
// Wait for initialization to complete
channel.eventLoop().submit(NOOP_RUNNABLE).sync();
channel.connect(host).sync();
serverChannel.close();
ArgumentCaptor<ChannelHandlerContext> contextCaptor = ArgumentCaptor.forClass(ChannelHandlerContext.class);
Mockito.verify(mockHandler).channelActive(contextCaptor.capture());
ChannelHandlerContext serverContext = contextCaptor.getValue();
final String golden = "isThisThingOn?";
ChannelFuture negotiationFuture = channel.writeAndFlush(bb(golden, channel));
// Wait for sending initial request to complete
channel.eventLoop().submit(NOOP_RUNNABLE).sync();
ArgumentCaptor<Object> objectCaptor = ArgumentCaptor.forClass(Object.class);
Mockito.verify(mockHandler).channelRead(ArgumentMatchers.<ChannelHandlerContext>any(), objectCaptor.capture());
ByteBuf b = (ByteBuf) objectCaptor.getValue();
String request = b.toString(UTF_8);
b.release();
assertTrue("No trailing newline: " + request, request.endsWith("\r\n\r\n"));
assertTrue("No CONNECT: " + request, request.startsWith("CONNECT specialHost:314 "));
assertTrue("No host header: " + request, request.contains("host: specialHost:314"));
assertFalse(negotiationFuture.isDone());
serverContext.writeAndFlush(bb("HTTP/1.1 200 OK\r\n\r\n", serverContext.channel())).sync();
negotiationFuture.sync();
channel.eventLoop().submit(NOOP_RUNNABLE).sync();
objectCaptor = ArgumentCaptor.forClass(Object.class);
Mockito.verify(mockHandler, times(2)).channelRead(ArgumentMatchers.<ChannelHandlerContext>any(), objectCaptor.capture());
b = (ByteBuf) objectCaptor.getAllValues().get(1);
// If we were using the real grpcHandler, this would have been the HTTP/2 preface
String preface = b.toString(UTF_8);
b.release();
assertEquals(golden, preface);
channel.close();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method httpProxy_500.
@Test
public void httpProxy_500() throws Exception {
DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
// ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called
// the channel is already active.
LocalAddress proxy = new LocalAddress("httpProxy_500");
SocketAddress host = InetSocketAddress.createUnresolved("specialHost", 314);
ChannelInboundHandler mockHandler = mock(ChannelInboundHandler.class);
Channel serverChannel = new ServerBootstrap().group(elg).channel(LocalServerChannel.class).childHandler(mockHandler).bind(proxy).sync().channel();
ProtocolNegotiator nego = ProtocolNegotiators.httpProxy(proxy, null, null, ProtocolNegotiators.plaintext());
// normally NettyClientTransport will add WBAEH which kick start the ProtocolNegotiation,
// mocking the behavior using KickStartHandler.
ChannelHandler handler = new KickStartHandler(nego.newHandler(FakeGrpcHttp2ConnectionHandler.noopHandler()));
Channel channel = new Bootstrap().group(elg).channel(LocalChannel.class).handler(handler).register().sync().channel();
pipeline = channel.pipeline();
// Wait for initialization to complete
channel.eventLoop().submit(NOOP_RUNNABLE).sync();
channel.connect(host).sync();
serverChannel.close();
ArgumentCaptor<ChannelHandlerContext> contextCaptor = ArgumentCaptor.forClass(ChannelHandlerContext.class);
Mockito.verify(mockHandler).channelActive(contextCaptor.capture());
ChannelHandlerContext serverContext = contextCaptor.getValue();
final String golden = "isThisThingOn?";
ChannelFuture negotiationFuture = channel.writeAndFlush(bb(golden, channel));
// Wait for sending initial request to complete
channel.eventLoop().submit(NOOP_RUNNABLE).sync();
ArgumentCaptor<Object> objectCaptor = ArgumentCaptor.forClass(Object.class);
Mockito.verify(mockHandler).channelRead(any(ChannelHandlerContext.class), objectCaptor.capture());
ByteBuf request = (ByteBuf) objectCaptor.getValue();
request.release();
assertFalse(negotiationFuture.isDone());
String response = "HTTP/1.1 500 OMG\r\nContent-Length: 4\r\n\r\noops";
serverContext.writeAndFlush(bb(response, serverContext.channel())).sync();
thrown.expect(ProxyConnectException.class);
try {
negotiationFuture.sync();
} finally {
channel.close();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project neo4j by neo4j.
the class HouseKeeperTest method shouldNotPropagateChannelInactive.
@Test
void shouldNotPropagateChannelInactive() throws Exception {
ChannelInboundHandler next = mock(ChannelInboundHandler.class);
BoltConnection connection = mock(BoltConnection.class);
channel = new EmbeddedChannel(new HouseKeeper(connection, NullLog.getInstance()), next);
channel.pipeline().fireChannelInactive();
verify(next, never()).channelInactive(any());
}
Aggregations