Search in sources :

Example 51 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltProtocolV1Test method closesInputAndOutput.

@Test
public void closesInputAndOutput() {
    Channel outputChannel = mock(Channel.class);
    ByteBufAllocator allocator = mock(ByteBufAllocator.class);
    ByteBuf buffer = mock(ByteBuf.class);
    when(outputChannel.alloc()).thenReturn(allocator);
    when(allocator.buffer(anyInt(), anyInt())).thenReturn(buffer);
    BoltStateMachine machine = mock(BoltStateMachine.class);
    BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), outputChannel, NullLogService.getInstance());
    protocol.close();
    verify(machine).close();
    verify(buffer).release();
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) SynchronousBoltWorker(org.neo4j.bolt.v1.runtime.SynchronousBoltWorker) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Channel(io.netty.channel.Channel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 52 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine 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

BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)49 Test (org.junit.Test)43 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)31 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 HashMap (java.util.HashMap)4 SocketTransportHandler (org.neo4j.bolt.transport.SocketTransportHandler)4 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)4 SynchronousBoltWorker (org.neo4j.bolt.v1.runtime.SynchronousBoltWorker)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 InetSocketAddress (java.net.InetSocketAddress)3 BaseMatcher (org.hamcrest.BaseMatcher)3 Description (org.hamcrest.Description)3 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)3 Record (org.neo4j.bolt.v1.runtime.spi.Record)3 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)2 BoltResponseHandler (org.neo4j.bolt.v1.runtime.BoltResponseHandler)2 StatementProcessor (org.neo4j.bolt.v1.runtime.StatementProcessor)2 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)2 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)2