use of org.neo4j.kernel.api.impl.fulltext.FulltextIndexProceduresUtil.AWAIT_REFRESH in project neo4j by neo4j.
the class FulltextProceduresTest method concurrentPopulationAndUpdatesToAnEventuallyConsistentIndexMustEventuallyResultInCorrectIndexState.
@Test
void concurrentPopulationAndUpdatesToAnEventuallyConsistentIndexMustEventuallyResultInCorrectIndexState() throws Exception {
String oldValue = "red";
String newValue = "green";
// First we create the nodes and relationships with the property value "red".
LongHashSet nodeIds = new LongHashSet();
LongHashSet relIds = new LongHashSet();
generateNodesAndRelationshipsWithProperty(200, nodeIds, relIds, oldValue);
// Then, in two concurrent transactions, we create our indexes AND change all the property values to "green".
CountDownLatch readyLatch = new CountDownLatch(2);
BinaryLatch startLatch = new BinaryLatch();
Runnable createIndexes = () -> {
readyLatch.countDown();
startLatch.await();
try (Transaction tx = db.beginTx()) {
tx.execute(format(NODE_CREATE, DEFAULT_NODE_IDX_NAME, asStrList(LABEL.name()), asStrList(PROP) + EVENTUALLY_CONSISTENT));
tx.execute(format(RELATIONSHIP_CREATE, DEFAULT_REL_IDX_NAME, asStrList(REL.name()), asStrList(PROP) + EVENTUALLY_CONSISTENT));
tx.commit();
}
};
Runnable makeAllEntitiesGreen = () -> {
try (Transaction tx = db.beginTx()) {
// Prepare our transaction state first.
nodeIds.forEach(nodeId -> tx.getNodeById(nodeId).setProperty(PROP, newValue));
relIds.forEach(relId -> tx.getRelationshipById(relId).setProperty(PROP, newValue));
// Okay, NOW we're ready to race!
readyLatch.countDown();
startLatch.await();
tx.commit();
}
};
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<?> future1 = executor.submit(createIndexes);
Future<?> future2 = executor.submit(makeAllEntitiesGreen);
readyLatch.await();
startLatch.release();
// Finally, when everything has settled down, we should see that all of the nodes and relationships are indexed with the value "green".
try {
future1.get();
future2.get();
awaitIndexesOnline();
try (Transaction tx = db.beginTx()) {
tx.execute(AWAIT_REFRESH).close();
}
assertQueryFindsIds(db, true, DEFAULT_NODE_IDX_NAME, newValue, nodeIds);
assertQueryFindsIds(db, false, DEFAULT_REL_IDX_NAME, newValue, relIds);
} finally {
IOUtils.closeAllSilently(executor::shutdown);
}
}
Aggregations