Search in sources :

Example 26 with KernelTransactionImplementation

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);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 27 with KernelTransactionImplementation

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);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 28 with KernelTransactionImplementation

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);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.jupiter.api.Test)

Example 29 with KernelTransactionImplementation

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) StorageEngine(org.neo4j.storageengine.api.StorageEngine) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaState(org.neo4j.internal.schema.SchemaState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) DatabaseTransactionEventListeners(org.neo4j.kernel.internal.event.DatabaseTransactionEventListeners) Pool(org.neo4j.collection.pool.Pool) Dependencies(org.neo4j.collection.Dependencies) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Example 30 with KernelTransactionImplementation

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);
    }
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) CountsDelta(org.neo4j.storageengine.api.CountsDelta) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Aggregations

KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)35 Test (org.junit.jupiter.api.Test)20 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)13 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)8 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)7 StorageReader (org.neo4j.storageengine.api.StorageReader)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)6 DbmsRuntimeRepository (org.neo4j.dbms.database.DbmsRuntimeRepository)5 Transaction (org.neo4j.graphdb.Transaction)5 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)5 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)5 InOrder (org.mockito.InOrder)4 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 Test (org.junit.Test)3 SecurityAuthorizationHandler (org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler)3 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)3 IndexingProvidersService (org.neo4j.kernel.impl.api.index.IndexingProvidersService)3