Search in sources :

Example 1 with NodeValueIndexCursor

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 2 with NodeValueIndexCursor

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();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with NodeValueIndexCursor

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);
    }
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 4 with NodeValueIndexCursor

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();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with NodeValueIndexCursor

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();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)42 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)20 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)20 Test (org.junit.jupiter.api.Test)18 Transaction (org.neo4j.graphdb.Transaction)16 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)16 ArrayList (java.util.ArrayList)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 TokenRead (org.neo4j.internal.kernel.api.TokenRead)7 Read (org.neo4j.internal.kernel.api.Read)6 Value (org.neo4j.values.storable.Value)6 KernelException (org.neo4j.exceptions.KernelException)3 Node (org.neo4j.graphdb.Node)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Label (org.neo4j.graphdb.Label)2 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)2 NodeIndexCursor (org.neo4j.internal.kernel.api.NodeIndexCursor)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2