Search in sources :

Example 1 with PrimitiveLongSet

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

the class IndexingAcceptanceTest method shouldSupportIndexSeekByPrefix.

@Test
public void shouldSupportIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias", "Mats", "Carla");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl", "Karlsson");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations ops = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(ops, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(ops.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 2 with PrimitiveLongSet

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

the class IndexingAcceptanceTest method shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix.

@Test
public void shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias");
    PrimitiveLongSet toDelete = createNodes(db, LABEL1, "name", "Karlsson", "Mats");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        PrimitiveLongIterator deleting = toDelete.iterator();
        while (deleting.hasNext()) {
            long id = deleting.next();
            db.getNodeById(id).delete();
            expected.remove(id);
        }
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 3 with PrimitiveLongSet

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

the class InconsistencyReportReaderTest method shouldReadBasicEntities.

@Test
public void shouldReadBasicEntities() throws Exception {
    // GIVEN
    ByteArrayOutputStream out = new ByteArrayOutputStream(1_000);
    FormattedLog log = FormattedLog.toOutputStream(out);
    InconsistencyMessageLogger logger = new InconsistencyMessageLogger(log);
    long nodeId = 5;
    long relationshipGroupId = 10;
    long relationshipId = 15;
    long propertyId = 20;
    logger.error(RecordType.NODE, new NodeRecord(nodeId), "Some error", "something");
    logger.error(RecordType.RELATIONSHIP, new RelationshipRecord(relationshipId), "Some error", "something");
    logger.error(RecordType.RELATIONSHIP_GROUP, new RelationshipGroupRecord(relationshipGroupId), "Some error", "something");
    logger.error(RecordType.PROPERTY, new PropertyRecord(propertyId), "Some error", "something");
    String text = out.toString();
    PrimitiveLongSet nodes = Primitive.longSet();
    PrimitiveLongSet relationships = Primitive.longSet();
    PrimitiveLongSet relationshipGroups = Primitive.longSet();
    PrimitiveLongSet properties = Primitive.longSet();
    // WHEN
    InconsistencyReportReader reader = new InconsistencyReportReader(new Inconsistencies() {

        @Override
        public void relationshipGroup(long id) {
            relationshipGroups.add(id);
        }

        @Override
        public void relationship(long id) {
            relationships.add(id);
        }

        @Override
        public void property(long id) {
            properties.add(id);
        }

        @Override
        public void node(long id) {
            nodes.add(id);
        }
    });
    reader.read(new StringReader(text));
    // THEN
    assertEquals(asSet(iterator(nodeId)), nodes);
    assertEquals(asSet(iterator(relationshipId)), relationships);
    assertEquals(asSet(iterator(relationshipGroupId)), relationshipGroups);
    assertEquals(asSet(iterator(propertyId)), properties);
}
Also used : FormattedLog(org.neo4j.logging.FormattedLog) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Inconsistencies(org.neo4j.tools.dump.InconsistencyReportReader.Inconsistencies) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) StringReader(java.io.StringReader) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger) Test(org.junit.Test)

Example 4 with PrimitiveLongSet

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

the class PrimitiveLongSetTest method shouldContainAddedValues_generated_1.

@Test
public void shouldContainAddedValues_generated_1() throws Exception {
    // GIVEN
    PrimitiveLongSet set = newSet(15);
    Set<Long> expectedValues = new HashSet<>();
    long[] valuesToAdd = new long[] { 1207043189, 380713862, 1902858197, 1996873101, 1357024628, 1044248801, 1558157493, 2040311008, 2017660098, 1332670047, 663662790, 2063747422, 1554358949, 1761477445, 1141526838, 1698679618, 1279767067, 508574, 2071755904 };
    for (long key : valuesToAdd) {
        set.add(key);
        expectedValues.add(key);
    }
    // WHEN/THEN
    boolean existedBefore = set.contains(679990875);
    boolean added = set.add(679990875);
    boolean existsAfter = set.contains(679990875);
    assertFalse("679990875 should not exist before adding here", existedBefore);
    assertTrue("679990875 should be reported as added here", added);
    assertTrue("679990875 should exist", existsAfter);
    expectedValues.add(679990875L);
    final Set<Long> visitedKeys = new HashSet<>();
    set.visitKeys(new PrimitiveLongVisitor() {

        @Override
        public boolean visited(long value) {
            assertTrue(visitedKeys.add(value));
            return false;
        }
    });
    assertEquals(expectedValues, visitedKeys);
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) PrimitiveLongVisitor(org.neo4j.collection.primitive.PrimitiveLongVisitor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with PrimitiveLongSet

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

the class PrimitiveLongSetTest method shouldHandleEmptySet.

@Test
public void shouldHandleEmptySet() throws Exception {
    // GIVEN
    PrimitiveLongSet set = Primitive.longSet(0);
    // THEN
    assertFalse(set.contains(564));
}
Also used : 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