use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery() 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.indexUpdatesForRangeSeekByString(index, "Anne", true, "Bill", 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);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery.StringRangePredicate rangePredicate = IndexQuery.range(index.schema().getPropertyId(), "Anne", true, "Bill", false);
when(indexReader.query(rangePredicate)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, rangePredicate);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery() 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.StringContainsPredicate indexQuery = IndexQuery.stringContains(index.schema().getPropertyId(), "contains");
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));
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldNotAddConstraintAlreadyExistsInTheStore.
@Test
public void shouldNotAddConstraintAlreadyExistsInTheStore() throws Exception {
// given
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
TransactionState txState = mock(TransactionState.class);
when(txState.nodesWithLabelChanged(anyInt())).thenReturn(new DiffSets<Long>());
when(txState.hasChanges()).thenReturn(true);
KernelStatement state = mockedState(txState);
when(inner.constraintsGetForSchema(any())).thenReturn(iterator(constraint));
StateHandlingStatementOperations context = newTxStateOps(inner);
// when
context.uniquePropertyConstraintCreate(state, descriptor);
// then
verify(txState).indexDoUnRemove(eq(constraint.ownedIndexDescriptor()));
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldGetConstraintsByLabel.
@Test
public void shouldGetConstraintsByLabel() 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.constraintsGetForLabel(1)).thenAnswer(invocation -> Iterators.emptyIterator());
when(inner.constraintsGetForLabel(2)).thenAnswer(invocation -> iterator(constraint1));
StateHandlingStatementOperations context = newTxStateOps(inner);
context.uniquePropertyConstraintCreate(state, constraint1.ownedIndexDescriptor().schema());
context.uniquePropertyConstraintCreate(state, constraint2.ownedIndexDescriptor().schema());
// when
Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetForLabel(state, 2)));
// then
assertEquals(asSet(constraint1), result);
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class IndexQueryTransactionStateTest method before.
@Before
public void before() throws Exception {
TransactionState txState = new TxState();
state = StatementOperationsTestHelper.mockedState(txState);
store = mock(StoreReadLayer.class);
when(store.indexGetState(newIndexDescriptor)).thenReturn(InternalIndexState.ONLINE);
when(store.indexesGetForLabel(labelId)).then(answerAsIteratorFrom(indexes));
when(store.indexesGetAll()).then(answerAsIteratorFrom(indexes));
when(store.constraintsGetForLabel(labelId)).thenReturn(Collections.emptyIterator());
when(store.indexGetForLabelAndPropertyKey(newIndexDescriptor.schema())).thenReturn(newIndexDescriptor);
statement = mock(StoreStatement.class);
when(state.getStoreStatement()).thenReturn(statement);
indexReader = mock(IndexReader.class);
when(statement.getIndexReader(newIndexDescriptor)).thenReturn(indexReader);
when(statement.getFreshIndexReader(newIndexDescriptor)).thenReturn(indexReader);
StateHandlingStatementOperations stateHandlingOperations = new StateHandlingStatementOperations(store, new InternalAutoIndexing(Config.empty(), null), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
txContext = new ConstraintEnforcingEntityOperations(new StandardConstraintSemantics(), stateHandlingOperations, stateHandlingOperations, stateHandlingOperations, stateHandlingOperations);
}
Aggregations