use of com.nokia.dempsy.cluster.ClusterInfoException in project Dempsy by Dempsy.
the class TestFullApp method testStartForceMpDisconnectWithStandby.
@Test
public void testStartForceMpDisconnectWithStandby() throws Throwable {
ClassPathXmlApplicationContext actx = null;
Dempsy dempsy = null;
try {
logger.debug("Starting up the appliction context ...");
actx = new ClassPathXmlApplicationContext(ctx);
actx.registerShutdownHook();
final FullApplication app = (FullApplication) actx.getBean("app");
dempsy = (Dempsy) actx.getBean("dempsy");
// Override the cluster session factory to keep track of the sessions asked for.
// This is so that I can grab the ZookeeperSession that's being instantiated by
// the MyMp cluster.
zookeeperCluster = null;
dempsy.setClusterSessionFactory(new ZookeeperSessionFactory(System.getProperty("zk_connect"), 5000) {
int sessionCount = 0;
@Override
public synchronized ClusterInfoSession createSession() throws ClusterInfoException {
sessionCount++;
ClusterInfoSession ret = super.createSession();
if (sessionCount == 2)
zookeeperCluster = (ZookeeperSession) ret;
return ret;
}
});
dempsy.start();
Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyAdaptor.class.getSimpleName()));
Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
final StatsCollector collector = node.getStatsCollector();
// we are going to create another node of the MyMp via a test hack
cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
Dempsy.Application.Cluster.Node mpnode = cluster.getNodes().get(0);
// this actually hoses the output schedule. It moves it to the new node due
// to a second call to setOutputInvoker.
// the code for start instantiates a new node
cluster.instantiateAndStartAnotherNodeForTesting();
assertNotNull(zookeeperCluster);
assertEquals(0, ((MetricGetters) collector).getDiscardedMessageCount());
assertEquals(0, ((MetricGetters) collector).getMessageFailedCount());
// ok ... so now we have stuff going all the way through. let's kick
// the middle Mp's zookeeper cluster and see what happens.
ZooKeeper origZk = zookeeperCluster.zkref.get();
// this should kill it.
origZk.close();
// but just to be sure actually stop the node.
mpnode.stop();
// we should be getting failures now ... and then recover.
// get the MyMp prototype
cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
// notice, we're getting the SECOND node.
node = cluster.getNodes().get(1);
final MyMp prototype = (MyMp) node.getMpContainer().getPrototype();
// so let's see where we are
final long interimMessageCount = prototype.myMpReceived.get();
// and now we should eventually get more as the session recovers.
assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return prototype.myMpReceived.get() > interimMessageCount + 100;
}
}));
} finally {
if (dempsy != null)
dempsy.stop();
if (actx != null)
actx.close();
if (dempsy != null)
assertTrue(dempsy.waitToBeStopped(baseTimeoutMillis));
}
}
use of com.nokia.dempsy.cluster.ClusterInfoException in project Dempsy by Dempsy.
the class TestZookeeperClusterResilience method testBouncingServer.
@Test
public void testBouncingServer() throws Throwable {
ZookeeperTestServer server = new ZookeeperTestServer();
ZookeeperSession session = null;
final ClusterId clusterId = new ClusterId(appname, "testBouncingServer");
try {
server.start();
ZookeeperSessionFactory factory = new ZookeeperSessionFactory("127.0.0.1:" + port, 5000);
session = (ZookeeperSession) factory.createSession();
final ZookeeperSession cluster = session;
createClusterLevel(clusterId, session);
TestWatcher callback = new TestWatcher(cluster) {
@Override
public void process() {
boolean done = false;
while (!done) {
done = true;
try {
if (session.getSubdirs(clusterId.asPath(), this).size() == 0)
session.mkdir(clusterId.asPath() + "/slot1", null, DirMode.EPHEMERAL);
called.set(true);
} catch (ClusterInfoException.NoNodeException e) {
try {
createClusterLevel(clusterId, session);
done = false;
} catch (ClusterInfoException e1) {
throw new RuntimeException(e1);
}
} catch (ClusterInfoException e) {
// this will fail when the connection is severed... that's ok.
}
}
}
};
cluster.exists(clusterId.asPath(), callback);
callback.process();
// create another session and look
ZookeeperSession session2 = (ZookeeperSession) factory.createSession();
assertEquals(1, session2.getSubdirs(new ClusterId(appname, "testBouncingServer").asPath(), null).size());
session2.stop();
// kill the server.
server.shutdown(false);
// reset the flags
callback.called.set(false);
// restart the server
server.start(false);
// wait for the call
assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new TestUtils.Condition<TestWatcher>() {
@Override
public boolean conditionMet(TestWatcher o) {
return o.called.get();
}
}));
// get the view from a new session.
session2 = (ZookeeperSession) factory.createSession();
assertEquals(1, session2.getSubdirs(new ClusterId(appname, "testBouncingServer").asPath(), null).size());
session2.stop();
} finally {
if (server != null)
server.shutdown();
if (session != null)
session.stop();
}
}
use of com.nokia.dempsy.cluster.ClusterInfoException in project Dempsy by Dempsy.
the class TestZookeeperClusterResilience method testBouncingServerWithCleanDataDir.
@Test
public void testBouncingServerWithCleanDataDir() throws Throwable {
ZookeeperTestServer server = new ZookeeperTestServer();
ZookeeperSession session = null;
final ClusterId clusterId = new ClusterId(appname, "testBouncingServerWithCleanDataDir");
try {
server.start();
ZookeeperSessionFactory factory = new ZookeeperSessionFactory("127.0.0.1:" + port, 5000);
session = (ZookeeperSession) factory.createSession();
final ZookeeperSession cluster = session;
createClusterLevel(clusterId, session);
TestWatcher callback = new TestWatcher(cluster) {
@Override
public void process() {
boolean done = false;
while (!done) {
done = true;
try {
if (session.getSubdirs(clusterId.asPath(), this).size() == 0)
session.mkdir(clusterId.asPath() + "/slot1", null, DirMode.EPHEMERAL);
called.set(true);
} catch (ClusterInfoException.NoNodeException e) {
try {
createClusterLevel(clusterId, session);
done = false;
} catch (ClusterInfoException e1) {
throw new RuntimeException(e1);
}
} catch (ClusterInfoException e) {
// this will fail when the connection is severed... that's ok.
}
}
}
};
cluster.exists(clusterId.asPath(), callback);
callback.process();
// create another session and look
ZookeeperSession session2 = (ZookeeperSession) factory.createSession();
assertEquals(1, session2.getSubdirs(new ClusterId(appname, "testBouncingServerWithCleanDataDir").asPath(), null).size());
session2.stop();
// kill the server.
server.shutdown(true);
// reset the flags
callback.called.set(false);
// restart the server
server.start(true);
// wait for the call
assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new TestUtils.Condition<TestWatcher>() {
@Override
public boolean conditionMet(TestWatcher o) {
return o.called.get();
}
}));
// get the view from a new session.
session2 = (ZookeeperSession) factory.createSession();
assertEquals(1, session2.getSubdirs(new ClusterId(appname, "testBouncingServerWithCleanDataDir").asPath(), null).size());
session2.stop();
} finally {
if (server != null)
server.shutdown();
if (session != null)
session.stop();
}
}
Aggregations