use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class HouseKeeperTest method shouldLogOnlyTheFirstCaughtException.
@Test
void shouldLogOnlyTheFirstCaughtException() throws Exception {
AssertableLogProvider logProvider = new AssertableLogProvider();
BoltConnection connection = mock(BoltConnection.class);
HouseKeeper houseKeeper = new HouseKeeper(connection, logProvider.getLog(HouseKeeper.class));
Bootstrap bootstrap = newBootstrap(houseKeeper);
RuntimeException error1 = new RuntimeException("error #1");
RuntimeException error2 = new RuntimeException("error #2");
RuntimeException error3 = new RuntimeException("error #3");
try (ServerSocket serverSocket = new ServerSocket(0)) {
ChannelFuture future = bootstrap.connect("localhost", serverSocket.getLocalPort()).sync();
Channel channel = future.channel();
// fire multiple errors
channel.pipeline().fireExceptionCaught(error1);
channel.pipeline().fireExceptionCaught(error2);
channel.pipeline().fireExceptionCaught(error3);
// await for the channel to be closed by the HouseKeeper
channel.closeFuture().sync();
} finally {
// make sure event loop group is always terminated
bootstrap.config().group().shutdownGracefully().sync();
}
assertThat(logProvider).forClass(HouseKeeper.class).forLevel(ERROR).containsMessageWithException("Fatal error occurred when handling a client connection", error1);
}
use of org.neo4j.bolt.runtime.BoltConnection 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());
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class HouseKeeperTest method shouldNotPropagateExceptionCaught.
@Test
void shouldNotPropagateExceptionCaught() throws Exception {
ChannelInboundHandler next = mock(ChannelInboundHandler.class);
BoltConnection connection = mock(BoltConnection.class);
channel = new EmbeddedChannel(new HouseKeeper(connection, NullLog.getInstance()), next);
channel.pipeline().fireExceptionCaught(new RuntimeException("some exception"));
verify(next, never()).exceptionCaught(any(), any());
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class HouseKeeperTest method shouldLogExceptionOnExceptionCaught.
@Test
void shouldLogExceptionOnExceptionCaught() {
AssertableLogProvider logProvider = new AssertableLogProvider();
BoltConnection connection = mock(BoltConnection.class);
channel = new EmbeddedChannel(new HouseKeeper(connection, logProvider.getLog(HouseKeeper.class)));
RuntimeException exception = new RuntimeException("some exception");
channel.pipeline().fireExceptionCaught(exception);
verify(connection).stop();
assertThat(logProvider).forClass(HouseKeeper.class).forLevel(ERROR).containsMessageWithException("Fatal error occurred when handling a client connection", exception);
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class HouseKeeperTest method shouldNotLogExceptionsWhenEvenLoopIsShuttingDown.
@Test
void shouldNotLogExceptionsWhenEvenLoopIsShuttingDown() throws Exception {
AssertableLogProvider logProvider = new AssertableLogProvider();
BoltConnection connection = mock(BoltConnection.class);
HouseKeeper houseKeeper = new HouseKeeper(connection, logProvider.getLog(HouseKeeper.class));
Bootstrap bootstrap = newBootstrap(houseKeeper);
try (ServerSocket serverSocket = new ServerSocket(0)) {
ChannelFuture future = bootstrap.connect("localhost", serverSocket.getLocalPort()).sync();
Channel channel = future.channel();
// write some messages without flushing
for (int i = 0; i < 100; i++) {
// use void promise which should redirect all write errors back to the pipeline and the HouseKeeper
channel.write(writeUtf8(channel.alloc(), "Hello"), channel.voidPromise());
}
// stop the even loop to make all pending writes fail
bootstrap.config().group().shutdownGracefully();
// await for the channel to be closed by the HouseKeeper
channel.closeFuture().sync();
} finally {
// make sure event loop group is always terminated
bootstrap.config().group().shutdownGracefully().sync();
}
assertThat(logProvider).doesNotHaveAnyLogs();
}
Aggregations