use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.
@Test
public void shouldCreateIndexInAnotherTransaction() throws Exception {
// given
StatementOperationParts constraintCreationContext = mockedParts();
StatementOperationParts indexCreationContext = mockedParts();
KernelStatement state = mockedState();
IndexingService indexingService = mock(IndexingService.class);
StubKernel kernel = new StubKernel();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
long indexId = creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
// then
assertEquals(2468L, indexId);
assertEquals(1, kernel.statements.size());
verify(kernel.statements.get(0).txState()).indexRuleDoAdd(eq(index));
verifyNoMoreInteractions(indexCreationContext.schemaWriteOperations());
verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
verify(indexProxy).awaitStoreScanCompleted();
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.
@Test
public void shouldDropIndexIfPopulationFails() throws Exception {
// given
StatementOperationParts constraintCreationContext = mockedParts();
KernelStatement state = mockedState();
IndexingService indexingService = mock(IndexingService.class);
StubKernel kernel = new StubKernel();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, "a");
doThrow(new IndexPopulationFailedKernelException(SchemaBoundary.map(descriptor), "some index", cause)).when(indexProxy).awaitStoreScanCompleted();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
try {
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
fail("expected exception");
}// then
catch (UniquePropertyValueValidationException e) {
assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) ASSERT label[123].property[456] IS UNIQUE.", e.getMessage());
}
assertEquals(2, kernel.statements.size());
TransactionState tx1 = kernel.statements.get(0).txState();
NewIndexDescriptor newIndex = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
verify(tx1).indexRuleDoAdd(newIndex);
verifyNoMoreInteractions(tx1);
verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
TransactionState tx2 = kernel.statements.get(1).txState();
verify(tx2).indexDoDrop(newIndex);
verifyNoMoreInteractions(tx2);
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexScanWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexScanWithIndexQuery() 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 query = IndexQuery.exists(index.schema().getPropertyId());
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));
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix() 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 query = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
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));
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class StorageLayerTest method before.
@SuppressWarnings("deprecation")
@Before
public void before() {
db = (GraphDatabaseAPI) createGraphDatabase();
DependencyResolver resolver = db.getDependencyResolver();
this.disk = resolver.resolveDependency(StorageEngine.class).storeReadLayer();
this.state = new KernelStatement(null, null, disk.newStatement(), new Procedures(), new CanWrite(), LockTracer.NONE);
}
Aggregations