Search in sources :

Example 56 with PrimitiveLongIterator

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

the class IndexQueryTransactionStateTest method shouldExcludeExistingNodesWithCorrectPropertyAfterRemovingLabel.

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

Example 57 with PrimitiveLongIterator

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

the class IndexQueryTransactionStateTest method shouldExcludeChangedNodesWithMissingLabelFromIndexQuery.

@Test
public void shouldExcludeChangedNodesWithMissingLabelFromIndexQuery() throws Exception {
    // Given
    when(indexReader.query(withValue)).then(answerAsPrimitiveLongIteratorFrom(asList(2L, 3L)));
    state.txState().nodeDoAddProperty(1L, intProperty(propertyKeyId, 10));
    // When
    PrimitiveLongIterator result = txContext.indexQuery(state, newIndexDescriptor, withValue);
    // Then
    assertThat(PrimitiveLongCollections.toSet(result), equalTo(asSet(2L, 3L)));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Test(org.junit.Test)

Example 58 with PrimitiveLongIterator

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

the class IndexQueryTransactionStateTest method shouldExcludeNodesWithRemovedProperty.

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

Example 59 with PrimitiveLongIterator

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

the class IndexQueryTransactionStateTest method shouldIncludeExistingNodesWithCorrectPropertyAfterAddingLabel.

@Test
public void shouldIncludeExistingNodesWithCorrectPropertyAfterAddingLabel() throws Exception {
    // Given
    when(indexReader.query(withValue)).then(answerAsPrimitiveLongIteratorFrom(asList(2L, 3L)));
    long nodeId = 1L;
    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 60 with PrimitiveLongIterator

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringSuffixPredicate indexQuery = IndexQuery.stringSuffix(index.schema().getPropertyId(), "suffix");
    when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)65 Test (org.junit.Test)50 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)18 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 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 Transaction (org.neo4j.graphdb.Transaction)7 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)6 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 Cursor (org.neo4j.cursor.Cursor)3 ReadOperations (org.neo4j.kernel.api.ReadOperations)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2