Search in sources :

Example 6 with SimpleStatementLocks

use of org.neo4j.kernel.impl.locking.SimpleStatementLocks in project neo4j by neo4j.

the class KernelTransactionImplementationTest method shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader.

@SuppressWarnings("unchecked")
@Test
public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception {
    // GIVEN a transaction starting at one point in time
    long startingTime = clock.millis();
    when(legacyIndexState.hasChanges()).thenReturn(true);
    doAnswer(invocation -> {
        @SuppressWarnings("unchecked") Collection<StorageCommand> commands = invocation.getArgumentAt(0, Collection.class);
        commands.add(mock(Command.class));
        return null;
    }).when(storageEngine).createCommands(any(Collection.class), any(TransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    try (KernelTransactionImplementation transaction = newTransaction(securityContext())) {
        SimpleStatementLocks statementLocks = new SimpleStatementLocks(mock(Locks.Client.class));
        transaction.initialize(5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, AUTH_DISABLED, 0L);
        try (KernelStatement statement = transaction.acquireStatement()) {
            // which will pull it from the supplier and the mocking above
            statement.legacyIndexTxState();
        // will have it say that it has changes.
        }
        // WHEN committing it at a later point
        clock.forward(5, MILLISECONDS);
        // ...and simulating some other transaction being committed
        when(metaDataStore.getLastCommittedTransactionId()).thenReturn(7L);
        transaction.success();
    }
    // THEN start time and last tx when started should have been taken from when the transaction started
    assertEquals(5L, commitProcess.transaction.getLatestCommittedTxWhenStarted());
    assertEquals(startingTime, commitProcess.transaction.getTimeStarted());
    assertEquals(startingTime + 5, commitProcess.transaction.getTimeCommitted());
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) StorageStatement(org.neo4j.storageengine.api.StorageStatement) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.storageengine.api.lock.ResourceLocker) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) Collection(java.util.Collection) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) Test(org.junit.Test)

Example 7 with SimpleStatementLocks

use of org.neo4j.kernel.impl.locking.SimpleStatementLocks in project neo4j by neo4j.

the class KernelTransactionImplementationTest method initializeAndClose.

private void initializeAndClose(KernelTransactionImplementation tx, int times) throws Exception {
    for (int i = 0; i < times; i++) {
        SimpleStatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
        tx.initialize(i + 10, i + 10, statementLocks, KernelTransaction.Type.implicit, securityContext(), 0L);
        tx.close();
    }
}
Also used : NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks)

Example 8 with SimpleStatementLocks

use of org.neo4j.kernel.impl.locking.SimpleStatementLocks in project neo4j by neo4j.

the class KernelTransactionImplementationTest method markForTerminationWithCorrectReuseCount.

@Test
public void markForTerminationWithCorrectReuseCount() throws Exception {
    int reuseCount = 10;
    Status.Transaction terminationReason = Status.Transaction.Terminated;
    KernelTransactionImplementation tx = newNotInitializedTransaction();
    initializeAndClose(tx, reuseCount);
    Locks.Client locksClient = mock(Locks.Client.class);
    SimpleStatementLocks statementLocks = new SimpleStatementLocks(locksClient);
    tx.initialize(42, 42, statementLocks, KernelTransaction.Type.implicit, securityContext(), 0L);
    assertTrue(tx.markForTermination(reuseCount, terminationReason));
    assertEquals(terminationReason, tx.getReasonIfTerminated().get());
    verify(locksClient).stop();
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Locks(org.neo4j.kernel.impl.locking.Locks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Test(org.junit.Test)

Example 9 with SimpleStatementLocks

use of org.neo4j.kernel.impl.locking.SimpleStatementLocks in project neo4j by neo4j.

the class ConstraintEnforcingEntityOperationsTest method given_ConstraintEnforcingEntityOperations_with_OnlineIndex.

@Before
public void given_ConstraintEnforcingEntityOperations_with_OnlineIndex() throws Exception {
    this.readOps = mock(EntityReadOperations.class);
    SchemaReadOperations schemaReadOps = mock(SchemaReadOperations.class);
    SchemaWriteOperations schemaWriteOps = mock(SchemaWriteOperations.class);
    this.state = mock(KernelStatement.class);
    when(schemaReadOps.indexGetState(state, index)).thenReturn(InternalIndexState.ONLINE);
    this.locks = mock(Locks.Client.class);
    when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
    when(state.lockTracer()).thenReturn(LockTracer.NONE);
    this.ops = new ConstraintEnforcingEntityOperations(new StandardConstraintSemantics(), null, readOps, schemaWriteOps, schemaReadOps);
}
Also used : KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) ConstraintEnforcingEntityOperations(org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) Before(org.junit.Before)

Aggregations

SimpleStatementLocks (org.neo4j.kernel.impl.locking.SimpleStatementLocks)9 Test (org.junit.Test)4 NoOpClient (org.neo4j.kernel.impl.locking.NoOpClient)4 Locks (org.neo4j.kernel.impl.locking.Locks)3 StorageStatement (org.neo4j.storageengine.api.StorageStatement)3 Status (org.neo4j.kernel.api.exceptions.Status)2 StatementLocks (org.neo4j.kernel.impl.locking.StatementLocks)2 Collection (java.util.Collection)1 Supplier (java.util.function.Supplier)1 Before (org.junit.Before)1 Pool (org.neo4j.collection.pool.Pool)1 PageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 IndexNotApplicableKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)1 ConstraintEnforcingEntityOperations (org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)1 SchemaWriteGuard (org.neo4j.kernel.impl.api.SchemaWriteGuard)1