use of org.neo4j.bolt.runtime.BoltConnectionFactory in project neo4j by neo4j.
the class AbstractBoltProtocolTest method shouldInstallChannelHandlersInCorrectOrder.
@Test
void shouldInstallChannelHandlersInCorrectOrder() throws Throwable {
// Given
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltConnectionFactory connectionFactory = mock(BoltConnectionFactory.class);
var memoryTracker = mock(MemoryTracker.class);
when(connectionFactory.newConnection(eq(boltChannel), any(), any())).thenReturn(mock(BoltConnection.class));
BoltProtocol boltProtocol = new TestAbstractBoltProtocol(boltChannel, connectionFactory, mock(BoltStateMachineFactory.class), Config.defaults(), NullLogService.getInstance(), mock(TransportThrottleGroup.class), mock(ChannelProtector.class), memoryTracker);
// When
boltProtocol.install();
Iterator<Map.Entry<String, ChannelHandler>> handlers = channel.pipeline().iterator();
assertThat(handlers.next().getValue()).isInstanceOf(ChunkDecoder.class);
assertThat(handlers.next().getValue()).isInstanceOf(MessageAccumulator.class);
assertThat(handlers.next().getValue()).isInstanceOf(MessageDecoder.class);
assertThat(handlers.next().getValue()).isInstanceOf(HouseKeeper.class);
assertFalse(handlers.hasNext());
}
use of org.neo4j.bolt.runtime.BoltConnectionFactory 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.runtime.BoltConnectionFactory in project neo4j by neo4j.
the class BoltServer method init.
@Override
public void init() {
Log log = logService.getInternalLog(BoltServer.class);
boltMemoryPool = new BoltMemoryPool(memoryPools, NETTY_BUF_ALLOCATOR.metric());
life.add(new BoltMemoryPoolLifeCycleAdapter(boltMemoryPool));
InternalLoggerFactory.setDefaultFactory(new Netty4LoggerFactory(logService.getInternalLogProvider()));
TransportThrottleGroup throttleGroup = new TransportThrottleGroup(config, clock);
BoltSchedulerProvider boltSchedulerProvider = life.setLast(new ExecutorBoltSchedulerProvider(config, new CachedThreadPoolExecutorFactory(), jobScheduler, logService));
BoltConnectionFactory boltConnectionFactory = createConnectionFactory(config, boltSchedulerProvider, logService, clock);
BoltStateMachineFactory externalBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(externalAuthManager), clock);
BoltStateMachineFactory internalBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(internalAuthManager), clock);
BoltStateMachineFactory loopbackBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(loopbackAuthManager), clock);
BoltProtocolFactory externalBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, externalBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
BoltProtocolFactory internalBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, internalBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
BoltProtocolFactory loopbackBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, loopbackBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
if (config.get(CommonConnectorConfig.ocsp_stapling_enabled)) {
enableOcspStapling();
}
ByteBufAllocator bufferAllocator = getBufferAllocator();
if (config.get(BoltConnector.enabled)) {
jobScheduler.setThreadFactory(Group.BOLT_NETWORK_IO, NettyThreadFactory::new);
NettyServer nettyServer;
var isNotReadReplica = config.get(GraphDatabaseSettings.mode) != GraphDatabaseSettings.Mode.READ_REPLICA;
var loopbackProtocolInitializer = createLoopbackProtocolInitializer(loopbackBoltProtocolFactory, throttleGroup, bufferAllocator);
if (config.get(GraphDatabaseSettings.routing_enabled) && isNotReadReplica) {
nettyServer = new NettyServer(jobScheduler.threadFactory(Group.BOLT_NETWORK_IO), createExternalProtocolInitializer(externalBoltProtocolFactory, throttleGroup, log, bufferAllocator), createInternalProtocolInitializer(internalBoltProtocolFactory, throttleGroup, bufferAllocator), loopbackProtocolInitializer, connectorPortRegister, logService, config);
} else {
nettyServer = new NettyServer(jobScheduler.threadFactory(Group.BOLT_NETWORK_IO), createExternalProtocolInitializer(externalBoltProtocolFactory, throttleGroup, log, bufferAllocator), loopbackProtocolInitializer, connectorPortRegister, logService, config);
}
life.add(nettyServer);
log.info("Bolt server loaded");
}
life.init();
}
Aggregations