Search in sources :

Example 6 with ProtocolChooser

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

the class ProtocolChooserTest method shouldRejectIfInvalidHandshake.

@Test
public void shouldRejectIfInvalidHandshake() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, mock(BiFunction.class));
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0xDE, (byte) 0xAD, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(outcome, equalTo(INVALID_HANDSHAKE));
    assertThat(chooser.chosenProtocol(), nullValue());
}
Also used : BiFunction(java.util.function.BiFunction) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 7 with ProtocolChooser

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

the class ProtocolChooserTest method shouldFallBackToNoneProtocolIfNoMatch.

@Test
public void shouldFallBackToNoneProtocolIfNoMatch() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, mock(BiFunction.class));
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4 }), ch);
    // Then
    assertThat(outcome, equalTo(NO_APPLICABLE_PROTOCOL));
    assertThat(chooser.chosenProtocol(), nullValue());
}
Also used : BiFunction(java.util.function.BiFunction) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 8 with ProtocolChooser

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

the class ProtocolChooserTest method shouldHandleVersionBoundary.

@Test
public void shouldHandleVersionBoundary() throws Throwable {
    // Given
    long maxUnsignedInt32 = 4_294_967_295L;
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(maxUnsignedInt32, factory);
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(outcome, equalTo(PROTOCOL_CHOSEN));
    assertThat(chooser.chosenProtocol(), equalTo(protocol));
}
Also used : ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 9 with ProtocolChooser

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

the class ProtocolChooserTest method shouldHandleHandshakeFollowedByMessageInSameBuffer.

@Test
public void shouldHandleHandshakeFollowedByMessageInSameBuffer() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, factory);
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    ByteBuf buffer = wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, // These last four bytes are not part of the handshake
    4 });
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(buffer, ch);
    // Then
    assertThat(outcome, equalTo(PROTOCOL_CHOSEN));
    assertThat(chooser.chosenProtocol(), equalTo(protocol));
    assertThat(buffer.readableBytes(), equalTo(4));
}
Also used : ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) ByteBuf(io.netty.buffer.ByteBuf) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Aggregations

ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)9 Test (org.junit.Test)8 HandshakeOutcome (org.neo4j.bolt.transport.HandshakeOutcome)7 BiFunction (java.util.function.BiFunction)4 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 HashMap (java.util.HashMap)1 BoltProtocol (org.neo4j.bolt.transport.BoltProtocol)1 SocketTransportHandler (org.neo4j.bolt.transport.SocketTransportHandler)1 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)1 SynchronousBoltWorker (org.neo4j.bolt.v1.runtime.SynchronousBoltWorker)1 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)1