Search in sources :

Example 21 with ClusterId

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++;
                        }
                    }
                }
            }
        }
    }
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 22 with ClusterId

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();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(com.nokia.dempsy.config.ClusterId) Test(org.junit.Test)

Example 23 with ClusterId

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();
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) Node(com.nokia.dempsy.Dempsy.Application.Cluster.Node)

Example 24 with ClusterId

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);
            }
        }
    }
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) Start(com.nokia.dempsy.annotations.Start) Method(java.lang.reflect.Method) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Example 25 with ClusterId

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();
        }
    });
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ClusterId (com.nokia.dempsy.config.ClusterId)34 Test (org.junit.Test)23 Condition (com.nokia.dempsy.TestUtils.Condition)15 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)9 ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)7 Dempsy (com.nokia.dempsy.Dempsy)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ClusterDefinition (com.nokia.dempsy.config.ClusterDefinition)5 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)5 Node (com.nokia.dempsy.Dempsy.Application.Cluster.Node)4 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)4 ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)4 MetricGetters (com.nokia.dempsy.monitoring.coda.MetricGetters)4 MyMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyMp)3 Destination (com.nokia.dempsy.messagetransport.Destination)3 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3