use of com.nokia.dempsy.config.ApplicationDefinition in project Dempsy by Dempsy.
the class TestRouterInstantiation method testDispatchBadMessage.
@Test
public void testDispatchBadMessage() throws Throwable {
ApplicationDefinition app = new ApplicationDefinition("test");
Router router = new Router(app);
Object o;
router.dispatch(o = new Object() {
@MessageKey
public String getKey() {
return "hello";
}
});
assertTrue(router.stopTryingToSendTheseTypes.contains(o.getClass()));
MessageThatFailsOnKeyRetrieve message = new MessageThatFailsOnKeyRetrieve();
router.dispatch(message);
assertTrue(message.threw);
// this should just warn
router.dispatch(null);
}
use of com.nokia.dempsy.config.ApplicationDefinition in project Dempsy by Dempsy.
the class TestRouterInstantiation method testGetMessages.
@Test
public void testGetMessages() throws Throwable {
ApplicationDefinition app = new ApplicationDefinition("test");
Router router = new Router(app);
List<Object> messages = new ArrayList<Object>();
Object first = new Object();
router.getMessages(first, messages);
Assert.assertEquals(1, messages.size());
Assert.assertSame(first, messages.get(0));
}
use of com.nokia.dempsy.config.ApplicationDefinition in project Dempsy by Dempsy.
the class TestFullApp method testSeparateClustersInOneVm.
@Test
public void testSeparateClustersInOneVm() throws Throwable {
// now start each cluster
ctx[0] = "fullApp/Dempsy-FullUp.xml";
Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, 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;
}
}));
} finally {
ctx[0] = dempsyConfig;
for (DempsyHolder cur : dempsys.values()) {
cur.dempsy.stop();
cur.actx.close();
}
}
}
use of com.nokia.dempsy.config.ApplicationDefinition 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.config.ApplicationDefinition 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