Search in sources :

Example 1 with JunkDestination

use of com.nokia.dempsy.TestUtils.JunkDestination 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)

Aggregations

Condition (com.nokia.dempsy.TestUtils.Condition)1 JunkDestination (com.nokia.dempsy.TestUtils.JunkDestination)1 ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)1 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)1 DisruptibleSession (com.nokia.dempsy.cluster.DisruptibleSession)1 ClusterId (com.nokia.dempsy.config.ClusterId)1 MetricGetters (com.nokia.dempsy.monitoring.coda.MetricGetters)1 DefaultRouterSlotInfo (com.nokia.dempsy.router.DecentralizedRoutingStrategy.DefaultRouterSlotInfo)1 Test (org.junit.Test)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1