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);
}
use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.
the class TransactionIT method begin__execute__rollback_concurrently.
@ParameterizedTest
@MethodSource("argumentsProvider")
@Timeout(30)
public void begin__execute__rollback_concurrently(String txUri) throws Exception {
this.txUri = txUri;
// begin
final Response begin = POST(txUri);
assertThat(begin.status()).isEqualTo(201);
assertHasTxLocation(begin, txUri);
Label sharedLockLabel = Label.label("sharedLock");
POST(transactionCommitUri(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n:" + sharedLockLabel + ")' } ] }"));
CountDownLatch nodeLockLatch = new CountDownLatch(1);
CountDownLatch nodeReleaseLatch = new CountDownLatch(1);
Future<?> lockerFuture = executors.submit(() -> lockNodeWithLabel(sharedLockLabel, nodeLockLatch, nodeReleaseLatch));
nodeLockLatch.await();
// execute
final String executeResource = begin.location();
final String statement = "MATCH (n:" + sharedLockLabel + ") DELETE n RETURN count(n)";
final Future<Response> executeFuture = executors.submit(() -> {
HTTP.Builder requestBuilder = HTTP.withBaseUri(container().getBaseUri());
Response response = requestBuilder.POST(executeResource, quotedJson("{ 'statements': [ { 'statement': '" + statement + "' } ] }"));
assertThat(response.status()).isEqualTo(200);
return response;
});
// terminate
final Future<Response> interruptFuture = executors.submit(() -> {
waitForStatementExecution(statement);
Response response = DELETE(executeResource);
assertThat(response.status()).as(response.toString()).isEqualTo(200);
nodeReleaseLatch.countDown();
return response;
});
interruptFuture.get();
lockerFuture.get();
Response execute = executeFuture.get();
assertThat(execute).satisfies(hasErrors(Status.Statement.Statement.ExecutionFailed));
Response execute2 = POST(executeResource, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
assertThat(execute2.status()).isEqualTo(404);
assertThat(execute2).satisfies(hasErrors(Status.Transaction.TransactionNotFound));
}
Aggregations