Search in sources :

Example 1 with PrimitiveLongIterator

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

the class IndexQueryTransactionStateTest method shouldIncludeCreatedNodesWithCorrectLabelAndProperty.

@Test
public void shouldIncludeCreatedNodesWithCorrectLabelAndProperty() throws Exception {
    // Given
    when(indexReader.query(withValue)).then(answerAsPrimitiveLongIteratorFrom(asList(2L, 3L)));
    long nodeId = 1L;
    state.txState().nodeDoAddProperty(nodeId, stringProperty(propertyKeyId, value));
    when(statement.acquireSingleNodeCursor(nodeId)).thenReturn(asNodeCursor(nodeId, 40L));
    mockStoreProperty();
    when(store.indexesGetForLabel(labelId)).thenReturn(indexes.iterator());
    txContext.nodeAddLabel(state, nodeId, labelId);
    // When
    PrimitiveLongIterator result = txContext.indexQuery(state, newIndexDescriptor, withValue);
    // Then
    assertThat(PrimitiveLongCollections.toSet(result), equalTo(asSet(nodeId, 2L, 3L)));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Test(org.junit.Test)

Example 2 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator 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 PrimitiveLongIterator

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

the class CompositeIndexingIT method shouldSeeAllNodesAddedBeforeTransaction.

@Test
public void shouldSeeAllNodesAddedBeforeTransaction() throws Exception {
    if (// this test does not make any sense for UNIQUE indexes
    index.type() != UNIQUE) {
        long nodeID1 = createNode();
        long nodeID2 = createNode();
        long nodeID3 = createNode();
        try (Transaction ignore = graphDatabaseAPI.beginTx()) {
            PrimitiveLongIterator resultIterator = seek();
            Set<Long> result = PrimitiveLongCollections.toSet(resultIterator);
            assertThat(result, contains(nodeID1, nodeID2, nodeID3));
        }
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 4 with PrimitiveLongIterator

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

the class CompositeIndexingIT method shouldSeeNodeAddedToByLabelIndexInTransaction.

@Test
public void shouldSeeNodeAddedToByLabelIndexInTransaction() throws Exception {
    try (Transaction ignore = graphDatabaseAPI.beginTx()) {
        DataWriteOperations writeOperations = statement().dataWriteOperations();
        long nodeID = writeOperations.nodeCreate();
        for (int propID : index.schema().getPropertyIds()) {
            writeOperations.nodeSetProperty(nodeID, DefinedProperty.intProperty(propID, propID));
        }
        writeOperations.nodeAddLabel(nodeID, LABEL_ID);
        PrimitiveLongIterator resultIterator = seek();
        assertThat(resultIterator.next(), equalTo(nodeID));
        assertFalse(resultIterator.hasNext());
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 5 with PrimitiveLongIterator

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

the class HopScotchHashingAlgorithmTest method shouldSupportIteratingThroughResize.

@Test
public void shouldSupportIteratingThroughResize() throws Exception {
    // GIVEN
    int threshold = figureOutGrowthThreshold();
    TableGrowthAwareMonitor monitor = new TableGrowthAwareMonitor();
    PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor);
    Set<Long> added = new HashSet<>();
    for (int i = 0; i < threshold - 1; i++) {
        long value = i * 3;
        set.add(value);
        added.add(value);
    }
    // WHEN
    PrimitiveLongIterator iterator = set.iterator();
    Set<Long> iterated = new HashSet<>();
    for (int i = 0; i < threshold / 2; i++) {
        iterated.add(iterator.next());
    }
    assertFalse(monitor.checkAndReset());
    // will push it over the edge, to grow the table
    set.add((threshold - 1) * 3);
    assertTrue(monitor.checkAndReset());
    while (iterator.hasNext()) {
        iterated.add(iterator.next());
    }
    // THEN
    assertEquals(added, iterated);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)68 Test (org.junit.Test)47 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)15 Transaction (org.neo4j.graphdb.Transaction)10 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)10 ReadOperations (org.neo4j.kernel.api.ReadOperations)8 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)8 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Node (org.neo4j.graphdb.Node)4 Statement (org.neo4j.kernel.api.Statement)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 ArrayList (java.util.ArrayList)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2