Search in sources :

Example 1 with SocketTransportHandler

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

the class SocketTransportHandlerTest method shouldInitializeProtocolOnFirstMessage.

@Test
public void shouldInitializeProtocolOnFirstMessage() throws Exception {
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ProtocolChooser chooser = protocolChooser(machine);
    ChannelHandlerContext context = channelHandlerContextMock();
    SocketTransportHandler handler = new SocketTransportHandler(chooser, NullLogProvider.getInstance());
    handler.channelRead(context, handshake());
    BoltProtocol protocol1 = chooser.chosenProtocol();
    handler.channelRead(context, handshake());
    BoltProtocol protocol2 = chooser.chosenProtocol();
    assertSame(protocol1, protocol2);
}
Also used : BoltProtocol(org.neo4j.bolt.transport.BoltProtocol) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) Test(org.junit.Test)

Example 2 with SocketTransportHandler

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

the class SocketTransportHandlerTest method shouldCloseContextWhenProtocolNotInitializedOnHandlerRemoved.

@Test
public void shouldCloseContextWhenProtocolNotInitializedOnHandlerRemoved() throws Throwable {
    // Given
    ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    SocketTransportHandler handler = newSocketTransportHandler(mock(ProtocolChooser.class));
    // When
    handler.handlerRemoved(context);
    // Then
    verify(context).close();
}
Also used : SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) Test(org.junit.Test)

Example 3 with SocketTransportHandler

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

the class SocketTransportHandlerTest method shouldCloseProtocolOnChannelInactive.

@Test
public void shouldCloseProtocolOnChannelInactive() throws Throwable {
    // Given
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ChannelHandlerContext ctx = channelHandlerContextMock();
    SocketTransportHandler handler = newSocketTransportHandler(protocolChooser(machine));
    // And Given a session has been established
    handler.channelRead(ctx, handshake());
    // When
    handler.channelInactive(ctx);
    // Then
    verify(machine).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 4 with SocketTransportHandler

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

the class SocketTransportHandlerTest method shouldCloseProtocolOnHandlerRemoved.

@Test
public void shouldCloseProtocolOnHandlerRemoved() throws Throwable {
    // Given
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ChannelHandlerContext ctx = channelHandlerContextMock();
    SocketTransportHandler handler = newSocketTransportHandler(protocolChooser(machine));
    // And Given a session has been established
    handler.channelRead(ctx, handshake());
    // When
    handler.handlerRemoved(ctx);
    // Then
    verify(machine).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 5 with SocketTransportHandler

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

the class SocketTransportHandlerTest method shouldCloseContextWhenProtocolNotInitializedOnChannelInactive.

@Test
public void shouldCloseContextWhenProtocolNotInitializedOnChannelInactive() throws Throwable {
    // Given
    ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    SocketTransportHandler handler = newSocketTransportHandler(mock(ProtocolChooser.class));
    // When
    handler.channelInactive(context);
    // Then
    verify(context).close();
}
Also used : SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) 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