Search in sources :

Example 1 with ClusterInfoSessionFactory

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

the class TestDempsy method testExpandingAndContractingKeySpace.

@Test
public void testExpandingAndContractingKeySpace() throws Throwable {
    Checker checker = new Checker() {

        @Override
        public void check(ApplicationContext context) throws Throwable {
            ClusterInfoSession session = null;
            try {
                // start things and verify that the init method was called
                Dempsy dempsy = (Dempsy) context.getBean("dempsy");
                TestMp mp = (TestMp) getMp(dempsy, "test-app", "test-cluster1");
                final ClusterId clusterId = new ClusterId("test-app", "test-cluster1");
                // verify we haven't called it again, not that there's really
                // a way to given the code
                assertEquals(1, mp.startCalls.get());
                // make sure that there are no Mps
                MetricGetters statsCollector = (MetricGetters) dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).getStatsCollector();
                // This will wait until the keySpace is up to the maxcount which is set (in the setup, below) to 100000
                assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 100000 == sc.getMessageProcessorCount();
                    }
                }));
                // now push the cluster into backup node.
                ClusterInfoSession originalSession = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).retouRteg().getClusterSession();
                ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
                session = TestUtils.stealShard(originalSession, factory, clusterId.asPath() + "/" + String.valueOf(0), baseTimeoutMillis);
                // If we got here then the MpContainer is on standby and the number of Mps should
                // drop to zero.
                assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 0 == sc.getMessageProcessorCount();
                    }
                }));
                Thread.sleep(10);
                assertEquals(0, statsCollector.getMessageProcessorCount());
                // this should give control back over to the original session.
                session.stop();
                session = null;
                // If we got here then the MpContainer is no longer on standby and the number of Mps should
                // go back to the original amount.
                assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 100000 == sc.getMessageProcessorCount();
                    }
                }));
                Thread.sleep(10);
                assertEquals(100000, statsCollector.getMessageProcessorCount());
            } finally {
                if (session != null)
                    session.stop();
            }
        }

        public String toString() {
            return "testExpandingAndContractingKeySpace";
        }

        public void setup() {
            KeySourceImpl.maxcount = 100000;
            System.setProperty("min_nodes_for_cluster", "1");
            System.setProperty("total_slots_for_cluster", "1");
        }
    };
    runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClusterInfoSessionFactory(com.nokia.dempsy.cluster.ClusterInfoSessionFactory) ClusterId(com.nokia.dempsy.config.ClusterId) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) MetricGetters(com.nokia.dempsy.monitoring.coda.MetricGetters) Test(org.junit.Test)

Example 2 with ClusterInfoSessionFactory

use of com.nokia.dempsy.cluster.ClusterInfoSessionFactory 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));
    }
}
Also used : ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) ClusterInfoWatcher(com.nokia.dempsy.cluster.ClusterInfoWatcher) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) Condition(com.nokia.dempsy.TestUtils.Condition) ClusterInfoSessionFactory(com.nokia.dempsy.cluster.ClusterInfoSessionFactory) ClusterId(com.nokia.dempsy.config.ClusterId) Dempsy(com.nokia.dempsy.Dempsy) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicLong(java.util.concurrent.atomic.AtomicLong) ZooKeeper(org.apache.zookeeper.ZooKeeper) ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 3 with ClusterInfoSessionFactory

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

the class TestDempsy method testFailedClusterManagerDuringKeyStoreCalls.

