Search in sources :

Example 16 with BoltConnection

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);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 17 with BoltConnection

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());
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.jupiter.api.Test)

Example 18 with BoltConnection

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());
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.jupiter.api.Test)

Example 19 with BoltConnection

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);
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 20 with BoltConnection

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();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

BoltConnection (org.neo4j.bolt.runtime.BoltConnection)31 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InetSocketAddress (java.net.InetSocketAddress)3 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)3 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelInboundHandler (io.netty.channel.ChannelInboundHandler)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 ServerSocket (java.net.ServerSocket)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2