Search in sources :

Example 11 with StateHandlingStatementOperations

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

the class SchemaTransactionStateTest method before.

@Before
public void before() throws Exception {
    txState = new TxState();
    state = StatementOperationsTestHelper.mockedState(txState);
    store = mock(StoreReadLayer.class);
    when(store.indexesGetForLabel(labelId1)).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    when(store.indexesGetForLabel(labelId2)).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    when(store.indexesGetAll()).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    txContext = new StateHandlingStatementOperations(store, mock(InternalAutoIndexing.class), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
    storeStatement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(storeStatement);
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Before(org.junit.Before)

Example 12 with StateHandlingStatementOperations

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

the class StateHandlingStatementOperationsTest method shouldGetAllConstraints.

@Test
public void shouldGetAllConstraints() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(2, 3);
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(4, 5);
    TransactionState txState = new TxState();
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForSchema(constraint1.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetForSchema(constraint2.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetAll()).thenAnswer(invocation -> iterator(constraint2));
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquePropertyConstraintCreate(state, constraint1.schema());
    context.uniquePropertyConstraintCreate(state, constraint2.schema());
    // when
    Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetAll(state)));
    // then
    assertEquals(asSet(constraint1, constraint2), result);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 13 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations 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)

Example 14 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations 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 15 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations 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)

Aggregations

StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)18 Test (org.junit.Test)14 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)14 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)13 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)12 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)10 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 StoreStatement (org.neo4j.kernel.impl.api.store.StoreStatement)5 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)4 Before (org.junit.Before)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 ConstraintEnforcingEntityOperations (org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 Matchers.anyLong (org.mockito.Matchers.anyLong)1 Cursor (org.neo4j.cursor.Cursor)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 DataIntegrityValidatingStatementOperations (org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations)1 GuardingStatementOperations (org.neo4j.kernel.impl.api.GuardingStatementOperations)1