use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class ConcurrentLuceneFulltextUpdaterTest method raceContestantsAndVerifyResults.
private void raceContestantsAndVerifyResults(Runnable aliceWork, Runnable changeConfig, Runnable bobWork) throws Throwable {
race.addContestants(aliceThreads, aliceWork);
race.addContestant(changeConfig);
race.addContestants(bobThreads, bobWork);
race.go();
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexOnline("nodes", 1, TimeUnit.MINUTES);
}
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = kernelTransaction(tx);
IndexReadSession index = ktx.dataRead().indexReadSession(ktx.schemaRead().indexGetForName("nodes"));
try (NodeValueIndexCursor bobCursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(index, bobCursor, unconstrained(), PropertyIndexQuery.fulltextSearch("bob"));
int bobCount = 0;
while (bobCursor.next()) {
bobCount += 1;
}
assertEquals(bobThreads * nodesCreatedPerThread, bobCount);
}
try (NodeValueIndexCursor aliceCursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(index, aliceCursor, unconstrained(), PropertyIndexQuery.fulltextSearch("alice"));
int aliceCount = 0;
while (aliceCursor.next()) {
aliceCount += 1;
}
assertEquals(0, aliceCount);
}
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInterleavedExact.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInterleavedExact(IndexCoordinator indexCoordinator) throws Exception {
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExact(ktx)) {
List<Long> actual1 = new ArrayList<>();
try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExact(ktx)) {
List<Long> actual2 = new ArrayList<>();
// Interleave
exhaustInterleaved(cursor1, actual1, cursor2, actual2);
// then
indexCoordinator.assertExactResult(actual1);
indexCoordinator.assertExactResult(actual2);
}
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class LuceneFulltextTestSupport method assertQueryFindsIds.
void assertQueryFindsIds(KernelTransaction ktx, boolean nodes, String indexName, String query, long... ids) throws Exception {
IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
MutableLongSet set = LongSets.mutable.of(ids);
if (nodes) {
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(set.remove(nodeId), format("Result returned node id %d, expected one of %s", nodeId, Arrays.toString(ids)));
}
}
} else {
try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().relationshipIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long relationshipId = cursor.relationshipReference();
assertTrue(set.remove(relationshipId), format("Result returned relationship id %d, expected one of %s", relationshipId, Arrays.toString(ids)));
}
}
}
if (!set.isEmpty()) {
fail("Number of results differ from expected. " + set.size() + " IDs were not found in the result: " + set);
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInterleavedRange.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInterleavedRange(IndexCoordinator indexCoordinator) throws Exception {
assumeTrue(indexCoordinator.supportRangeQuery());
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryRange(ktx);
NodeValueIndexCursor cursor2 = indexCoordinator.queryRange(ktx)) {
List<Long> actual1 = new ArrayList<>();
List<Long> actual2 = new ArrayList<>();
// Interleave
exhaustInterleaved(cursor1, actual1, cursor2, actual2);
// then
indexCoordinator.assertRangeResult(actual1);
indexCoordinator.assertRangeResult(actual2);
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInnerNewExact.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInnerNewExact(IndexCoordinator indexCoordinator) throws Exception {
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExact(ktx)) {
List<Long> actual1 = new ArrayList<>();
while (cursor1.next()) {
actual1.add(cursor1.nodeReference());
try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExact(ktx)) {
List<Long> actual2 = asList(cursor2);
indexCoordinator.assertExactResult(actual2);
}
}
// then
indexCoordinator.assertExactResult(actual1);
}
tx.commit();
}
}
Aggregations