use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method runAllCombinations.
public void runAllCombinations(String applicationContext, Checker checker) throws Throwable {
for (String clusterManager : clusterManagers) {
for (String[] alternatingTransports : transports) {
// select one of the alternatingTransports
for (String transport : new AlternatingIterable(hardcore, alternatingTransports)) {
for (String serializer : new AlternatingIterable(hardcore, serializers)) {
// alternate the dempsy configs
for (String dempsyConfig : new AlternatingIterable(hardcore, dempsyConfigs)) {
if (!badCombos.contains(new ClusterId(clusterManager, transport))) {
String pass = applicationContext + " test: " + (checker == null ? "none" : checker) + " using " + dempsyConfig + "," + clusterManager + "," + serializer + "," + transport;
try {
logger.debug("*****************************************************************");
logger.debug(pass);
logger.debug("*****************************************************************");
if (checker != null) {
// reset everything
init();
// allow modification to defaults for this test.
checker.setup();
}
String[] ctx = { dempsyConfig, clusterManager, transport, serializer, "testDempsy/" + applicationContext };
logger.debug("Starting up the appliction context ...");
ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(ctx);
actx.registerShutdownHook();
Dempsy dempsy = (Dempsy) actx.getBean("dempsy");
assertTrue(pass, TestUtils.waitForClustersToBeInitialized(baseTimeoutMillis, dempsy));
WaitForShutdown waitingForShutdown = new WaitForShutdown(dempsy);
Thread waitingForShutdownThread = new Thread(waitingForShutdown, "Waiting For Shutdown");
waitingForShutdownThread.start();
Thread.yield();
logger.debug("Running test ...");
if (checker != null)
checker.check(actx);
logger.debug("Done with test, stopping the application context ...");
actx.stop();
actx.destroy();
assertTrue(waitingForShutdown.waitForShutdownDoneLatch.await(baseTimeoutMillis, TimeUnit.MILLISECONDS));
assertTrue(waitingForShutdown.shutdown);
logger.debug("Finished this pass.");
} catch (AssertionError re) {
logger.error("***************** FAILED ON: " + pass);
throw re;
} finally {
LocalClusterSessionFactory.completeReset();
}
runCount++;
}
}
}
}
}
}
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method testIndividualClusterStart.
@Test
public void testIndividualClusterStart() throws Throwable {
ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext("testDempsy/Dempsy-IndividualClusterStart.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterInfo-LocalActx.xml", "testDempsy/Serializer-KryoActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml");
actx.registerShutdownHook();
Dempsy dempsy = (Dempsy) actx.getBean("dempsy");
assertNotNull(dempsy);
Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster0"));
assertNull(cluster);
cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster1"));
assertNull(cluster);
cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster2"));
assertNotNull(cluster);
assertEquals(1, cluster.getNodes().size());
cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster3"));
assertNull(cluster);
cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster4"));
assertNull(cluster);
actx.stop();
actx.destroy();
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method getAdaptor.
private static Adaptor getAdaptor(Dempsy dempsy, String appName, String clusterName) {
Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId(appName, clusterName));
// currently there is one node per cluster.
Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
return node.clusterDefinition.getAdaptor();
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class MpContainer method preInitializePrototype.
/**
* Run any methods annotated PreInitilze on the MessageProcessor prototype
* @param prototype reference to MessageProcessor prototype
*/
private void preInitializePrototype(Object prototype) {
for (Method method : prototype.getClass().getMethods()) {
if (method.isAnnotationPresent(com.nokia.dempsy.annotations.Start.class)) {
// if the start method takes a ClusterId or ClusterDefinition then pass it.
Class<?>[] parameterTypes = method.getParameterTypes();
boolean takesClusterId = false;
if (parameterTypes != null && parameterTypes.length == 1) {
if (ClusterId.class.isAssignableFrom(parameterTypes[0]))
takesClusterId = true;
else {
logger.error("The method \"" + method.getName() + "\" on " + SafeString.objectDescription(prototype) + " is annotated with the @" + Start.class.getSimpleName() + " annotation but doesn't have the correct signature. " + "It needs to either take no parameters or take a single " + ClusterId.class.getSimpleName() + " parameter.");
// return without invoking start.
return;
}
} else if (parameterTypes != null && parameterTypes.length > 1) {
logger.error("The method \"" + method.getName() + "\" on " + SafeString.objectDescription(prototype) + " is annotated with the @" + Start.class.getSimpleName() + " annotation but doesn't have the correct signature. " + "It needs to either take no parameters or take a single " + ClusterId.class.getSimpleName() + " parameter.");
// return without invoking start.
return;
}
try {
if (takesClusterId)
method.invoke(prototype, clusterId);
else
method.invoke(prototype);
// Only allow one such method, which is checked during validation
break;
} catch (Exception e) {
logger.error(MarkerFactory.getMarker("FATAL"), "can't run MP initializer " + method.getName(), e);
}
}
}
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestAllClusterImpls method testConsumerCluster.
@Test
public void testConsumerCluster() throws Throwable {
runAllCombinations(new Checker() {
@Override
public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable {
final ClusterId cid = new ClusterId("test-app6", "test-cluster");
session1 = factory.createSession();
createClusterLevel(cid, session1);
sessionsToClose.add(session1);
session2 = factory.createSession();
sessionsToClose.add(session2);
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
String consumer = getClusterLeaf(cid, session1);
session1.setData(consumer, "Test");
thread1Passed = true;
latch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
});
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
latch.await(10, TimeUnit.SECONDS);
String producer = getClusterLeaf(cid, session2);
String data = (String) session2.getData(producer, null);
if ("Test".equals(data))
thread2Passed = true;
} catch (Exception e) {
e.printStackTrace();
}
}
});
t2.start();
t1.join(30000);
// use a timeout just in case. A failure should be indicated below if the thread never finishes.
t2.join(30000);
assertTrue(pass, thread1Passed);
assertTrue(pass, thread2Passed);
session2.stop();
session1.stop();
}
});
}
Aggregations