use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName.
@Test
void shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
long orphanedConstraintIndexId = 111;
String orphanedName = "blabla";
IndexDescriptor orphanedIndex = IndexPrototype.uniqueForSchema(schema).withName(orphanedName).materialise(orphanedConstraintIndexId);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(orphanedIndex)).thenReturn(indexProxy);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(schemaRead.index(schema)).thenReturn(Iterators.iterator(orphanedIndex));
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
when(schemaRead.indexGetForName(orphanedName)).thenReturn(orphanedIndex);
when(schemaRead.indexGetOwningUniquenessConstraintId(orphanedIndex)).thenReturn(// which means it has no owner
null);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
assertEquals(1, kernel.transactions.size());
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.
@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
IndexDescriptor index = prototype.materialise(this.index.getId());
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
assertEquals(1, kernel.transactions.size());
KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
verify(transactionInstance).indexUniqueCreate(prototype);
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldFailOnExistingOwnedConstraintIndex.
@Test
void shouldFailOnExistingOwnedConstraintIndex() {
// given
IndexingService indexingService = mock(IndexingService.class);
long constraintIndexOwnerId = 222;
when(schemaRead.index(schema)).thenReturn(Iterators.iterator(index));
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(index);
// which means there's an owner
when(schemaRead.indexGetOwningUniquenessConstraintId(index)).thenReturn(constraintIndexOwnerId);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
assertThrows(AlreadyConstrainedException.class, () -> {
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
});
// then
assertEquals(0, kernel.transactions.size(), "There should have been no need to acquire a statement to create the constraint index");
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class KernelTransactionFactory method kernelTransactionWithInternals.
private static Instances kernelTransactionWithInternals(LoginContext loginContext) {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency(mock(GraphDatabaseFacade.class));
KernelTransactionImplementation transaction = new KernelTransactionImplementation(Config.defaults(), mock(DatabaseTransactionEventListeners.class), mock(ConstraintIndexCreator.class), mock(GlobalProcedures.class), mock(InternalTransactionCommitProcess.class), mock(TransactionMonitor.class), mock(Pool.class), Clocks.nanoClock(), new AtomicReference<>(CpuClock.NOT_AVAILABLE), mock(DatabaseTracers.class, RETURNS_MOCKS), storageEngine, any -> CanWrite.INSTANCE, EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock(SchemaState.class), mockedTokenHolders(), mock(IndexingService.class), mock(IndexStatisticsStore.class), dependencies, new TestDatabaseIdRepository().defaultDatabase(), LeaseService.NO_LEASES, MemoryPools.NO_TRACKING, DatabaseReadOnlyChecker.writable(), TransactionExecutionMonitor.NO_OP, CommunitySecurityLog.NULL_LOG, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
transaction.initialize(0, 0, new NoOpClient(), KernelTransaction.Type.IMPLICIT, loginContext.authorize(LoginContext.IdLookup.EMPTY, DEFAULT_DATABASE_NAME, CommunitySecurityLog.NULL_LOG), 0L, 1L, EMBEDDED_CONNECTION);
return new Instances(transaction);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class TransactionCountingStateVisitorTraceIT method traceStateWithChanges.
private void traceStateWithChanges(Consumer<Transaction> transactionalOperation) throws KernelException {
try (var transaction = database.beginTx()) {
var internalTransaction = (InternalTransaction) transaction;
KernelTransactionImplementation kernelTransaction = (KernelTransactionImplementation) internalTransaction.kernelTransaction();
var cursorContext = kernelTransaction.cursorContext();
transactionalOperation.accept(transaction);
cursorContext.getCursorTracer().reportEvents();
assertZeroCursor(cursorContext);
var transactionState = kernelTransaction.txState();
var counts = new CountsDelta();
try (StorageReader storageReader = kernelTransaction.newStorageReader();
var stateVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, transactionState, counts, cursorContext)) {
transactionState.accept(stateVisitor);
}
assertTwoCursor(cursorContext);
}
}
Aggregations