Search in sources :

Example 26 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class BadCollectorTest method shouldBeAbleToRetrieveDuplicateNodeIds.

@Test
public void shouldBeAbleToRetrieveDuplicateNodeIds() throws IOException {
    // given
    int tolerance = 15;
    BadCollector badCollector = new BadCollector(badOutputFile(), tolerance, BadCollector.COLLECT_ALL);
    // when
    for (int i = 0; i < 15; i++) {
        badCollector.collectDuplicateNode(i, i, "group", "source" + i, "otherSource" + i);
    }
    // then
    assertEquals(15, PrimitiveLongCollections.count(badCollector.leftOverDuplicateNodesIds()));
    PrimitiveLongSet longs = PrimitiveLongCollections.asSet(badCollector.leftOverDuplicateNodesIds());
    for (int i = 0; i < 15; i++) {
        assertTrue(longs.contains(i));
    }
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 27 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class NodeRelationshipCacheTest method shouldVisitChangedNodes.

@Test
public void shouldVisitChangedNodes() throws Exception {
    // GIVEN
    int nodes = 10;
    cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 2, 100, base);
    cache.setHighNodeId(nodes);
    for (long nodeId = 0; nodeId < nodes; nodeId++) {
        cache.incrementCount(nodeId);
        if (random.nextBoolean()) {
            cache.incrementCount(nodeId);
        }
    }
    PrimitiveLongSet keySparseChanged = Primitive.longSet(nodes);
    PrimitiveLongSet keyDenseChanged = Primitive.longSet(nodes);
    for (int i = 0; i < nodes / 2; i++) {
        long nodeId = random.nextLong(nodes);
        cache.getAndPutRelationship(nodeId, Direction.OUTGOING, random.nextLong(1_000_000), false);
        boolean dense = cache.isDense(nodeId);
        (dense ? keyDenseChanged : keySparseChanged).add(nodeId);
    }
    {
        // WHEN (sparse)
        NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (sparse)
            assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, false);
        assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.isEmpty());
    }
    {
        // WHEN (dense)
        NodeChangeVisitor visitor = (nodeId, array) -> {
            // THEN (dense)
            assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId));
        };
        cache.visitChangedNodes(visitor, true);
        assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.isEmpty());
    }
}
Also used : NodeChangeVisitor(org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache.NodeChangeVisitor) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 28 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedIndexReaderTest method rangeSeekByPrefixOverPartitions.

@Test
public void rangeSeekByPrefixOverPartitions() throws Exception {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    IndexQuery.StringPrefixPredicate query = IndexQuery.stringPrefix(1, "prefix");
    when(indexReader1.query(query)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.query(query)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.query(query)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet results = PrimitiveLongCollections.asSet(indexReader.query(query));
    verifyResult(results);
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 29 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedIndexReaderTest method rangeSeekByNumberOverPartitions.

@Test
public void rangeSeekByNumberOverPartitions() throws Exception {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    IndexQuery.NumberRangePredicate query = IndexQuery.range(1, 1, true, 2, true);
    when(indexReader1.query(query)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.query(query)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.query(query)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet results = PrimitiveLongCollections.asSet(indexReader.query(query));
    verifyResult(results);
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 30 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedIndexReaderTest method scanOverPartitions.

@Test
public void scanOverPartitions() throws Exception {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    IndexQuery.ExistsPredicate query = IndexQuery.exists(1);
    when(indexReader1.query(query)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.query(query)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.query(query)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet results = PrimitiveLongCollections.asSet(indexReader.query(query));
    verifyResult(results);
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Aggregations

PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)36 Test (org.junit.Test)27 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)5 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)5 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IOException (java.io.IOException)3 CCVar (apoc.algo.wcc.CCVar)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CCResult (apoc.result.CCResult)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 java.util (java.util)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1