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());
}
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;
}
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();
}
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);
}
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);
}
Aggregations