Search in sources :

Example 31 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class FulltextProceduresTestSupport method assertQueryFindsIds.

static void assertQueryFindsIds(GraphDatabaseService db, boolean queryNodes, String index, String query, LongHashSet ids) {
    // Create a defensive copy, because we're going to modify this instance.
    ids = new LongHashSet(ids);
    String queryCall = queryNodes ? QUERY_NODES : QUERY_RELS;
    long[] expectedIds = ids.toArray();
    MutableLongSet actualIds = new LongHashSet();
    try (Transaction tx = db.beginTx()) {
        LongFunction<Entity> getEntity = queryNodes ? tx::getNodeById : tx::getRelationshipById;
        Result result = tx.execute(format(queryCall, index, query));
        Double score = Double.MAX_VALUE;
        while (result.hasNext()) {
            Map<String, Object> entry = result.next();
            long nextId = ((Entity) entry.get(queryNodes ? NODE : RELATIONSHIP)).getId();
            Double nextScore = (Double) entry.get(SCORE);
            assertThat(nextScore).isLessThanOrEqualTo(score);
            score = nextScore;
            actualIds.add(nextId);
            if (!ids.remove(nextId)) {
                String msg = "This id was not expected: " + nextId;
                failQuery(getEntity, index, query, ids, expectedIds, actualIds, msg);
            }
        }
        if (!ids.isEmpty()) {
            String msg = "Not all expected ids were found: " + ids;
            failQuery(getEntity, index, query, ids, expectedIds, actualIds, msg);
        }
        tx.commit();
    }
}
Also used : Entity(org.neo4j.graphdb.Entity) Result(org.neo4j.graphdb.Result) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Transaction(org.neo4j.graphdb.Transaction)

Example 32 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet 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 33 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class ReuseStorageSpaceIT method shouldPrioritizeFreelistWhenConcurrentlyAllocating.

@Test
void shouldPrioritizeFreelistWhenConcurrentlyAllocating() throws Exception {
    DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseInternalSettings.force_small_id_cache, true).build();
    try {
        // given
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        int numNodes = 40_000;
        MutableLongSet nodeIds = createNodes(db, numNodes);
        try (Transaction tx = db.beginTx()) {
            nodeIds.forEach(nodeId -> tx.getNodeById(nodeId).delete());
            tx.commit();
        }
        db.getDependencyResolver().resolveDependency(IdController.class).maintenance();
        // First create 40,000 nodes, then delete them, ensure ID maintenance has run and allocate concurrently
        int numThreads = 4;
        Collection<Callable<MutableLongSet>> allocators = new ArrayList<>();
        for (int i = 0; i < numThreads; i++) {
            allocators.add(() -> createNodes(db, numNodes / numThreads));
        }
        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
        List<Future<MutableLongSet>> results = executor.invokeAll(allocators);
        MutableLongSet reallocatedNodeIds = LongSets.mutable.withInitialCapacity(numNodes);
        for (Future<MutableLongSet> result : results) {
            reallocatedNodeIds.addAll(result.get());
        }
        assertThat(reallocatedNodeIds).as(diff(nodeIds, reallocatedNodeIds)).isEqualTo(nodeIds);
    } finally {
        dbms.shutdown();
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) ExecutorService(java.util.concurrent.ExecutorService) IdController(org.neo4j.internal.id.IdController) Future(java.util.concurrent.Future) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 34 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldPerformExactLookup.

@Test
void shouldPerformExactLookup() throws Exception {
    // given
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(PROP_INDEX_NAME));
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "one"));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, strOne);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "two"));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, strTwo1, strTwo2);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "three"));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, strThree1, strThree2, strThree3);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 1));
        // then
        assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 2));
        // then
        assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 3));
        // then
        assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 6));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, num6);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 12.0));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, num12a, num12b);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, true));
        // then
        assertFoundEntitiesAndNoValue(cursor, uniqueIds, boolTrue);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian, 0, 0)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian_3D, 0, 0, 0)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84, 0, 0)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84_3D, 0, 0, 0)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1989, 3, 24)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1986, 11, 18)));
        // then
        assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 35 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldProvideValuesForPoints.

@Test
void shouldProvideValuesForPoints() throws Exception {
    // given
    assumeTrue(indexParams.indexProvidesSpatialValues());
    int prop = token.propertyKey(EVER_PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(WHAT_EVER_INDEX_NAME));
    assertEquals(IndexValueCapability.YES, index.reference().getCapability().valueCapability(ValueCategory.GEOMETRY));
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unorderedValues(), PropertyIndexQuery.range(prop, Cartesian));
        // then
        assertFoundEntitiesAndValue(cursor, uniqueIds, index.reference().getCapability().valueCapability(ValueCategory.GEOMETRY), true, whateverPoint);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)153 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)57 Test (org.junit.jupiter.api.Test)54 Test (org.junit.Test)49 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)17 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ArrayList (java.util.ArrayList)13 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 LongIterator (org.eclipse.collections.api.iterator.LongIterator)10 LongSet (org.eclipse.collections.api.set.primitive.LongSet)9 Value (org.neo4j.values.storable.Value)8 Map (java.util.Map)7 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)7 Transaction (org.neo4j.graphdb.Transaction)7 Write (org.neo4j.internal.kernel.api.Write)7 NavigableMap (java.util.NavigableMap)6 UnmodifiableMap (org.eclipse.collections.impl.UnmodifiableMap)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)6