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