use of org.neo4j.kernel.impl.coreapi.TopLevelTransaction in project neo4j by neo4j.
the class ExecutionResultTest method activeTransaction.
private TopLevelTransaction activeTransaction() {
ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
KernelTransaction kernelTransaction = bridge.getTopLevelTransactionBoundToThisThread(false);
return kernelTransaction == null ? null : new TopLevelTransaction(kernelTransaction, null);
}
use of org.neo4j.kernel.impl.coreapi.TopLevelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldThrowTransactionExceptionOnTransientKernelException.
@Test
public 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();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (org.neo4j.graphdb.TransactionFailureException e) {
// THEN Good
}
}
use of org.neo4j.kernel.impl.coreapi.TopLevelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldLetThroughTransientFailureException.
@Test
public void shouldLetThroughTransientFailureException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new TransientDatabaseFailureException("Just a random failure")).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (TransientFailureException e) {
// THEN Good
}
}
use of org.neo4j.kernel.impl.coreapi.TopLevelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.
@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (TransientTransactionFailureException e) {
// THEN Good
}
}
use of org.neo4j.kernel.impl.coreapi.TopLevelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldShowTransactionTerminatedExceptionAsTransient.
@Test
public void shouldShowTransactionTerminatedExceptionAsTransient() throws Exception {
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
doReturn(true).when(kernelTransaction).isOpen();
RuntimeException error = new TransactionTerminatedException(Status.Transaction.Terminated);
doThrow(error).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (Exception e) {
assertThat(e, instanceOf(TransientTransactionFailureException.class));
assertSame(error, e.getCause());
}
}
Aggregations