use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.
the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV41.
@Test
void shouldCreateBoltStateMachinesV41() {
BoltStateMachineFactoryImpl factory = newBoltFactory();
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 1), CHANNEL, MapValue.EMPTY, memoryTracker);
assertNotNull(boltStateMachine);
assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV41.class);
verify(memoryTracker).getScopedMemoryTracker();
verify(memoryTracker, times(3)).allocateHeap(anyLong());
verifyNoMoreInteractions(memoryTracker);
}
use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.
the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV4.
@Test
void shouldCreateBoltStateMachinesV4() {
BoltStateMachineFactoryImpl factory = newBoltFactory();
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 0), CHANNEL, MapValue.EMPTY, memoryTracker);
assertNotNull(boltStateMachine);
assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV4.class);
verify(memoryTracker).getScopedMemoryTracker();
verify(memoryTracker, times(3)).allocateHeap(anyLong());
verifyNoMoreInteractions(memoryTracker);
}
use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.
the class BoltStateMachineFactoryImplTest method shouldThrowExceptionIfVersionIsUnknown.
@ParameterizedTest(name = "V{0}")
@ValueSource(ints = { 999, -1, 1, 2 })
void shouldThrowExceptionIfVersionIsUnknown(int protocolVersion) {
BoltStateMachineFactoryImpl factory = newBoltFactory();
BoltProtocolVersion boltProtocolVersion = new BoltProtocolVersion(protocolVersion, 0);
var memoryTracker = mock(MemoryTracker.class);
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> factory.newStateMachine(boltProtocolVersion, CHANNEL, MapValue.EMPTY, memoryTracker));
assertThat(error.getMessage()).startsWith("Failed to create a state machine for protocol version");
verifyNoMoreInteractions(memoryTracker);
}
use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.
the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV43.
@Test
void shouldCreateBoltStateMachinesV43() {
BoltStateMachineFactoryImpl factory = newBoltFactory();
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 3), CHANNEL, MapValue.EMPTY, memoryTracker);
assertNotNull(boltStateMachine);
assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV43.class);
verify(memoryTracker).getScopedMemoryTracker();
verify(memoryTracker, times(3)).allocateHeap(anyLong());
verifyNoMoreInteractions(memoryTracker);
}
use of org.neo4j.bolt.BoltProtocolVersion in project neo4j by neo4j.
the class ProtocolHandshaker method performHandshake.
private boolean performHandshake() {
try (var handshakeMemoryTracker = memoryTracker.getScopedMemoryTracker()) {
ArrayList<BoltProtocolVersion> suggestions = new ArrayList<BoltProtocolVersion>();
for (int i = 0; i < 4; i++) {
int rawBytes = handshakeBuffer.getInt((i + 1) * Integer.BYTES);
int major = BoltProtocolVersion.getMajorFromRawBytes(rawBytes);
int minor = BoltProtocolVersion.getMinorFromRawBytes(rawBytes);
int range = BoltProtocolVersion.getRangeFromRawBytes(rawBytes);
handshakeMemoryTracker.allocateHeap(BoltProtocolVersion.SHALLOW_SIZE * (range + 1));
for (// Range is inclusive thus the use of <=
int j = 0; // Range is inclusive thus the use of <=
j <= range; // Range is inclusive thus the use of <=
j++) {
int newMinor = Math.max(minor - j, 0);
BoltProtocolVersion suggestion = new BoltProtocolVersion(major, newMinor);
protocol = boltProtocolFactory.create(suggestion, boltChannel, channelProtector, memoryTracker);
if (protocol != null) {
break;
}
suggestions.add(suggestion);
}
if (protocol != null) {
break;
}
}
if (protocol == null) {
log.debug("Failed Bolt handshake: Bolt versions suggested by client '%s' are not supported by this server.", Arrays.toString(suggestions.toArray()));
}
}
return protocol != null;
}
Aggregations