use of org.neo4j.kernel.api.impl.fulltext.FulltextIndexProceduresUtil.RELATIONSHIP_CREATE 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);
}
}
use of org.neo4j.kernel.api.impl.fulltext.FulltextIndexProceduresUtil.RELATIONSHIP_CREATE in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes.
@Test
void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception {
GraphDatabaseService db = createDatabase();
Label[] labels = IntStream.range(1, 7).mapToObj(i -> Label.label("LABEL" + i)).toArray(Label[]::new);
RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i -> RelationshipType.withName("REL" + i)).toArray(RelationshipType[]::new);
String[] propertyKeys = IntStream.range(1, 7).mapToObj(i -> "PROP" + i).toArray(String[]::new);
RandomValues randomValues = random.randomValues();
try (Transaction tx = db.beginTx()) {
int nodeCount = 1000;
List<Node> nodes = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
Label[] nodeLabels = random.ints(random.nextInt(labels.length), 0, labels.length).distinct().mapToObj(x -> labels[x]).toArray(Label[]::new);
Node node = tx.createNode(nodeLabels);
Stream.of(propertyKeys).forEach(p -> node.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject()));
nodes.add(node);
int localRelCount = Math.min(nodes.size(), 5);
random.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x -> node.createRelationshipTo(nodes.get(x), relTypes[random.nextInt(relTypes.length)])).forEach(r -> Stream.of(propertyKeys).forEach(p -> r.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject())));
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 1; i < labels.length; i++) {
tx.execute(format(NODE_CREATE, "nodes" + i, asStrList(Arrays.stream(labels).limit(i).map(Label::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
for (int i = 1; i < relTypes.length; i++) {
tx.execute(format(RELATIONSHIP_CREATE, "rels" + i, asStrList(Arrays.stream(relTypes).limit(i).map(RelationshipType::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
tx.commit();
}
managementService.shutdown();
assertIsConsistent(checkConsistency());
}
Aggregations