use of com.nokia.dempsy.cluster.ClusterInfoWatcher in project Dempsy by Dempsy.
the class TestZookeeperClusterResilience method testSessionExpiredWithFullApp.
@Test
public void testSessionExpiredWithFullApp() throws Throwable {
// now lets startup the server.
ZookeeperTestServer server = null;
final AtomicReference<ZookeeperSession> sessionRef = new AtomicReference<ZookeeperSession>();
ZookeeperSession session = null;
final AtomicLong processCount = new AtomicLong(0);
Dempsy[] dempsy = new Dempsy[3];
try {
server = new ZookeeperTestServer();
server.start();
session = new ZookeeperSession("127.0.0.1:" + port, 5000) {
@Override
public WatcherProxy makeWatcherProxy(ClusterInfoWatcher w) {
processCount.incrementAndGet();
return super.makeWatcherProxy(w);
}
;
};
sessionRef.set(session);
final FullApplication app = new FullApplication();
ApplicationDefinition ad = app.getTopology();
// no calls yet
assertEquals(0, processCount.intValue());
dempsy[0] = getDempsyFor(new ClusterId(FullApplication.class.getSimpleName(), FullApplication.MyAdaptor.class.getSimpleName()), ad);
dempsy[0].setClusterSessionFactory(new ZookeeperSessionFactory("127.0.0.1:" + port, 5000));
dempsy[1] = getDempsyFor(new ClusterId(FullApplication.class.getSimpleName(), FullApplication.MyMp.class.getSimpleName()), ad);
dempsy[1].setClusterSessionFactory(new ZookeeperSessionFactory("127.0.0.1:" + port, 5000));
dempsy[2] = getDempsyFor(new ClusterId(FullApplication.class.getSimpleName(), FullApplication.MyRankMp.class.getSimpleName()), ad);
// dempsy[2].setClusterSessionFactory(new ZookeeperSessionFactory<ClusterInformation, SlotInformation>("127.0.0.1:" + port,5000));
dempsy[2].setClusterSessionFactory(new ClusterInfoSessionFactory() {
@Override
public ClusterInfoSession createSession() throws ClusterInfoException {
return sessionRef.get();
}
});
// start everything in reverse order
for (int i = 2; i >= 0; i--) dempsy[i].start();
// make sure the final count is incrementing
long curCount = app.finalMessageCount.get();
assertTrue(poll(30000, curCount, new Condition<Long>() {
@Override
public boolean conditionMet(Long o) {
return app.finalMessageCount.get() > (o + 100L);
}
}));
logger.trace("Killing zookeeper");
ZooKeeper origZk = session.zkref.get();
ZookeeperTestServer.forceSessionExpiration(origZk);
logger.trace("Killed zookeeper");
// wait for the current session to go invalid
assertTrue(poll(baseTimeoutMillis, origZk, new Condition<ZooKeeper>() {
@Override
public boolean conditionMet(ZooKeeper o) {
return !o.getState().isAlive();
}
}));
// make sure the final count is STILL incrementing
curCount = app.finalMessageCount.get();
assertTrue(poll(30000, curCount, new Condition<Long>() {
@Override
public boolean conditionMet(Long o) {
return app.finalMessageCount.get() > (o + 100L);
}
}));
} finally {
if (server != null)
server.shutdown();
if (session != null)
session.stop();
for (int i = 0; i < dempsy.length; i++) if (dempsy[i] != null)
dempsy[i].stop();
for (int i = 0; i < dempsy.length; i++) if (dempsy[i] != null)
assertTrue(dempsy[i].waitToBeStopped(baseTimeoutMillis));
}
}
Aggregations