use of org.neo4j.kernel.lifecycle.LifecycleStatus in project neo4j by neo4j.
the class ClusterTransactionIT method givenClusterWhenShutdownMasterThenCannotStartTransactionOnSlave.
@Test
public void givenClusterWhenShutdownMasterThenCannotStartTransactionOnSlave() throws Throwable {
final HighlyAvailableGraphDatabase master = cluster.getMaster();
final HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
final long nodeId;
try (Transaction tx = master.beginTx()) {
nodeId = master.createNode().getId();
tx.success();
}
cluster.sync();
// When
final FutureTask<Boolean> result = new FutureTask<>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try (Transaction tx = slave.beginTx()) {
tx.acquireWriteLock(slave.getNodeById(nodeId));
} catch (Exception e) {
return contains(e, TransactionFailureException.class);
}
// Fail otherwise
return false;
}
});
master.getDependencyResolver().resolveDependency(LifeSupport.class).addLifecycleListener(new LifecycleListener() {
@Override
public void notifyStatusChanged(Object instance, LifecycleStatus from, LifecycleStatus to) {
if (instance.getClass().getName().contains("DatabaseAvailability") && to == LifecycleStatus.STOPPED) {
result.run();
}
}
});
master.shutdown();
// Then
assertThat(result.get(), equalTo(true));
}
Aggregations