Search in sources :

Example 6 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method createdWorkerThreadsShouldContainConnectorNameAndRemoteAddressInTheirNamesWhenActive.

@Test
void createdWorkerThreadsShouldContainConnectorNameAndRemoteAddressInTheirNamesWhenActive() throws Exception {
    final AtomicReference<String> capturedThreadName = new AtomicReference<>();
    AtomicInteger processNextBatchCount = new AtomicInteger();
    String id = UUID.randomUUID().toString();
    BoltConnection connection = newConnection(id);
    AtomicBoolean exitCondition = new AtomicBoolean();
    when(connection.processNextBatch()).thenAnswer(inv -> {
        capturedThreadName.set(Thread.currentThread().getName());
        processNextBatchCount.incrementAndGet();
        return awaitExit(exitCondition);
    });
    boltScheduler.init();
    boltScheduler.start();
    boltScheduler.created(connection);
    boltScheduler.enqueued(connection, Jobs.noop());
    Predicates.await(() -> processNextBatchCount.get() > 0, 1, MINUTES);
    assertThat(capturedThreadName.get()).contains(String.format("[%s]", CONNECTOR_KEY));
    assertThat(capturedThreadName.get()).contains(String.format("[%s]", connection.remoteAddress()));
    exitCondition.set(true);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 7 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method enqueuedShouldNotScheduleJobWhenActiveWorkItemExists.

@Test
void enqueuedShouldNotScheduleJobWhenActiveWorkItemExists() throws Throwable {
    String id = UUID.randomUUID().toString();
    BoltConnection connection = newConnection(id);
    AtomicBoolean exitCondition = new AtomicBoolean();
    when(connection.processNextBatch()).thenAnswer(inv -> awaitExit(exitCondition));
    boltScheduler.init();
    boltScheduler.start();
    boltScheduler.created(connection);
    boltScheduler.enqueued(connection, Jobs.noop());
    Predicates.await(() -> boltScheduler.isActive(connection), 1, MINUTES);
    boltScheduler.enqueued(connection, Jobs.noop());
    exitCondition.set(true);
    Predicates.await(() -> !boltScheduler.isActive(connection), 1, MINUTES);
    verify(connection).processNextBatch();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Test(org.junit.jupiter.api.Test)

Example 8 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class MessageProcessingHandlerTest method shouldCallHaltOnUnexpectedFailures.

@Test
void shouldCallHaltOnUnexpectedFailures() throws Exception {
    // Given
    BoltResponseMessageWriter msgWriter = newResponseHandlerMock();
    doThrow(new RuntimeException("Something went horribly wrong")).when(msgWriter).write(any(SuccessMessage.class));
    BoltConnection connection = mock(BoltConnection.class);
    MessageProcessingHandler handler = new MessageProcessingHandler(msgWriter, connection, mock(Log.class));
    // When
    handler.onFinish();
    // Then
    verify(connection).stop();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Log(org.neo4j.logging.Log) Test(org.junit.jupiter.api.Test)

Example 9 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection 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 10 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class HouseKeeperTest method shouldStopConnectionOnChannelInactive.

@Test
void shouldStopConnectionOnChannelInactive() {
    BoltConnection connection = mock(BoltConnection.class);
    channel = new EmbeddedChannel(new HouseKeeper(connection, NullLog.getInstance()));
    channel.pipeline().fireChannelInactive();
    verify(connection).stop();
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Aggregations

BoltConnection (org.neo4j.bolt.runtime.BoltConnection)31 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InetSocketAddress (java.net.InetSocketAddress)3 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)3 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelInboundHandler (io.netty.channel.ChannelInboundHandler)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 ServerSocket (java.net.ServerSocket)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2