Search in sources :

Example 11 with BoltProtocolVersion

use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.

the class ProtocolHandshakerTest method shouldHandleProtocolRanges.

@ParameterizedTest
@MethodSource("protocolVersionProviderInRange")
void shouldHandleProtocolRanges(int major, int minor) {
    // Given
    int packedVersion = new BoltProtocolVersion(major, minor).toInt();
    BoltProtocol protocol = newBoltProtocol(major, minor);
    BoltProtocolFactory handlerFactory = newProtocolFactory(major, minor, protocol);
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, boltChannel, logProvider, false, true, mock(ChannelProtector.class), memoryTracker));
    // When
    ByteBuf input = // create handshake data
    Unpooled.wrappedBuffer(// preamble
    new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17 }, // first choice - 4.0 no range
    new byte[] { 0, 0, 0, 4 }, // second choice - 4.3 -> 4.1 inclusive range of 2
    new byte[] { 0, 2, 3, 4 }, // No protocol
    new byte[] { 0, 0, 0, 0 }, // No protocol
    new byte[] { 0, 0, 0, 0 });
    channel.writeInbound(input);
    // Then
    assertEquals(1, channel.outboundMessages().size());
    assertByteBufEquals(Unpooled.buffer().writeInt(packedVersion), channel.readOutbound());
    assertThrows(NoSuchElementException.class, () -> channel.pipeline().remove(ProtocolHandshaker.class));
    assertTrue(channel.isActive());
}
Also used : BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) BoltProtocolFactory(org.neo4j.bolt.transport.BoltProtocolFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with BoltProtocolVersion

use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.

the class ProtocolHandshakerTest method newBoltProtocol.

private static BoltProtocol newBoltProtocol(int majorVersion, int minorVersion) {
    BoltProtocol handler = mock(BoltProtocol.class);
    when(handler.version()).thenReturn(new BoltProtocolVersion(majorVersion, minorVersion));
    return handler;
}
Also used : BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion)

Example 13 with BoltProtocolVersion

use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.

the class ProtocolHandshakerTest method shouldHandleMaxVersionNumber.

@Test
void shouldHandleMaxVersionNumber() {
    int maxVersionNumber = 255;
    // Given
    BoltProtocol protocol = newBoltProtocol(maxVersionNumber, maxVersionNumber);
    BoltProtocolFactory handlerFactory = newProtocolFactory(maxVersionNumber, maxVersionNumber, protocol);
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, boltChannel, logProvider, false, true, mock(ChannelProtector.class), memoryTracker));
    // When
    ByteBuf input = // create handshake data
    Unpooled.wrappedBuffer(// preamble
    new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17 }, // first choice - no protocol
    new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, // second choice - protocol 1
    new byte[] { 0, 0, 0, 0 }, // third choice - no protocol
    new byte[] { 0, 0, 0, 0 }, // fourth choice - no protocol
    new byte[] { 0, 0, 0, 0 });
    channel.writeInbound(input);
    // Then
    assertEquals(1, channel.outboundMessages().size());
    assertByteBufEquals(Unpooled.buffer().writeInt(new BoltProtocolVersion(maxVersionNumber, maxVersionNumber).toInt()), channel.readOutbound());
    assertThrows(NoSuchElementException.class, () -> channel.pipeline().remove(ProtocolHandshaker.class));
    assertTrue(channel.isActive());
    verify(protocol).install();
}
Also used : BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) BoltProtocolFactory(org.neo4j.bolt.transport.BoltProtocolFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with BoltProtocolVersion

use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.

the class DefaultBoltProtocolFactoryTest method shouldCreateNothingForUnknownProtocolVersion.

@Test
void shouldCreateNothingForUnknownProtocolVersion() {
    int protocolVersion = 42;
    BoltChannel channel = newTestBoltChannel();
    BoltProtocolFactory factory = new DefaultBoltProtocolFactory(mock(BoltConnectionFactory.class), mock(BoltStateMachineFactory.class), Config.defaults(), NullLogService.getInstance(), new TestDatabaseIdRepository(), CustomBookmarkFormatParser.DEFAULT, mock(TransportThrottleGroup.class), Clocks.fakeClock(), Duration.ZERO);
    BoltProtocol protocol = factory.create(new BoltProtocolVersion(protocolVersion, 0), channel, mock(ChannelProtector.class), mock(MemoryTracker.class));
    // handler is not created
    assertNull(protocol);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with BoltProtocolVersion

use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV42.

@Test
void shouldCreateBoltStateMachinesV42() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 2), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV42.class);
    verify(memoryTracker).getScopedMemoryTracker();
    verify(memoryTracker, times(3)).allocateHeap(anyLong());
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)17 Test (org.junit.jupiter.api.Test)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)6 BoltProtocol (org.neo4j.bolt.BoltProtocol)5 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 ByteBuf (io.netty.buffer.ByteBuf)2 BoltChannel (org.neo4j.bolt.BoltChannel)2 BoltConnectionFactory (org.neo4j.bolt.runtime.BoltConnectionFactory)2 BoltStateMachineFactory (org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory)2 BoltTestUtil.newTestBoltChannel (org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel)2 BoltProtocolFactory (org.neo4j.bolt.transport.BoltProtocolFactory)2 TestDatabaseIdRepository (org.neo4j.kernel.database.TestDatabaseIdRepository)2 ArrayList (java.util.ArrayList)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)1 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)1