Search in sources :

Example 21 with KernelStatement

use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldNeverDelegateWrites.

@Test
public void shouldNeverDelegateWrites() throws Exception {
    KernelStatement state = mockedState();
    when(state.txState()).thenReturn(new TxState());
    StoreStatement storeStatement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(storeStatement);
    when(inner.indexesGetForLabel(0)).thenReturn(iterator(NewIndexDescriptorFactory.forLabel(0, 0)));
    when(storeStatement.acquireSingleNodeCursor(anyLong())).thenReturn(asNodeCursor(0));
    when(inner.nodeGetProperties(eq(storeStatement), any(NodeItem.class))).thenReturn(asPropertyCursor());
    StateHandlingStatementOperations ctx = newTxStateOps(inner);
    // When
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
    ctx.indexCreate(state, descriptor);
    ctx.nodeAddLabel(state, 0, 0);
    ctx.indexDrop(state, NewIndexDescriptorFactory.forSchema(descriptor));
    ctx.nodeRemoveLabel(state, 0, 0);
    // one for add and one for remove
    verify(storeStatement, times(2)).acquireSingleNodeCursor(0);
    verifyNoMoreInteractions(storeStatement);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 22 with KernelStatement

use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery() 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.indexUpdatesForSeek(index, OrderedPropertyValues.ofUndefined("value"))).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.ExactPredicate query = IndexQuery.exact(index.schema().getPropertyId(), "value");
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // 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)

Example 23 with KernelStatement

use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method indexQueryClosesIndexReader.

@Test
public void indexQueryClosesIndexReader() throws Exception {
    KernelStatement kernelStatement = mock(KernelStatement.class);
    StoreStatement storeStatement = mock(StoreStatement.class);
    IndexReader indexReader = mock(IndexReader.class);
    when(indexReader.query(any())).thenReturn(PrimitiveLongCollections.emptyIterator());
    when(storeStatement.getFreshIndexReader(any())).thenReturn(indexReader);
    when(kernelStatement.getStoreStatement()).thenReturn(storeStatement);
    StateHandlingStatementOperations operations = newTxStateOps(mock(StoreReadLayer.class));
    operations.nodeGetFromUniqueIndexSeek(kernelStatement, NewIndexDescriptorFactory.uniqueForLabel(1, 1), IndexQuery.exact(1, "foo"));
    verify(indexReader).close();
}
Also used : KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 24 with KernelStatement

use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefixWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefixWithIndexQuery() 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.indexUpdatesForRangeSeekByPrefix(index, "prefix")).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.StringPrefixPredicate indexQuery = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
    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)

Example 25 with KernelStatement

use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery.

@SuppressWarnings("unchecked")
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery() throws Exception {
    // Given
    final int propertyKey = 2;
    final int inRange = 15;
    int lower = 10;
    int upper = 20;
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(statement.getStoreStatement()).thenReturn(storageStatement);
    when(txState.indexUpdatesForRangeSeekByNumber(index, lower, true, upper, false)).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);
    when(txState.augmentSingleNodeCursor(any(Cursor.class), anyLong())).thenAnswer(invocationOnMock -> {
        long nodeId = (long) invocationOnMock.getArguments()[1];
        when(txState.augmentSinglePropertyCursor(any(Cursor.class), any(PropertyContainerState.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
        return asNodeCursor(nodeId, nodeId + 20000);
    });
    IndexReader indexReader = addMockedIndexReader(storageStatement);
    IndexQuery.NumberRangePredicate indexQuery = IndexQuery.range(index.schema().getPropertyId(), lower, true, upper, false);
    when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    when(storageStatement.acquireSingleNodeCursor(anyLong())).thenAnswer(invocationOnMock -> {
        long nodeId = (long) invocationOnMock.getArguments()[0];
        when(storeReadLayer.nodeGetProperty(eq(storageStatement), any(NodeItem.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
        return asNodeCursor(nodeId, nodeId + 20000);
    });
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StorageStatement(org.neo4j.storageengine.api.StorageStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) Cursor(org.neo4j.cursor.Cursor) StubCursors.asNodeCursor(org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor) StubCursors.asPropertyCursor(org.neo4j.kernel.impl.api.state.StubCursors.asPropertyCursor) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyContainerState(org.neo4j.storageengine.api.txstate.PropertyContainerState) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Aggregations

KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)28 Test (org.junit.Test)19 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)14 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)13 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)9 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)9 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 NodeItem (org.neo4j.storageengine.api.NodeItem)6 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 StatementOperationParts (org.neo4j.kernel.impl.api.StatementOperationParts)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)3 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2