Search in sources :

Example 11 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class RelationshipChangesForNodeTest method shouldGetRelationshipsByTypeAndDirection.

@Test
void shouldGetRelationshipsByTypeAndDirection() {
    RelationshipChangesForNode changes = createRelationshipChangesForNode(ADD, INSTANCE);
    final int TYPE = 2;
    final int DECOY_TYPE = 666;
    changes.addRelationship(1, TYPE, INCOMING);
    changes.addRelationship(2, TYPE, OUTGOING);
    changes.addRelationship(3, TYPE, OUTGOING);
    changes.addRelationship(4, TYPE, LOOP);
    changes.addRelationship(5, TYPE, LOOP);
    changes.addRelationship(6, TYPE, LOOP);
    changes.addRelationship(10, DECOY_TYPE, INCOMING);
    changes.addRelationship(11, DECOY_TYPE, OUTGOING);
    changes.addRelationship(12, DECOY_TYPE, LOOP);
    LongIterator rawIncoming = changes.getRelationships(Direction.INCOMING, TYPE);
    assertThat(asArray(rawIncoming)).containsExactly(1, 4, 5, 6);
    LongIterator rawOutgoing = changes.getRelationships(Direction.OUTGOING, TYPE);
    assertThat(asArray(rawOutgoing)).containsExactly(2, 3, 4, 5, 6);
}
Also used : RelationshipChangesForNode.createRelationshipChangesForNode(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.jupiter.api.Test)

Example 12 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class RelationshipChangesForNodeTest method shouldGetRelationships.

@Test
void shouldGetRelationships() {
    RelationshipChangesForNode changes = createRelationshipChangesForNode(ADD, INSTANCE);
    final int TYPE = 2;
    changes.addRelationship(1, TYPE, INCOMING);
    changes.addRelationship(2, TYPE, OUTGOING);
    changes.addRelationship(3, TYPE, OUTGOING);
    changes.addRelationship(4, TYPE, LOOP);
    changes.addRelationship(5, TYPE, LOOP);
    changes.addRelationship(6, TYPE, LOOP);
    LongIterator rawRelationships = changes.getRelationships();
    assertThat(asArray(rawRelationships)).containsExactly(1, 2, 3, 4, 5, 6);
}
Also used : RelationshipChangesForNode.createRelationshipChangesForNode(org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.jupiter.api.Test)

Example 13 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class IndexSamplingController method recoverIndexSamples.

public void recoverIndexSamples() {
    samplingLock.lock();
    try {
        IndexMap indexMap = indexMapSnapshotProvider.indexMapSnapshot();
        final LongIterator indexIds = indexMap.indexIds();
        List<IndexSamplingJobHandle> asyncSamplingJobs = Lists.mutable.of();
        while (indexIds.hasNext()) {
            long indexId = indexIds.next();
            IndexDescriptor descriptor = indexMap.getIndexProxy(indexId).getDescriptor();
            if (indexRecoveryCondition.test(descriptor) && descriptor.getIndexType() != IndexType.LOOKUP) {
                if (logRecoverIndexSamples) {
                    log.info("Index requires sampling, id=%d, name=%s.", indexId, descriptor.getName());
                }
                if (asyncRecoverIndexSamples) {
                    asyncSamplingJobs.add(sampleIndexOnTracker(indexMap, indexId));
                } else {
                    sampleIndexOnCurrentThread(indexMap, indexId);
                }
            } else {
                if (logRecoverIndexSamples) {
                    log.info("Index does not require sampling, id=%d, name=%s.", indexId, descriptor.getName());
                }
            }
        }
        if (asyncRecoverIndexSamplesWait) {
            waitForAsyncIndexSamples(asyncSamplingJobs);
        }
    } finally {
        samplingLock.unlock();
    }
}
Also used : IndexMap(org.neo4j.kernel.impl.api.index.IndexMap) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) LongIterator(org.eclipse.collections.api.iterator.LongIterator)

Example 14 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class PrimitiveLongCollectionsTest method shouldNotContinueToCallNextOnHasNextFalse.

@Test
void shouldNotContinueToCallNextOnHasNextFalse() {
    // GIVEN
    AtomicLong count = new AtomicLong(2);
    LongIterator iterator = new AbstractPrimitiveLongBaseIterator() {

        @Override
        protected boolean fetchNext() {
            return count.decrementAndGet() >= 0 && next(count.get());
        }
    };
    // WHEN/THEN
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(1L, iterator.next());
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(0L, iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
    assertEquals(-1L, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongIterator(org.eclipse.collections.api.iterator.LongIterator) AbstractPrimitiveLongBaseIterator(org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator) Test(org.junit.jupiter.api.Test)

Example 15 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class PrimitiveLongCollectionsTest method reverseArrayOfItemsAsIterator.

@Test
void reverseArrayOfItemsAsIterator() {
    // GIVEN
    long[] items = new long[] { 2, 5, 234 };
    // WHEN
    LongIterator iterator = PrimitiveLongCollections.reverseIterator(items);
    // THEN
    assertItems(iterator, 234, 5, 2);
}
Also used : LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.jupiter.api.Test)

Aggregations

LongIterator (org.eclipse.collections.api.iterator.LongIterator)45 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)9 MutableLongIterator (org.eclipse.collections.api.iterator.MutableLongIterator)5 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)4 LongSet (org.eclipse.collections.api.set.primitive.LongSet)3 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)3 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)2 LongIterable (org.eclipse.collections.api.LongIterable)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 RelationshipChangesForNode.createRelationshipChangesForNode (org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode)2 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1 ImmutableEmptyLongIterator (org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator)1 AbstractPrimitiveLongBaseIterator (org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator)1 RangeLongIterator (org.neo4j.collection.RangeLongIterator)1