Search in sources :

Example 1 with BoltConnectionFactory

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());
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) Test(org.junit.jupiter.api.Test)

Example 2 with BoltConnectionFactory

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();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BoltConnectionFactory

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();
}
Also used : BoltMemoryPool(org.neo4j.bolt.transport.BoltMemoryPool) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) DefaultBoltConnectionFactory(org.neo4j.bolt.runtime.DefaultBoltConnectionFactory) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) Log(org.neo4j.logging.Log) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) ExecutorBoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.ExecutorBoltSchedulerProvider) NettyThreadFactory(org.neo4j.bolt.runtime.scheduling.NettyThreadFactory) BoltProtocolFactory(org.neo4j.bolt.transport.BoltProtocolFactory) DefaultBoltProtocolFactory(org.neo4j.bolt.transport.DefaultBoltProtocolFactory) NettyServer(org.neo4j.bolt.transport.NettyServer) CachedThreadPoolExecutorFactory(org.neo4j.bolt.runtime.scheduling.CachedThreadPoolExecutorFactory) ExecutorBoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.ExecutorBoltSchedulerProvider) BoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.BoltSchedulerProvider) Netty4LoggerFactory(org.neo4j.bolt.transport.Netty4LoggerFactory) TransportThrottleGroup(org.neo4j.bolt.transport.TransportThrottleGroup)

Aggregations

BoltConnectionFactory (org.neo4j.bolt.runtime.BoltConnectionFactory)3 BoltStateMachineFactory (org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory)3 BoltChannel (org.neo4j.bolt.BoltChannel)2 BoltProtocol (org.neo4j.bolt.BoltProtocol)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 BoltTestUtil.newTestBoltChannel (org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)1 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1 DefaultBoltConnectionFactory (org.neo4j.bolt.runtime.DefaultBoltConnectionFactory)1 BoltSchedulerProvider (org.neo4j.bolt.runtime.scheduling.BoltSchedulerProvider)1 CachedThreadPoolExecutorFactory (org.neo4j.bolt.runtime.scheduling.CachedThreadPoolExecutorFactory)1 ExecutorBoltSchedulerProvider (org.neo4j.bolt.runtime.scheduling.ExecutorBoltSchedulerProvider)1 NettyThreadFactory (org.neo4j.bolt.runtime.scheduling.NettyThreadFactory)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1