use of org.neo4j.graphdb.event.TransactionEventHandler in project neo4j by neo4j.
the class TestTransactionEvents method makeSureBeforeAfterAreCalledCorrectly.
@Test
public void makeSureBeforeAfterAreCalledCorrectly() {
List<TransactionEventHandler<Object>> handlers = new ArrayList<>();
handlers.add(new FailingEventHandler<>(new DummyTransactionEventHandler<>(null), false));
handlers.add(new FailingEventHandler<>(new DummyTransactionEventHandler<>(null), false));
handlers.add(new FailingEventHandler<>(new DummyTransactionEventHandler<>(null), true));
handlers.add(new FailingEventHandler<>(new DummyTransactionEventHandler<>(null), false));
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
for (TransactionEventHandler<Object> handler : handlers) {
db.registerTransactionEventHandler(handler);
}
try {
Transaction tx = db.beginTx();
try {
db.createNode().delete();
tx.success();
tx.close();
fail("Should fail commit");
} catch (TransactionFailureException e) {
// OK
}
verifyHandlerCalls(handlers, false);
db.unregisterTransactionEventHandler(handlers.remove(2));
for (TransactionEventHandler<Object> handler : handlers) {
((DummyTransactionEventHandler<Object>) ((FailingEventHandler<Object>) handler).source).reset();
}
try (Transaction transaction = db.beginTx()) {
db.createNode().delete();
transaction.success();
}
verifyHandlerCalls(handlers, true);
} finally {
for (TransactionEventHandler<Object> handler : handlers) {
db.unregisterTransactionEventHandler(handler);
}
}
}
Aggregations