Search in sources :

Example 6 with SocketTransportHandler

use of org.neo4j.bolt.transport.SocketTransportHandler in project neo4j by neo4j.

the class SocketTransportHandlerTest method logsAndClosesContextWhenProtocolNotInitializedOnUnexpectedExceptions.

@Test
public void logsAndClosesContextWhenProtocolNotInitializedOnUnexpectedExceptions() throws Throwable {
    // Given
    ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    AssertableLogProvider logging = new AssertableLogProvider();
    SocketTransportHandler handler = new SocketTransportHandler(mock(ProtocolChooser.class), logging);
    // When
    Throwable cause = new Throwable("Oh no!");
    handler.exceptionCaught(context, cause);
    // Then
    verify(context).close();
    logging.assertExactly(inLog(SocketTransportHandler.class).error(equalTo("Fatal error occurred when handling a client connection: Oh no!"), is(cause)));
}
Also used : SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 7 with SocketTransportHandler

use of org.neo4j.bolt.transport.SocketTransportHandler in project neo4j by neo4j.

the class SocketTransportHandlerTest method logsAndClosesProtocolOnUnexpectedExceptions.

@Test
public void logsAndClosesProtocolOnUnexpectedExceptions() throws Throwable {
    // Given
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ChannelHandlerContext ctx = channelHandlerContextMock();
    AssertableLogProvider logging = new AssertableLogProvider();
    SocketTransportHandler handler = new SocketTransportHandler(protocolChooser(machine), logging);
    // And Given a session has been established
    handler.channelRead(ctx, handshake());
    // When
    Throwable cause = new Throwable("Oh no!");
    handler.exceptionCaught(ctx, cause);
    // Then
    verify(machine).close();
    logging.assertExactly(inLog(SocketTransportHandler.class).error(equalTo("Fatal error occurred when handling a client connection: Oh no!"), is(cause)));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 Test (org.junit.Test)7 SocketTransportHandler (org.neo4j.bolt.transport.SocketTransportHandler)7 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)4 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)4 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 BoltProtocol (org.neo4j.bolt.transport.BoltProtocol)1