use of com.nokia.dempsy.Dempsy in project Dempsy by Dempsy.
the class RunAppInVm method run.
public static ClassPathXmlApplicationContext run(boolean startUp) throws Throwable {
//======================================================
// Handle all of the options.
String appCtxFilename = System.getProperty(appdefParam);
if (appCtxFilename == null || appCtxFilename.length() == 0) {
// usage("the java vm option \"-D" + appdefParam + "\" wasn't specified.");
String application = System.getProperty(applicationParam);
if (application == null || application.length() == 0)
usage("the java vm option \"-D" + appdefParam + "\" or the java vm option \"-D" + applicationParam + "\" wasn't specified.");
appCtxFilename = "DempsyApplicationContext-" + application + ".xml";
}
//======================================================
String contextFile = "classpath:Dempsy-localVm.xml";
context = null;
try {
// Initialize Spring
context = new ClassPathXmlApplicationContext(new String[] { appCtxFilename, contextFile });
context.registerShutdownHook();
} catch (Throwable e) {
logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e);
throw e;
}
if (context != null) {
try {
Dempsy dempsy = context.getBean(Dempsy.class);
if (startUp) {
dempsy.start();
dempsy.waitToBeStopped();
}
} catch (InterruptedException e) {
logger.error("Interrupted . . . ", e);
} finally {
if (startUp)
context.stop();
}
logger.info("Shut down dempsy appliction " + appCtxFilename + ", bye!");
}
return context;
}
use of com.nokia.dempsy.Dempsy in project Dempsy by Dempsy.
the class TestRunAppInVm method testNormalStartup.
@Test
public void testNormalStartup() throws Throwable {
// need to wait on the clean shutdown
finished = new CountDownLatch(1);
// call run in another thread
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
RunAppInVm.run(true);
} catch (Throwable th) {
failed = true;
} finally {
finished.countDown();
}
}
}, "DempsyStartup");
t.start();
// wait for DempsyGrabber
for (long endTime = System.currentTimeMillis() + 60000; endTime > System.currentTimeMillis() && SimpleAppForTesting.grabber.get() == null; ) Thread.sleep(1);
assertNotNull(SimpleAppForTesting.grabber.get());
assertTrue(SimpleAppForTesting.grabber.get().waitForDempsy(60000));
assertTrue(SimpleAppForTesting.grabber.get().waitForContext(60000));
Dempsy dempsy = SimpleAppForTesting.grabber.get().dempsy.get();
// wait for Dempsy to be running
for (long endTime = System.currentTimeMillis() + 60000; endTime > System.currentTimeMillis() && !dempsy.isRunning(); ) Thread.sleep(1);
assertTrue(dempsy.isRunning());
// let the thing run for a bit.
Thread.sleep(500);
assertTrue(dempsy.isRunning());
dempsy.stop();
// wait for Dempsy to be stopped
for (long endTime = System.currentTimeMillis() + 60000; endTime > System.currentTimeMillis() && dempsy.isRunning(); ) Thread.sleep(1);
assertFalse(dempsy.isRunning());
assertFalse(failed);
}
use of com.nokia.dempsy.Dempsy in project Dempsy by Dempsy.
the class TestZookeeperClusterResilience method getDempsyFor.
private static Dempsy getDempsyFor(ClusterId clusterId, ApplicationDefinition ad) throws Throwable {
//------------------------------------------------------------------------------
// here is a complete non-spring, non-DI Dempsy instantiation
//------------------------------------------------------------------------------
List<ApplicationDefinition> ads = new ArrayList<ApplicationDefinition>();
ads.add(ad);
Dempsy dempsy = new Dempsy();
dempsy.setApplicationDefinitions(ads);
dempsy.setClusterCheck(new SpecificClusterCheck(clusterId));
dempsy.setDefaultRoutingStrategy(new DecentralizedRoutingStrategy(20, 1));
dempsy.setDefaultSerializer(new JavaSerializer<Object>());
dempsy.setDefaultStatsCollectorFactory(new StatsCollectorFactoryCoda());
dempsy.setDefaultTransport(new TcpTransport());
return dempsy;
}
use of com.nokia.dempsy.Dempsy 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));
}
}
use of com.nokia.dempsy.Dempsy in project Dempsy by Dempsy.
the class TestFullApp method testFailover.
@Test
public void testFailover() throws Throwable {
// now start each cluster
ctx[0] = "fullApp/Dempsy-FullUp.xml";
Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>();
DempsyHolder spare = new DempsyHolder();
try {
ApplicationDefinition ad = new FullApplication().getTopology();
ad.initialize();
List<ClusterDefinition> clusters = ad.getClusterDefinitions();
for (int i = clusters.size() - 1; i >= 0; i--) {
ClusterDefinition cluster = clusters.get(i);
CheckCluster.toCheckAgainst = cluster.getClusterId();
DempsyHolder cur = new DempsyHolder();
cur.clusterid = cluster.getClusterId();
cur.actx = new ClassPathXmlApplicationContext(ctx);
cur.actx.registerShutdownHook();
cur.dempsy = (Dempsy) cur.actx.getBean("dempsy");
cur.dempsy.start();
dempsys.put(cluster.getClusterId(), cur);
}
// get the last FullApplication in the processing chain.
ClassPathXmlApplicationContext actx = dempsys.get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx;
final FullApplication app = (FullApplication) actx.getBean("app");
// this checks that the throughput works.
assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return app.finalMessageCount.get() > 100;
}
}));
// now start another MyMp cluster.
spare = new DempsyHolder();
spare.clusterid = new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName());
CheckCluster.toCheckAgainst = spare.clusterid;
spare.actx = new ClassPathXmlApplicationContext(ctx);
spare.dempsy = (Dempsy) spare.actx.getBean("dempsy");
spare.dempsy.start();
Dempsy.Application.Cluster cluster = spare.dempsy.getCluster(spare.clusterid);
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 = spare.dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
node = cluster.getNodes().get(0);
final MyMp spareprototype = (MyMp) node.getMpContainer().getPrototype();
// TODO, see if we really need that check, and if so, implement
// an alternate way to get it, since with the stats collector rework
// we no longer use an independent MetricsRegistry per StatsCollector
// instance.
assertEquals(0, ((MetricGetters) collector).getDispatchedMessageCount());
assertEquals(0, spareprototype.myMpReceived.get());
// now bring down the original
DempsyHolder original = dempsys.get(spare.clusterid);
final MyMp originalprototype = (MyMp) original.dempsy.getCluster(spare.clusterid).getNodes().get(0).getMpContainer().getPrototype();
final long originalNumMessages = originalprototype.myMpReceived.get();
// makes sure the message count is still advancing
assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return originalprototype.myMpReceived.get() > originalNumMessages;
}
}));
// check one more time
assertEquals(0, spareprototype.myMpReceived.get());
// now stop the original ... the spare should pick up.
original.dempsy.stop();
// there's a race condition between the stop returning and the last message
// being processed.
// we need to check that a certain amount of time passes during which no more messages have been received.
// if we haven't seen a message in 1/2 second then we
final long numMillisecondsWithoutAMessage = 500;
// will assume that the messages have stopped.
// now we wait until at least numMillisecondsWithoutAMessage goes by without the myMpReceived
// being incremented. This must happen within the baseTimeoutMillis or this check is
// considered failed.
poll(baseTimeoutMillis + numMillisecondsWithoutAMessage, originalprototype, new Condition<Object>() {
long startCheckingTime = System.currentTimeMillis();
long lastMessage = originalprototype.myMpReceived.get();
@Override
public boolean conditionMet(Object o) {
if (originalprototype.myMpReceived.get() != lastMessage) {
startCheckingTime = System.currentTimeMillis();
lastMessage = originalprototype.myMpReceived.get();
return false;
} else
return (System.currentTimeMillis() - startCheckingTime) > numMillisecondsWithoutAMessage;
}
});
// now check to see if the new one picked up.
assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return spareprototype.myMpReceived.get() > 10;
}
}));
} finally {
ctx[0] = dempsyConfig;
for (DempsyHolder cur : dempsys.values()) {
cur.dempsy.stop();
cur.actx.close();
}
if (spare.dempsy != null)
spare.dempsy.stop();
if (spare.actx != null)
spare.actx.close();
}
}
Aggregations