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;
}
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;
}
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());
}
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();
}
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);
}
Aggregations