use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.
the class DefaultBoltProtocolFactoryTest method shouldCreateBoltProtocol.
@ParameterizedTest(name = "V{0}.{1}")
@CsvSource({ "3, 0", "4, 0", "4, 1", "4, 2", "4, 3" })
void shouldCreateBoltProtocol(int majorVersion, int minorVersion) throws Throwable {
EmbeddedChannel channel = new EmbeddedChannel();
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltProtocolVersion boltProtocolVersion = new BoltProtocolVersion(majorVersion, minorVersion);
BoltStateMachineFactory stateMachineFactory = mock(BoltStateMachineFactory.class);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
var channelProtector = mock(ChannelProtector.class);
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
when(stateMachineFactory.newStateMachine(boltProtocolVersion, boltChannel, MapValue.EMPTY, memoryTracker)).thenReturn(stateMachine);
BoltConnectionFactory connectionFactory = mock(BoltConnectionFactory.class);
BoltConnection connection = mock(BoltConnection.class);
when(connectionFactory.newConnection(eq(boltChannel), eq(stateMachine), any())).thenReturn(connection);
BoltProtocolFactory factory = new DefaultBoltProtocolFactory(connectionFactory, stateMachineFactory, Config.defaults(), NullLogService.getInstance(), new TestDatabaseIdRepository(), CustomBookmarkFormatParser.DEFAULT, mock(TransportThrottleGroup.class), Clocks.fakeClock(), Duration.ZERO);
BoltProtocol protocol = factory.create(boltProtocolVersion, boltChannel, channelProtector, memoryTracker);
protocol.install();
// handler with correct version is created
assertEquals(boltProtocolVersion, protocol.version());
// it uses the expected worker
verify(connectionFactory).newConnection(eq(boltChannel), any(BoltStateMachine.class), any(BoltResponseMessageWriter.class));
verify(memoryTracker, times(5)).allocateHeap(anyLong());
// and halts this same worker when closed
verify(connection, never()).stop();
channel.close();
verify(connection).stop();
channel.finishAndReleaseAll();
}
use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.
the class SocketTransport method channelInitializer.
@Override
public ChannelInitializer<Channel> channelInitializer() {
return new ChannelInitializer<>() {
@Override
public void initChannel(Channel ch) {
ch.config().setAllocator(allocator);
var memoryTracker = new LocalMemoryTracker(memoryPool, 0, 64, null);
ch.closeFuture().addListener(future -> memoryTracker.close());
memoryTracker.allocateHeap(HeapEstimator.sizeOf(ch));
memoryTracker.allocateHeap(UnauthenticatedChannelProtector.SHALLOW_SIZE + BoltChannel.SHALLOW_SIZE);
var channelProtector = new UnauthenticatedChannelProtector(ch, channelTimeout, maxMessageSize, memoryTracker);
BoltChannel boltChannel = newBoltChannel(ch, channelProtector, memoryTracker);
connectionTracker.add(boltChannel);
ch.closeFuture().addListener(future -> connectionTracker.remove(boltChannel));
// install throttles
throttleGroup.install(ch, memoryTracker);
// add a close listener that will uninstall throttles
ch.closeFuture().addListener(future -> throttleGroup.uninstall(ch));
memoryTracker.allocateHeap(TransportSelectionHandler.SHALLOW_SIZE);
TransportSelectionHandler transportSelectionHandler = new TransportSelectionHandler(boltChannel, sslCtx, encryptionRequired, false, logging, boltProtocolFactory, channelProtector, memoryTracker);
ch.pipeline().addLast(transportSelectionHandler);
}
};
}
use of org.neo4j.bolt.BoltChannel 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.BoltChannel in project neo4j by neo4j.
the class DefaultBoltConnectionFactoryTest method shouldInstallKeepAliveHandler.
@Test
void shouldInstallKeepAliveHandler() {
var schedulerProvider = mock(BoltSchedulerProvider.class);
var config = Config.newBuilder().set(BoltConnectorInternalSettings.connection_keep_alive_type, BoltConnectorInternalSettings.KeepAliveRequestType.ALL).build();
var logService = mock(LogService.class);
var pipeline = mock(ChannelPipeline.class);
var channel = mock(Channel.class, RETURNS_MOCKS);
var protector = mock(ChannelProtector.class);
var boltChannel = new BoltChannel("bolt123", "joffrey", channel, protector);
var stateMachine = mock(BoltStateMachine.class);
var messageWriter = mock(BoltResponseMessageWriter.class);
when(channel.pipeline()).thenReturn(pipeline);
var connectionFactory = new DefaultBoltConnectionFactory(schedulerProvider, config, logService, Clock.systemUTC(), new Monitors());
connectionFactory.newConnection(boltChannel, stateMachine, messageWriter);
verify(channel).pipeline();
verify(pipeline).addLast(Mockito.any(KeepAliveHandler.class));
verifyNoMoreInteractions(pipeline);
}
use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldSetPendingErrorOnMarkFailedIfNoHandler.
@Test
void shouldSetPendingErrorOnMarkFailedIfNoHandler() {
BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class);
BoltChannel boltChannel = mock(BoltChannel.class);
var memoryTracker = mock(MemoryTracker.class);
BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
machine.markFailed(error);
assertEquals(error, pendingError(machine));
assertThat(machine).satisfies(inState(FailedState.class));
}
Aggregations