Search in sources :

Example 1 with TransientDatabaseFailureException

use of org.neo4j.graphdb.TransientDatabaseFailureException 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
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientFailureException(org.neo4j.graphdb.TransientFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 2 with TransientDatabaseFailureException

use of org.neo4j.graphdb.TransientDatabaseFailureException in project neo4j by neo4j.

the class ClusterPartitionIT method ensureInstanceIsReadOnlyInPendingState.

/*
     * This method must be called on an instance that has had addSomeData() called on it.
     */
private void ensureInstanceIsReadOnlyInPendingState(HighlyAvailableGraphDatabase instance) {
    assertEquals(PENDING, instance.getInstanceState());
    tx(instance, retryACoupleOfTimesOn(TRANSIENT_ERRORS), db -> assertEquals(testPropValue, instance.getNodeById(testNodeId).getProperty(testPropKey)));
    try (Transaction ignored = instance.beginTx()) {
        instance.getNodeById(testNodeId).delete();
        fail("Should not be able to do write transactions when detached");
    } catch (TransientDatabaseFailureException | TransactionFailureException expected) {
    // expected
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException)

Aggregations

TransientDatabaseFailureException (org.neo4j.graphdb.TransientDatabaseFailureException)2 Test (org.junit.Test)1 Transaction (org.neo4j.graphdb.Transaction)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 TransientFailureException (org.neo4j.graphdb.TransientFailureException)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)1 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)1