use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class DijkstraIncreasingWeightTest method testForLoops.
@Test
@Timeout(5)
void testForLoops() {
/*
*
* (b)
* / \ 0
* 0 0 / \ - 0 - (c1) - 0 -
* \ / \/ / \
* (s) - 1 - (a1) - 1 - (a2) - 1 - (a3) (a4) - 1 - (t)
* \ /
* - 0 - (c2) - 0 -
*
*/
try (Transaction transaction = graphDb.beginTx()) {
Node s = graph.makeNode(transaction, "s");
Node t = graph.makeNode(transaction, "t");
// Blob loop
graph.makeEdge(transaction, "s", "a1", "length", 1);
graph.makeEdge(transaction, "a1", "b", "length", 0);
graph.makeEdge(transaction, "b", "a1", "length", 0);
// Self loop
graph.makeEdge(transaction, "a1", "a2", "length", 1);
graph.makeEdge(transaction, "a2", "a2", "length", 0);
// Diamond loop
graph.makeEdge(transaction, "a2", "a3", "length", 1);
graph.makeEdge(transaction, "a3", "c1", "length", 0);
graph.makeEdge(transaction, "a3", "c2", "length", 0);
graph.makeEdge(transaction, "c1", "a4", "length", 0);
graph.makeEdge(transaction, "c1", "a4", "length", 0);
graph.makeEdge(transaction, "a4", "t", "length", 1);
PathExpander<Double> expander = PathExpanders.allTypesAndDirections();
Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), DEFAULT_EPSILON, PathInterestFactory.all(DEFAULT_EPSILON));
Iterator<WeightedPath> paths = algo.findAllPaths(s, t).iterator();
assertTrue(paths.hasNext(), "Expected at least one path");
assertEquals(6, paths.next().length(), "Expected first path of length 6");
assertTrue(paths.hasNext(), "Expected at least two paths");
assertEquals(6, paths.next().length(), "Expected second path of length 6");
assertFalse(paths.hasNext(), "Expected exactly two paths");
transaction.commit();
}
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class CentralJobSchedulerTest method scheduledTasksThatThrowsPropagateDoNotPropagateExceptionAfterSubsequentExecution.
@Test
@Timeout(60)
void scheduledTasksThatThrowsPropagateDoNotPropagateExceptionAfterSubsequentExecution() throws InterruptedException {
life.start();
RuntimeException boom = new RuntimeException("boom");
AtomicBoolean throwException = new AtomicBoolean();
CountDownLatch startCounter = new CountDownLatch(10);
AtomicBoolean canceled = new AtomicBoolean();
Runnable job = () -> {
try {
if (throwException.compareAndSet(false, true)) {
throw boom;
}
} finally {
startCounter.countDown();
}
};
JobHandle<?> handle = scheduler.scheduleRecurring(Group.INDEX_POPULATION, NOT_MONITORED, job, 1, TimeUnit.MILLISECONDS);
handle.registerCancelListener(() -> canceled.set(true));
startCounter.await();
handle.cancel();
assertTrue(canceled.get());
assertThrows(CancellationException.class, handle::waitTermination);
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class InternalTransactionCommitProcessIT method commitDuringContinuousCheckpointing.
@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void commitDuringContinuousCheckpointing() throws Exception {
final AtomicBoolean done = new AtomicBoolean();
Workers<Runnable> workers = new Workers<>(getClass().getSimpleName());
try {
for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++) {
workers.start(new Runnable() {
private final ThreadLocalRandom random = ThreadLocalRandom.current();
@Override
public void run() {
while (!done.get()) {
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
randomSleep();
}
}
private void randomSleep() {
try {
Thread.sleep(random.nextInt(50));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
Thread.sleep(SECONDS.toMillis(2));
} finally {
done.set(true);
}
workers.awaitAndThrowOnError();
assertThat(countsStore.txId()).as("Count store should be rotated once at least").isGreaterThan(0L);
long lastRotationTx = checkPointer.forceCheckPoint(new SimpleTriggerInfo("test"));
assertEquals(transactionIdStore.getLastClosedTransactionId(), lastRotationTx, "NeoStore last closed transaction id should be equal last count store rotation transaction id.");
assertEquals(transactionIdStore.getLastClosedTransactionId(), countsStore.txId(), "Last closed transaction should be last rotated tx in count store");
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class KernelTransactionTimeoutMonitorIT method terminatingTransactionMustEagerlyReleaseTheirLocks.
@Test
@Timeout(30)
void terminatingTransactionMustEagerlyReleaseTheirLocks() throws Exception {
AtomicBoolean nodeLockAcquired = new AtomicBoolean();
AtomicBoolean lockerDone = new AtomicBoolean();
BinaryLatch lockerPause = new BinaryLatch();
long nodeId;
try (Transaction tx = database.beginTx()) {
nodeId = tx.createNode().getId();
tx.commit();
}
Future<?> locker = executor.submit(() -> {
try (Transaction tx = database.beginTx()) {
Node node = tx.getNodeById(nodeId);
tx.acquireReadLock(node);
nodeLockAcquired.set(true);
lockerPause.await();
}
lockerDone.set(true);
});
boolean proceed;
do {
proceed = nodeLockAcquired.get();
} while (!proceed);
terminateOngoingTransaction();
// but the thread should still be blocked on the latch
assertFalse(lockerDone.get());
// Yet we should be able to proceed and grab the locks they once held
try (Transaction tx = database.beginTx()) {
// Write-locking is only possible if their shared lock was released
tx.acquireWriteLock(tx.getNodeById(nodeId));
tx.commit();
}
// No exception from our lock client being stopped (e.g. we ended up blocked for too long) or from timeout
lockerPause.release();
locker.get();
assertTrue(lockerDone.get());
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class RecordStorageEngineTest method shutdownRecordStorageEngineAfterFailedTransaction.
@Test
@Timeout(30)
void shutdownRecordStorageEngineAfterFailedTransaction() throws Exception {
RecordStorageEngine engine = buildRecordStorageEngine();
Exception applicationError = executeFailingTransaction(engine);
assertNotNull(applicationError);
}
Aggregations