use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class KernelTransactionsTest method shouldTellWhenTransactionsFromSnapshotHaveBeenClosed.
@Test
public void shouldTellWhenTransactionsFromSnapshotHaveBeenClosed() throws Throwable {
// GIVEN
KernelTransactions transactions = newKernelTransactions();
KernelTransaction a = getKernelTransaction(transactions);
KernelTransaction b = getKernelTransaction(transactions);
KernelTransaction c = getKernelTransaction(transactions);
KernelTransactionsSnapshot snapshot = transactions.get();
assertFalse(snapshot.allClosed());
// WHEN a gets closed
a.close();
assertFalse(snapshot.allClosed());
// WHEN c gets closed and (test knowing too much) that instance getting reused in another transaction "d".
c.close();
KernelTransaction d = getKernelTransaction(transactions);
assertFalse(snapshot.allClosed());
// WHEN b finally gets closed
b.close();
assertTrue(snapshot.allClosed());
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldRollbackOnClosingTerminatedButSuccessfulTransaction.
@Test
public void shouldRollbackOnClosingTerminatedButSuccessfulTransaction() throws Exception {
// GIVEN
KernelTransaction transaction = newTransaction(securityContext());
transactionInitializer.accept(transaction);
transaction.markForTermination(Status.General.UnknownError);
transaction.success();
assertEquals(Status.General.UnknownError, transaction.getReasonIfTerminated().get());
try {
// WHEN
transaction.close();
fail("Exception expected");
} catch (Exception e) {
assertThat(e, instanceOf(TransactionTerminatedException.class));
}
// THEN
verify(transactionMonitor, times(1)).transactionFinished(false, isWriteTx);
verify(transactionMonitor, times(1)).transactionTerminated(isWriteTx);
verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class KernelTransactionsTest method shouldDisposeTransactionsWhenAsked.
@Test
public void shouldDisposeTransactionsWhenAsked() throws Throwable {
// Given
KernelTransactions transactions = newKernelTransactions();
transactions.disposeAll();
KernelTransaction first = getKernelTransaction(transactions);
KernelTransaction second = getKernelTransaction(transactions);
KernelTransaction leftOpen = getKernelTransaction(transactions);
first.close();
second.close();
// When
transactions.disposeAll();
// Then
KernelTransaction postDispose = getKernelTransaction(transactions);
assertThat(postDispose, not(equalTo(first)));
assertThat(postDispose, not(equalTo(second)));
assertTrue(leftOpen.getReasonIfTerminated() != null);
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldCommitSuccessfulTransaction.
@Test
public void shouldCommitSuccessfulTransaction() throws Exception {
// GIVEN
try (KernelTransaction transaction = newTransaction(securityContext())) {
// WHEN
transactionInitializer.accept(transaction);
transaction.success();
}
// THEN
verify(transactionMonitor, times(1)).transactionFinished(true, isWriteTx);
verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldIgnoreTerminateAfterRollback.
@Test
public void shouldIgnoreTerminateAfterRollback() throws Exception {
KernelTransaction transaction = newTransaction(securityContext());
transactionInitializer.accept(transaction);
transaction.close();
transaction.markForTermination(Status.General.UnknownError);
// THEN
verify(transactionMonitor, times(1)).transactionFinished(false, isWriteTx);
verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Aggregations