Search in sources :

Example 1 with TransactionTerminatedException

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

the class ClusterTest method givenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch.

@Test
public void givenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch() throws Throwable {
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("waitfortx")).withCluster(ClusterManager.clusterOfSize(3)).build();
    try {
        clusterManager.start();
        ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
        cluster.await(allSeesAllAsAvailable());
        HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
        Transaction tx = slave.beginTx();
        // Do a little write operation so that all "write" aspects of this tx is initializes properly
        slave.createNode();
        // Shut down master while we're keeping this transaction open
        cluster.shutdown(cluster.getMaster());
        cluster.await(masterAvailable());
        cluster.await(masterSeesSlavesAsAvailable(1));
        // Ending up here means that we didn't wait for this transaction to complete
        tx.success();
        try {
            tx.close();
            fail("Exception expected");
        } catch (Exception e) {
            assertThat(e, instanceOf(TransientTransactionFailureException.class));
            Throwable rootCause = rootCause(e);
            assertThat(rootCause, instanceOf(TransactionTerminatedException.class));
            assertThat(((TransactionTerminatedException) rootCause).status(), Matchers.equalTo(Status.General.DatabaseUnavailable));
        }
    } finally {
        clusterManager.stop();
    }
}
Also used : TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) IOException(java.io.IOException) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Test(org.junit.Test)

Example 2 with TransactionTerminatedException

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

the class ClusterLocksIT method aPendingMemberShouldBeAbleToServeReads.

@Test
public void aPendingMemberShouldBeAbleToServeReads() throws Throwable {
    // given
    createNodeOnMaster(testLabel, cluster.getMaster());
    cluster.sync();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    cluster.fail(slave, ClusterManager.NetworkFlag.values());
    cluster.await(instanceEvicted(slave));
    assertEquals(PENDING, slave.getInstanceState());
    // when
    for (int i = 0; i < 10; i++) {
        try (Transaction tx = slave.beginTx()) {
            Node single = Iterables.single(slave.getAllNodes());
            Label label = Iterables.single(single.getLabels());
            assertEquals(testLabel, label);
            tx.success();
            break;
        } catch (TransactionTerminatedException e) {
            // Race between going to pending and reading, try again in a little while
            Thread.sleep(1_000);
        }
    }
// then no exceptions thrown
}
Also used : TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 3 with TransactionTerminatedException

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

Example 4 with TransactionTerminatedException

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

the class KernelIT method shouldKillTransactionsOnShutdown.

@Test
public void shouldKillTransactionsOnShutdown() throws Throwable {
    // Given
    assumeThat(kernel, instanceOf(Kernel.class));
    // Then
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read())) {
        ((Kernel) kernel).stop();
        tx.acquireStatement().readOperations().nodeExists(0L);
        fail("Should have been terminated.");
    } catch (TransactionTerminatedException e) {
    // Success
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Kernel(org.neo4j.kernel.impl.api.Kernel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 Transaction (org.neo4j.graphdb.Transaction)2 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)2 IOException (java.io.IOException)1 Label (org.neo4j.graphdb.Label)1 Node (org.neo4j.graphdb.Node)1 TransientDatabaseFailureException (org.neo4j.graphdb.TransientDatabaseFailureException)1 TransientFailureException (org.neo4j.graphdb.TransientFailureException)1 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1 Kernel (org.neo4j.kernel.impl.api.Kernel)1 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)1 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)1 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)1