use of com.nokia.dempsy.monitoring.StatsCollector in project Dempsy by Dempsy.
the class TestInstanceManager method setupContainer.
//----------------------------------------------------------------------------
// Test Cases
//----------------------------------------------------------------------------
public MpContainer setupContainer(Object prototype) throws ContainerException {
DummyDispatcher dispatcher = new DummyDispatcher();
StatsCollector stats = new StatsCollectorCoda(new ClusterId("test", "test"), new StatsCollectorFactoryCoda().getNamingStrategy());
JavaSerializer<Object> serializer = new JavaSerializer<Object>();
manager = new MpContainer(new ClusterId("test", "test"));
manager.setDispatcher(dispatcher);
manager.setStatCollector(stats);
manager.setSerializer(serializer);
manager.setPrototype(prototype);
return manager;
}
use of com.nokia.dempsy.monitoring.StatsCollector in project Dempsy by Dempsy.
the class PassthroughTransport method createOutbound.
@Override
public SenderFactory createOutbound(DempsyExecutor executor, final StatsCollector statsCollector) {
return new SenderFactory() {
private volatile boolean isStopped = false;
private StatsCollector sc = statsCollector;
@Override
public Sender getSender(Destination destination) throws MessageTransportException {
if (isStopped == true)
throw new MessageTransportException("getSender called for the destination " + SafeString.valueOf(destination) + " on a stopped " + SafeString.valueOfClass(this));
PassthroughSender ret = (PassthroughSender) (((PassthroughDestination) destination).sender);
ret.statsCollector = sc;
return ret;
}
@Override
public void stop() {
isStopped = true;
}
// There is no 'stop' on a PassthroughSender so there's nothing to do to reclaim it.
@Override
public void reclaim(Destination destination) {
}
};
}
use of com.nokia.dempsy.monitoring.StatsCollector in project Dempsy by Dempsy.
the class LifecycleHelper method invoke.
/**
* Invokes the appropriate message handler of the passed instance. Caller is responsible for not passing <code>null</code> messages.
*
* @throws ContainerException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
public Object invoke(Object instance, Object message, StatsCollector statsCollector) throws ContainerException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Class<?> messageClass = message.getClass();
if (!isMessageSupported(message))
throw new ContainerException(mpClassName + ": no handler for messages of type: " + messageClass.getName());
StatsCollector.TimerContext tctx = null;
try {
tctx = statsCollector.handleMessageStarted();
return invocationMethods.invokeMethod(instance, message);
} finally {
if (tctx != null)
tctx.stop();
}
}
use of com.nokia.dempsy.monitoring.StatsCollector 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();
}
}
use of com.nokia.dempsy.monitoring.StatsCollector in project Dempsy by Dempsy.
the class TestFullApp method testStartForceMpDisconnectStop.
@Test
public void testStartForceMpDisconnectStop() 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();
// this checks that the throughput works.
assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return app.finalMessageCount.get() > 10;
}
}));
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();
long sessionid = origZk.getSessionId();
ZooKeeper killer = new ZooKeeper(System.getProperty("zk_connect"), 5000, new Watcher() {
@Override
public void process(WatchedEvent arg0) {
}
}, sessionid, null);
// tricks the server into expiring the other session
killer.close();
// // we should be getting failures now ...
// // but it's possible that it can reconnect prior to actually seeing an error so if this
// // fails frequently we need to remove this test.
// assertTrue(poll(baseTimeoutMillis, app, new Condition()
// {
// @Override
// public boolean conditionMet(Object o)
// {
// return collector.getMessageFailedCount() > 1;
// }
// }));
//... and then recover.
// get the MyMp prototype
cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
node = cluster.getNodes().get(0);
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));
}
}
Aggregations