use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class LabelsAcceptanceTest method shouldListAllRelationshipTypesInUseEvenWhenExclusiveRelationshipTypeLocksAreTaken.
@Test
void shouldListAllRelationshipTypesInUseEvenWhenExclusiveRelationshipTypeLocksAreTaken() {
assertTimeoutPreemptively(Duration.ofSeconds(30), () -> {
// Given
RelationshipType relType = RelationshipType.withName("REL");
Node node = createNode(db, Labels.MY_LABEL);
try (Transaction tx = db.beginTx()) {
tx.getNodeById(node.getId()).createRelationshipTo(node, relType).setProperty("prop", "val");
tx.commit();
}
BinaryLatch indexCreateStarted = new BinaryLatch();
BinaryLatch indexCreateAllowToFinish = new BinaryLatch();
Thread indexCreator = new Thread(() -> {
try (Transaction tx = db.beginTx()) {
tx.execute("CREATE FULLTEXT INDEX myIndex FOR ()-[r:REL]-() ON EACH [r.prop]").close();
indexCreateStarted.release();
indexCreateAllowToFinish.await();
tx.commit();
}
});
indexCreator.start();
// When
indexCreateStarted.await();
List<RelationshipType> relTypes;
try (Transaction transaction = db.beginTx()) {
relTypes = asList(transaction.getAllRelationshipTypesInUse());
}
indexCreateAllowToFinish.release();
indexCreator.join();
// Then
assertEquals(1, relTypes.size());
assertThat(map(RelationshipType::name, relTypes)).contains(relType.name());
});
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class EventuallyConsistentFulltextProceduresTest method fulltextIndexesMustBeEventuallyConsistentByDefaultWhenThisIsConfigured.
@Test
void fulltextIndexesMustBeEventuallyConsistentByDefaultWhenThisIsConfigured() throws InterruptedException {
try (Transaction tx = db.beginTx()) {
tx.execute(format(NODE_CREATE, DEFAULT_NODE_IDX_NAME, asStrList(LABEL.name()), asStrList(PROP, "otherprop")));
tx.execute(format(RELATIONSHIP_CREATE, DEFAULT_REL_IDX_NAME, asStrList(REL.name()), asStrList(PROP)));
tx.commit();
}
awaitIndexesOnline();
// Prevent index updates from being applied to eventually consistent indexes.
BinaryLatch indexUpdateBlocker = new BinaryLatch();
db.getDependencyResolver().resolveDependency(JobScheduler.class).schedule(Group.INDEX_UPDATING, NOT_MONITORED, indexUpdateBlocker::await);
LongHashSet nodeIds = new LongHashSet();
long relId;
try {
try (Transaction tx = db.beginTx()) {
Node node1 = tx.createNode(LABEL);
node1.setProperty(PROP, "bla bla");
Node node2 = tx.createNode(LABEL);
node2.setProperty("otherprop", "bla bla");
Relationship relationship = node1.createRelationshipTo(node2, REL);
relationship.setProperty(PROP, "bla bla");
nodeIds.add(node1.getId());
nodeIds.add(node2.getId());
relId = relationship.getId();
tx.commit();
}
// Index updates are still blocked for eventually consistent indexes, so we should not find anything at this point.
assertQueryFindsIdsInOrder(db, true, DEFAULT_NODE_IDX_NAME, "bla");
assertQueryFindsIdsInOrder(db, false, DEFAULT_REL_IDX_NAME, "bla");
} finally {
// Uncork the eventually consistent fulltext index updates.
Thread.sleep(10);
indexUpdateBlocker.release();
}
// And wait for them to apply.
try (Transaction transaction = db.beginTx()) {
transaction.execute(AWAIT_REFRESH).close();
transaction.commit();
}
// Now we should see our data.
assertQueryFindsIds(db, true, DEFAULT_NODE_IDX_NAME, "bla", nodeIds);
assertQueryFindsIds(db, false, DEFAULT_REL_IDX_NAME, "bla", newSetWith(relId));
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class TimeBasedTaskSchedulerTest method longRunningTasksMustNotDelayExecutionOfOtherTasks.
@Test
void longRunningTasksMustNotDelayExecutionOfOtherTasks() throws Exception {
BinaryLatch latch = new BinaryLatch();
Runnable longRunning = latch::await;
Runnable shortRunning = semaphore::release;
scheduler.submit(Group.STORAGE_MAINTENANCE, longRunning, 100, 100);
scheduler.submit(Group.STORAGE_MAINTENANCE, shortRunning, 100, 100);
for (int i = 0; i < 4; i++) {
clock.forward(100, TimeUnit.NANOSECONDS);
scheduler.tick();
assertSemaphoreAcquire();
}
latch.release();
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class CentralJobSchedulerTest method shutDownMustKillCancelledJobs.
@Test
@Timeout(value = 60)
void shutDownMustKillCancelledJobs() {
life.start();
BinaryLatch startLatch = new BinaryLatch();
BinaryLatch stopLatch = new BinaryLatch();
scheduler.schedule(Group.INDEX_POPULATION, NOT_MONITORED, () -> {
try {
startLatch.release();
Thread.sleep(100_000);
} catch (InterruptedException e) {
stopLatch.release();
throw new RuntimeException(e);
}
});
startLatch.await();
scheduler.shutdown();
stopLatch.await();
}
use of org.neo4j.util.concurrent.BinaryLatch in project neo4j by neo4j.
the class CentralJobSchedulerTest method scheduledTasksThatThrowsShouldStop.
@Test
@Timeout(value = 60)
void scheduledTasksThatThrowsShouldStop() {
life.start();
BinaryLatch triggerLatch = new BinaryLatch();
AtomicBoolean canceled = new AtomicBoolean();
RuntimeException boom = new RuntimeException("boom");
AtomicInteger triggerCounter = new AtomicInteger();
Runnable job = () -> {
try {
triggerCounter.incrementAndGet();
throw boom;
} finally {
triggerLatch.release();
}
};
JobHandle<?> jobHandle = scheduler.scheduleRecurring(Group.INDEX_POPULATION, NOT_MONITORED, job, 1, MILLISECONDS);
jobHandle.registerCancelListener(() -> canceled.set(true));
triggerLatch.await();
assertThat(triggerCounter.get()).isGreaterThanOrEqualTo(1);
assertFalse(canceled.get());
jobHandle.cancel();
assertTrue(canceled.get());
}
Aggregations