@Test
public void testFailedClusterManagerDuringKeyStoreCalls() throws Throwable {
    Checker checker = new Checker() {

        @Override
        public void check(ApplicationContext context) throws Throwable {
            ClusterInfoSession session = null;
            try {
                // start things and verify that the init method was called
                Dempsy dempsy = (Dempsy) context.getBean("dempsy");
                TestMp mp = (TestMp) getMp(dempsy, "test-app", "test-cluster1");
                final ClusterId clusterId = new ClusterId("test-app", "test-cluster1");
                // verify we haven't called it again, not that there's really
                // a way to given the code
                assertEquals(1, mp.startCalls.get());
                // make sure that there are no Mps
                MetricGetters statsCollector = (MetricGetters) dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).getStatsCollector();
                assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 100000 == sc.getMessageProcessorCount();
                    }
                }));
                // now there's 100000 mps in the container created from the KeySource. So we steal the 
                // shard and force if offline but continuously disrupt it while it tries to come
                // back up.
                // now push the cluster into backup node.
                ClusterInfoSession originalSession = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).retouRteg().getClusterSession();
                ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
                String path = clusterId.asPath() + "/" + String.valueOf(0);
                session = TestUtils.stealShard(originalSession, factory, path, baseTimeoutMillis);
                DefaultRouterSlotInfo si = (DefaultRouterSlotInfo) session.getData(path, null);
                // checks to see who actually has the slot.
                assertTrue(si.getDestination() instanceof JunkDestination);
                // we will keep disrupting the session but we should still end up with zero mps.
                for (int i = 0; i < 100; i++) {
                    ((DisruptibleSession) originalSession).disrupt();
                    Thread.sleep(1);
                }
                // now wait until we get to zero.
                assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 0 == sc.getMessageProcessorCount();
                    }
                }));
                Thread.sleep(10);
                assertEquals(0, statsCollector.getMessageProcessorCount());
                // ok. Now we will close the session that's holding the shard and allow the container
                // to re-establish control of that shard. During the KeyStore reinstantiation of the 
                // MPs we will be disrupting the session.
                session.stop();
                for (int i = 0; i < 100; i++) {
                    ((DisruptibleSession) originalSession).disrupt();
                    Thread.sleep(1);
                }
                // Now we should get back to 100000 Mps.
                poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {

                    @Override
                    public boolean conditionMet(MetricGetters sc) {
                        return 100000 == sc.getMessageProcessorCount();
                    }
                });
                assertEquals(100000, statsCollector.getMessageProcessorCount());
            } finally {
                if (session != null)
                    session.stop();
            }
        }

        public String toString() {
            return "testFailedClusterManagerDuringKeyStoreCalls";
        }

        public void setup() {
            KeySourceImpl.maxcount = 100000;
            System.setProperty("min_nodes_for_cluster", "1");
            System.setProperty("total_slots_for_cluster", "1");
        }
    };
    runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) JunkDestination(com.nokia.dempsy.TestUtils.JunkDestination) ClusterInfoSessionFactory(com.nokia.dempsy.cluster.ClusterInfoSessionFactory) ClusterId(com.nokia.dempsy.config.ClusterId) DisruptibleSession(com.nokia.dempsy.cluster.DisruptibleSession) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) DefaultRouterSlotInfo(com.nokia.dempsy.router.DecentralizedRoutingStrategy.DefaultRouterSlotInfo) MetricGetters(com.nokia.dempsy.monitoring.coda.MetricGetters) Test(org.junit.Test)

Example 4 with ClusterInfoSessionFactory

use of com.nokia.dempsy.cluster.ClusterInfoSessionFactory 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)

Aggregations

ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)4 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)4 ClusterId (com.nokia.dempsy.config.ClusterId)4 Test (org.junit.Test)4 Condition (com.nokia.dempsy.TestUtils.Condition)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 Dempsy (com.nokia.dempsy.Dempsy)2 MetricGetters (com.nokia.dempsy.monitoring.coda.MetricGetters)2 ApplicationContext (org.springframework.context.ApplicationContext)2 JunkDestination (com.nokia.dempsy.TestUtils.JunkDestination)1 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)1 ClusterInfoWatcher (com.nokia.dempsy.cluster.ClusterInfoWatcher)1 DisruptibleSession (com.nokia.dempsy.cluster.DisruptibleSession)1 ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)1 DefaultRouterSlotInfo (com.nokia.dempsy.router.DecentralizedRoutingStrategy.DefaultRouterSlotInfo)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1