use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionTerminationIT method terminateMasterTransactionThatWaitsForLockAcquiredBySlave.
@Test
public void terminateMasterTransactionThatWaitsForLockAcquiredBySlave() throws Exception {
ClusterManager.ManagedCluster cluster = startCluster();
String masterValue = "master";
String slaveValue = "slave";
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
createNode(cluster);
CountDownLatch slaveTxStarted = new CountDownLatch(1);
CountDownLatch slaveTxCommit = new CountDownLatch(1);
Future<?> slaveTx = setPropertyInSeparateThreadAndWaitBeforeCommit("slaveTx", slave, slaveValue, slaveTxStarted, slaveTxCommit);
await(slaveTxStarted);
AtomicReference<Transaction> masterTxReference = new AtomicReference<>();
CountDownLatch masterTxStarted = new CountDownLatch(1);
Future<?> masterTx = setPropertyInSeparateThreadAndAttemptToCommit("masterTx", master, masterValue, masterTxStarted, masterTxReference);
masterTxStarted.await();
sleepForAWhile();
terminate(masterTxReference);
assertTxWasTerminated(masterTx);
slaveTxCommit.countDown();
assertNull(slaveTx.get());
assertNodeExists(cluster, slaveValue);
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionTerminationIT method setPropertyInSeparateThreadAndWaitBeforeCommit.
private static Future<?> setPropertyInSeparateThreadAndWaitBeforeCommit(String threadName, GraphDatabaseService db, Object value, CountDownLatch txStarted, CountDownLatch txCommit) {
return executeInSeparateThread(threadName, () -> {
try (Transaction tx = db.beginTx()) {
Node node = findNode(db);
node.setProperty(PROPERTY, value);
txStarted.countDown();
await(txCommit);
tx.success();
}
});
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionTerminationIT method assertNodeExists.
private static void assertNodeExists(GraphDatabaseService db, Object value) {
try (Transaction tx = db.beginTx()) {
Node node = findNode(db);
assertTrue(node.hasProperty(PROPERTY));
assertEquals(value, node.getProperty(PROPERTY));
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionTerminationIT method terminateSlaveTransactionThatWaitsForLockOnMaster.
@Test
public void terminateSlaveTransactionThatWaitsForLockOnMaster() throws Exception {
ClusterManager.ManagedCluster cluster = startCluster();
String masterValue = "master";
String slaveValue = "slave";
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
createNode(cluster);
CountDownLatch masterTxStarted = new CountDownLatch(1);
CountDownLatch masterTxCommit = new CountDownLatch(1);
Future<?> masterTx = setPropertyInSeparateThreadAndWaitBeforeCommit("masterTx", master, masterValue, masterTxStarted, masterTxCommit);
await(masterTxStarted);
AtomicReference<Transaction> slaveTxReference = new AtomicReference<>();
CountDownLatch slaveTxStarted = new CountDownLatch(1);
Future<?> slaveTx = setPropertyInSeparateThreadAndAttemptToCommit("slaveTx", slave, slaveValue, slaveTxStarted, slaveTxReference);
slaveTxStarted.await();
sleepForAWhile();
terminate(slaveTxReference);
assertTxWasTerminated(slaveTx);
masterTxCommit.countDown();
assertNull(masterTx.get());
assertNodeExists(cluster, masterValue);
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionTerminationIT method createNode.
private static void createNode(GraphDatabaseService db) {
try (Transaction tx = db.beginTx()) {
db.createNode(LABEL);
tx.success();
}
}
Aggregations