use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerWithQueueTest method shouldNotScheduleNewJobIfHandlingSchedulingError.
@Test
void shouldNotScheduleNewJobIfHandlingSchedulingError() throws Throwable {
AtomicInteger handleSchedulingErrorCounter = new AtomicInteger(0);
AtomicBoolean exitCondition = new AtomicBoolean();
BoltConnection newConnection = newConnection(UUID.randomUUID().toString());
doAnswer(newBlockingAnswer(handleSchedulingErrorCounter, exitCondition)).when(newConnection).handleSchedulingError(any());
submitWork(threadPoolSize + queueSize);
// register connection
boltSchedulerWithQueue.created(newConnection);
// send a job and wait for it to enter handleSchedulingError and block there
CompletableFuture.runAsync(() -> boltSchedulerWithQueue.enqueued(newConnection, Jobs.noop()));
Predicates.awaitForever(() -> handleSchedulingErrorCounter.get() > 0, 500, MILLISECONDS);
// allow all threads to complete
afterExecuteEvent.countDown();
afterExecuteBarrier.await();
// post a job
boltSchedulerWithQueue.enqueued(newConnection, Jobs.noop());
// exit handleSchedulingError
exitCondition.set(true);
// verify that handleSchedulingError is called once and processNextBatch never.
assertEquals(1, handleSchedulingErrorCounter.get());
verify(newConnection, never()).processNextBatch();
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerWithQueueTest method newConnection.
private BoltConnection newConnection(String id) {
BoltConnection result = mock(BoltConnection.class);
when(result.id()).thenReturn(id);
when(result.remoteAddress()).thenReturn(new InetSocketAddress("localhost", 32_000));
return result;
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerTest method createdShouldAddConnectionToActiveConnections.
@Test
void createdShouldAddConnectionToActiveConnections() throws Throwable {
String id = UUID.randomUUID().toString();
BoltConnection connection = newConnection(id);
boltScheduler.init();
boltScheduler.start();
boltScheduler.created(connection);
verify(connection).id();
assertTrue(boltScheduler.isRegistered(connection));
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerTest method destroyedShouldCancelActiveWorkItem.
@Test
void destroyedShouldCancelActiveWorkItem() throws Throwable {
AtomicInteger processNextBatchCount = new AtomicInteger();
String id = UUID.randomUUID().toString();
BoltConnection connection = newConnection(id);
AtomicBoolean exitCondition = new AtomicBoolean();
when(connection.processNextBatch()).thenAnswer(inv -> {
processNextBatchCount.incrementAndGet();
return awaitExit(exitCondition);
});
boltScheduler.init();
boltScheduler.start();
boltScheduler.created(connection);
boltScheduler.enqueued(connection, Jobs.noop());
Predicates.await(() -> processNextBatchCount.get() > 0, 1, MINUTES);
boltScheduler.closed(connection);
Predicates.await(() -> !boltScheduler.isActive(connection), 1, MINUTES);
assertFalse(boltScheduler.isActive(connection));
assertEquals(1, processNextBatchCount.get());
exitCondition.set(true);
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerTest method createdWorkerThreadsShouldContainConnectorName.
@Test
void createdWorkerThreadsShouldContainConnectorName() throws Exception {
AtomicInteger executeBatchCompletionCount = new AtomicInteger();
AtomicReference<Thread> poolThread = new AtomicReference<>();
AtomicReference<String> poolThreadName = new AtomicReference<>();
String id = UUID.randomUUID().toString();
BoltConnection connection = newConnection(id);
when(connection.hasPendingJobs()).thenAnswer(inv -> {
executeBatchCompletionCount.incrementAndGet();
return false;
});
when(connection.processNextBatch()).thenAnswer(inv -> {
poolThread.set(Thread.currentThread());
poolThreadName.set(Thread.currentThread().getName());
return true;
});
boltScheduler.init();
boltScheduler.start();
boltScheduler.created(connection);
boltScheduler.enqueued(connection, Jobs.noop());
Predicates.await(() -> executeBatchCompletionCount.get() > 0, 1, MINUTES);
assertThat(poolThread.get().getName()).isNotEqualTo(poolThreadName.get());
assertThat(poolThread.get().getName()).contains(String.format("[%s]", CONNECTOR_KEY));
assertThat(poolThread.get().getName()).doesNotContain(String.format("[%s]", connection.remoteAddress()));
}
Aggregations