Search in sources :

Example 76 with MutableLongSet

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

the class RecordNodeCursorIT method shouldProperlyReturnHasLabel.

@RepeatedTest(10)
void shouldProperlyReturnHasLabel() {
    // given/when
    MutableLongSet labels = LongSets.mutable.empty();
    long nodeId = createNodeWithRandomLabels(labels);
    // then
    try (RecordNodeCursor nodeCursor = new RecordNodeCursor(nodeStore, neoStores.getRelationshipStore(), neoStores.getRelationshipGroupStore(), null, NULL)) {
        nodeCursor.single(nodeId);
        assertThat(nodeCursor.next()).isTrue();
        for (int labelId = 0; labelId < HIGH_LABEL_ID; labelId++) {
            boolean fromCursor = nodeCursor.hasLabel(labelId);
            boolean fromSet = labels.contains(labelId);
            assertThat(fromCursor).as("Label " + labelId).isEqualTo(fromSet);
        }
    }
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 77 with MutableLongSet

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

the class SchemaChecker method checkTokens.

private static <R extends TokenRecord> void checkTokens(TokenStore<R> store, Function<R, ConsistencyReport.NameConsistencyReport> report, Function<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> dynamicRecordReport, PageCacheTracer pageCacheTracer) {
    DynamicStringStore nameStore = store.getNameStore();
    DynamicRecord nameRecord = nameStore.newRecord();
    long highId = store.getHighId();
    MutableLongSet seenNameRecordIds = LongSets.mutable.empty();
    int blockSize = store.getNameStore().getRecordDataSize();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_CHECKER_TAG));
        RecordReader<R> tokenReader = new RecordReader<>(store, true, cursorContext);
        RecordReader<DynamicRecord> nameReader = new RecordReader<>(store.getNameStore(), false, cursorContext)) {
        for (long id = 0; id < highId; id++) {
            R record = tokenReader.read(id);
            if (record.inUse() && !NULL_REFERENCE.is(record.getNameId())) {
                safeLoadDynamicRecordChain(r -> {
                }, nameReader, seenNameRecordIds, record.getNameId(), blockSize, (i, r) -> dynamicRecordReport.apply(nameRecord).circularReferenceNext(r), (i, r) -> report.apply(record).nameBlockNotInUse(nameRecord), (i, r) -> dynamicRecordReport.apply(nameRecord).nextNotInUse(r), (i, r) -> dynamicRecordReport.apply(r).emptyBlock(), r -> dynamicRecordReport.apply(r).recordNotFullReferencesNext(), r -> dynamicRecordReport.apply(r).invalidLength());
            }
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 78 with MutableLongSet

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

the class NodeRelationshipCacheTest method shouldVisitChangedNodes.

@Test
public void shouldVisitChangedNodes() {
    // GIVEN
    int nodes = 100;
    int typeId = 10;
    int chunkSize = 10;
    List<Long> changedNodes = new ArrayList<>();
    cache = new NodeRelationshipCache(NumberArrayFactories.HEAP, 2, chunkSize, base, INSTANCE);
    cache.setNodeCount(nodes);
    for (long nodeId = 0; nodeId < nodes; nodeId++) {
        if (nodeId >= chunkSize && nodeId < 2 * chunkSize) {
            // One chunk without any changes
            continue;
        }
        cache.incrementCount(nodeId);
        if (random.nextBoolean()) {
            cache.incrementCount(nodeId);
        }
        changedNodes.add(nodeId);
    }
    MutableLongSet keySparseChanged = new LongHashSet();
    MutableLongSet keyDenseChanged = new LongHashSet();
    for (int i = 0; i < nodes / 2; i++) {
        long nodeId = random.among(changedNodes);
        cache.getAndPutRelationship(nodeId, typeId, Direction.OUTGOING, random.nextLong(1_000_000), false);
        boolean dense = cache.isDense(nodeId);
        (dense ? keyDenseChanged : keySparseChanged).add(nodeId);
    }
    {
        // WHEN (sparse)
        NodeRelationshipCache.NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (sparse)
            assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_SPARSE);
        assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.isEmpty());
    }
    {
        // WHEN (dense)
        NodeRelationshipCache.NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (dense)
            assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_DENSE);
        assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.isEmpty());
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 79 with MutableLongSet

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

the class MutableLongDiffSetsImplTest method useCollectionsFactory.

@Test
void useCollectionsFactory() {
    final MutableLongSet set1 = new LongHashSet();
    final MutableLongSet set2 = new LongHashSet();
    final CollectionsFactory collectionsFactory = mock(CollectionsFactory.class);
    doReturn(set1, set2).when(collectionsFactory).newLongSet(EmptyMemoryTracker.INSTANCE);
    final MutableLongDiffSetsImpl diffSets = new MutableLongDiffSetsImpl(collectionsFactory, EmptyMemoryTracker.INSTANCE);
    diffSets.add(1L);
    diffSets.remove(2L);
    assertSame(set1, diffSets.getAdded());
    assertSame(set2, diffSets.getRemoved());
    verify(collectionsFactory, times(2)).newLongSet(EmptyMemoryTracker.INSTANCE);
    verifyNoMoreInteractions(collectionsFactory);
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) CollectionsFactory(org.neo4j.kernel.impl.util.collection.CollectionsFactory) OnHeapCollectionsFactory(org.neo4j.kernel.impl.util.collection.OnHeapCollectionsFactory) Test(org.junit.jupiter.api.Test)

Example 80 with MutableLongSet

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

the class RelationshipTypeIndexCursorTestBase method shouldFindRelationshipsByTypeInTx.

@ParameterizedTest
@EnumSource(value = IndexOrder.class)
void shouldFindRelationshipsByTypeInTx(IndexOrder order) throws KernelException {
    long inStore;
    long inStore2;
    long deletedInTx;
    long createdInTx;
    long createdInTx2;
    try (KernelTransaction tx = beginTransaction()) {
        inStore = createRelationship(tx.dataWrite(), typeOne);
        createRelationship(tx.dataWrite(), typeTwo);
        deletedInTx = createRelationship(tx.dataWrite(), typeOne);
        inStore2 = createRelationship(tx.dataWrite(), typeOne);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        tx.dataWrite().relationshipDelete(deletedInTx);
        createdInTx = createRelationship(tx.dataWrite(), typeOne);
        createRelationship(tx.dataWrite(), typeTwo);
        createdInTx2 = createRelationship(tx.dataWrite(), typeOne);
        try (RelationshipTypeIndexCursor cursor = tx.cursors().allocateRelationshipTypeIndexCursor(NULL)) {
            MutableLongSet uniqueIds = new LongHashSet();
            // when
            relationshipTypeScan(tx, typeOne, cursor, order);
            // then
            assertRelationships(cursor, uniqueIds, order, inStore, inStore2, createdInTx, createdInTx2);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipTypeIndexCursor(org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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