use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class TransactionImplTest method shouldReturnTerminationReason.
@Test
void shouldReturnTerminationReason() {
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.getReasonIfTerminated()).thenReturn(Optional.empty()).thenReturn(Optional.of(Status.Transaction.Terminated));
TransactionImpl tx = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null);
Optional<Status> terminationReason1 = tx.terminationReason();
Optional<Status> terminationReason2 = tx.terminationReason();
assertFalse(terminationReason1.isPresent());
assertTrue(terminationReason2.isPresent());
assertEquals(Status.Transaction.Terminated, terminationReason2.get());
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class TransactionImplTest method shouldThrowTransactionExceptionOnTransientKernelException.
@Test
void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new RuntimeException("Just a random failure")).when(kernelTransaction).close();
TransactionImpl transaction = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null);
// WHEN
transaction.commit();
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class TransactionImplTest method fireCallbackOnClose.
@Test
void fireCallbackOnClose() {
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
MutableLong calls = new MutableLong();
// commit
try (TransactionImpl tx = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null)) {
tx.addCloseCallback(calls::increment);
tx.commit();
}
// and rollback
try (TransactionImpl tx = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null)) {
tx.addCloseCallback(calls::increment);
tx.rollback();
}
// and nothing
try (TransactionImpl tx = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null)) {
tx.addCloseCallback(calls::increment);
}
// should all invoke the callback
assertEquals(3, calls.longValue());
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class DenseNodeConcurrencyIT method assertNotBlocking.
private void assertNotBlocking(Consumer<Transaction> tx1, Consumer<Transaction> tx2) throws InterruptedException, ExecutionException {
try (OtherThreadExecutor t2 = new OtherThreadExecutor("T2")) {
Barrier.Control barrier = new Barrier.Control();
Future<Object> t2Future = null;
try {
t2Future = t2.executeDontWait(command(() -> {
try (Transaction tx = database.beginTx()) {
tx1.accept(tx);
((TransactionImpl) tx).commit(barrier::reached);
}
}));
barrier.await();
try (Transaction tx = database.beginTx()) {
tx2.accept(tx);
tx.commit();
}
} finally {
barrier.release();
waitFor(t2Future);
}
}
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class DenseNodeConcurrencyIT method assertBlocking.
private void assertBlocking(Consumer<Transaction> tx1, Consumer<Transaction> tx2, Predicate<OtherThreadExecutor.WaitDetails> waitDetailsPredicate) throws InterruptedException, ExecutionException, TimeoutException {
try (OtherThreadExecutor t2 = new OtherThreadExecutor("T2");
OtherThreadExecutor t3 = new OtherThreadExecutor("T3")) {
Barrier.Control barrier = new Barrier.Control();
Future<Object> t2Future = null;
Future<Object> t3Future = null;
try {
t2Future = t2.executeDontWait(command(() -> {
try (Transaction tx = database.beginTx()) {
tx1.accept(tx);
// ensure we upgrade to a write transaction to reach the barrier
tx.createNode();
((TransactionImpl) tx).commit(barrier::reached);
}
}));
barrier.await();
t3Future = t3.executeDontWait(command(() -> {
try (Transaction tx = database.beginTx()) {
tx2.accept(tx);
tx.commit();
}
}));
t3.waitUntilWaiting(waitDetailsPredicate);
} finally {
barrier.release();
waitFor(t2Future);
waitFor(t3Future);
}
}
}
Aggregations