Search in sources :

Example 6 with ClusterInfoSession

use of com.nokia.dempsy.cluster.ClusterInfoSession in project Dempsy by Dempsy.

the class TestFullApp method testStartForceMpDisconnectWithStandby.

@Test
public void testStartForceMpDisconnectWithStandby() 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();
        // we are going to create another node of the MyMp via a test hack
        cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
        Dempsy.Application.Cluster.Node mpnode = cluster.getNodes().get(0);
        // this actually hoses the output schedule. It moves it to the new node due
        //  to a second call to setOutputInvoker.
        // the code for start instantiates a new node
        cluster.instantiateAndStartAnotherNodeForTesting();
        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();
        // this should kill it.
        origZk.close();
        // but just to be sure actually stop the node.
        mpnode.stop();
        // we should be getting failures now ... and then recover.
        // get the MyMp prototype
        cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
        // notice, we're getting the SECOND node.
        node = cluster.getNodes().get(1);
        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));
    }
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) ClusterId(com.nokia.dempsy.config.ClusterId) StatsCollector(com.nokia.dempsy.monitoring.StatsCollector) Dempsy(com.nokia.dempsy.Dempsy) ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) MyMp(com.nokia.dempsy.cluster.zookeeper.FullApplication.MyMp) ZooKeeper(org.apache.zookeeper.ZooKeeper) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) Test(org.junit.Test)

Example 7 with ClusterInfoSession

use of com.nokia.dempsy.cluster.ClusterInfoSession in project Dempsy by Dempsy.

the class TestRouterClusterManagement method testChangingClusterInfo.

@Test
public void testChangingClusterInfo() throws Throwable {
    // check that the message didn't go through.
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/ClusterInfo-LocalActx.xml", "testDempsy/Serializer-KryoActx.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml");
    Dempsy dempsy = (Dempsy) context.getBean("dempsy");
    ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
    ClusterInfoSession session = factory.createSession();
    ClusterId curCluster = new ClusterId("test-app", "test-cluster1");
    TestUtils.createClusterLevel(curCluster, session);
    session.setData(curCluster.asPath(), new DecentralizedRoutingStrategy.DefaultRouterClusterInfo(20, 2));
    session.stop();
    dempsy.stop();
}
Also used : ClusterInfoSessionFactory(com.nokia.dempsy.cluster.ClusterInfoSessionFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(com.nokia.dempsy.config.ClusterId) Dempsy(com.nokia.dempsy.Dempsy) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) Test(org.junit.Test)

Example 8 with ClusterInfoSession

use of com.nokia.dempsy.cluster.ClusterInfoSession in project Dempsy by Dempsy.

the class TestRouterClusterManagement method init.

@Before
public void init() throws Throwable {
    onodes = System.setProperty("min_nodes_for_cluster", "1");
    oslots = System.setProperty("total_slots_for_cluster", "20");
    final ClusterId clusterId = new ClusterId("test", "test-slot");
    Destination destination = new Destination() {
    };
    ApplicationDefinition app = new ApplicationDefinition(clusterId.getApplicationName());
    DecentralizedRoutingStrategy strategy = new DecentralizedRoutingStrategy(1, 1);
    app.setRoutingStrategy(strategy);
    app.setSerializer(new JavaSerializer<Object>());
    ClusterDefinition cd = new ClusterDefinition(clusterId.getMpClusterName());
    cd.setMessageProcessorPrototype(new GoodTestMp());
    app.add(cd);
    app.initialize();
    LocalClusterSessionFactory mpfactory = new LocalClusterSessionFactory();
    ClusterInfoSession session = mpfactory.createSession();
    TestUtils.createClusterLevel(clusterId, session);
    // fake the inbound side setup
    inbound = strategy.createInbound(session, clusterId, new Dempsy() {

        public List<Class<?>> gm(ClusterDefinition clusterDef) {
            return super.getAcceptedMessages(clusterDef);
        }
    }.gm(cd), destination, new RoutingStrategy.Inbound.KeyspaceResponsibilityChangeListener() {

        @Override
        public void keyspaceResponsibilityChanged(Inbound inbound, boolean less, boolean more) {
        }
    });
    routerFactory = new Router(app);
    routerFactory.setClusterSession(session);
    routerFactory.setCurrentCluster(clusterId);
    routerFactory.initialize();
}
Also used : Destination(com.nokia.dempsy.messagetransport.Destination) ClusterDefinition(com.nokia.dempsy.config.ClusterDefinition) ClusterId(com.nokia.dempsy.config.ClusterId) Dempsy(com.nokia.dempsy.Dempsy) LocalClusterSessionFactory(com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory) ClusterRouter(com.nokia.dempsy.router.Router.ClusterRouter) Inbound(com.nokia.dempsy.router.RoutingStrategy.Inbound) ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) List(java.util.List) Before(org.junit.Before)

Aggregations

ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)8 ClusterId (com.nokia.dempsy.config.ClusterId)7 Test (org.junit.Test)6 Dempsy (com.nokia.dempsy.Dempsy)5 Condition (com.nokia.dempsy.TestUtils.Condition)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)4 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)4 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 DisruptibleSession (com.nokia.dempsy.cluster.DisruptibleSession)2 MyMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyMp)2 ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)2 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)2 MetricGetters (com.nokia.dempsy.monitoring.coda.MetricGetters)2 DefaultRouterSlotInfo (com.nokia.dempsy.router.DecentralizedRoutingStrategy.DefaultRouterSlotInfo)2 ApplicationContext (org.springframework.context.ApplicationContext)2 JunkDestination (com.nokia.dempsy.TestUtils.JunkDestination)1 ClusterInfoWatcher (com.nokia.dempsy.cluster.ClusterInfoWatcher)1 LocalClusterSessionFactory (com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory)1 ClusterDefinition (com.nokia.dempsy.config.ClusterDefinition)1