Search in sources :

Example 1 with SimpleStatementLocks

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

the class KernelTransactionTestBase method newTransaction.

public KernelTransactionImplementation newTransaction(long lastTransactionIdWhenStarted, SecurityContext securityContext, Locks.Client locks, long transactionTimeout) {
    KernelTransactionImplementation tx = newNotInitializedTransaction();
    StatementLocks statementLocks = new SimpleStatementLocks(locks);
    tx.initialize(lastTransactionIdWhenStarted, BASE_TX_COMMIT_TIMESTAMP, statementLocks, Type.implicit, securityContext, transactionTimeout);
    return tx;
}
Also used : SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks)

Example 2 with SimpleStatementLocks

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

the class StatementOperationsTestHelper method mockedState.

public static KernelStatement mockedState(final TransactionState txState) {
    KernelStatement state = mock(KernelStatement.class);
    Locks.Client locks = mock(Locks.Client.class);
    try {
        IndexReader indexReader = mock(IndexReader.class);
        when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
        StorageStatement storageStatement = mock(StorageStatement.class);
        when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
        when(state.getStoreStatement()).thenReturn(storageStatement);
    } catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
        throw new Error(e);
    }
    when(state.txState()).thenReturn(txState);
    when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
    when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
    when(state.readOperations()).thenReturn(mock(ReadOperations.class));
    return state;
}
Also used : SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Locks(org.neo4j.kernel.impl.locking.Locks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 3 with SimpleStatementLocks

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

the class KernelTransactionImplementationTest method shouldIncrementReuseCounterOnReuse.

@Test
public void shouldIncrementReuseCounterOnReuse() throws Exception {
    // GIVEN
    KernelTransactionImplementation transaction = newTransaction(securityContext());
    int reuseCount = transaction.getReuseCount();
    // WHEN
    transaction.close();
    SimpleStatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
    transaction.initialize(1, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, securityContext(), 0L);
    // THEN
    assertEquals(reuseCount + 1, transaction.getReuseCount());
}
Also used : NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Test(org.junit.Test)

Example 4 with SimpleStatementLocks

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

the class KernelTransactionImplementationTest method markForTerminationWithIncorrectReuseCount.

@Test
public void markForTerminationWithIncorrectReuseCount() throws Exception {
    int reuseCount = 13;
    int nextReuseCount = reuseCount + 2;
    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);
    assertFalse(tx.markForTermination(nextReuseCount, terminationReason));
    assertFalse(tx.getReasonIfTerminated().isPresent());
    verify(locksClient, never()).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 5 with SimpleStatementLocks

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

the class KernelTransactionFactory method kernelTransactionWithInternals.

static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
    TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
    TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
    when(headerInformationFactory.create()).thenReturn(headerInformation);
    StorageEngine storageEngine = mock(StorageEngine.class);
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(storeReadLayer.newStatement()).thenReturn(storageStatement);
    when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
    KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.class), mock(SchemaWriteGuard.class), new TransactionHooks(), mock(ConstraintIndexCreator.class), new Procedures(), headerInformationFactory, mock(TransactionRepresentationCommitProcess.class), mock(TransactionMonitor.class), mock(Supplier.class), mock(Pool.class), Clocks.systemClock(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
    StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
    transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
    return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) TransactionHeaderInformation(org.neo4j.kernel.impl.api.TransactionHeaderInformation) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) TransactionHooks(org.neo4j.kernel.impl.api.TransactionHooks) Procedures(org.neo4j.kernel.impl.proc.Procedures) TransactionHeaderInformationFactory(org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) CanWrite(org.neo4j.kernel.impl.factory.CanWrite) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) Supplier(java.util.function.Supplier) Pool(org.neo4j.collection.pool.Pool) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor)

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