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();
}
}
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
}
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());
}
}
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
}
}
Aggregations