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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations