Search in sources :

Example 1 with ClusterId

use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestMpContainerLoadHandling method setUp.

@Before
public void setUp() throws Exception {
    ClusterId cid = new ClusterId("TestMpContainerLoadHandling", "test" + sequence++);
    dispatcher = new MockDispatcher();
    StatsCollectorCoda sc = new StatsCollectorCoda(cid, new StatsCollectorFactoryCoda().getNamingStrategy());
    stats = sc;
    JavaSerializer<Object> serializer = new JavaSerializer<Object>();
    container = new MpContainer(cid);
    container.setDispatcher(dispatcher);
    container.setStatCollector(sc);
    container.setSerializer(serializer);
    container.setPrototype(new TestMessageProcessor());
    forceOutputException = false;
}
Also used : StatsCollectorCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorCoda) MpContainer(com.nokia.dempsy.container.MpContainer) ClusterId(com.nokia.dempsy.config.ClusterId) JavaSerializer(com.nokia.dempsy.serialization.java.JavaSerializer) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda) Before(org.junit.Before)

Example 2 with ClusterId

use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestStatsCollectorCoda method testEnvPrefixFromSystemProperty.

@Test
public void testEnvPrefixFromSystemProperty() throws Throwable {
    tearDown();
    System.setProperty(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName, "Hello.");
    setUp();
    StatsCollectorFactoryCoda.MetricNamingStrategy strategy = statsCollectorFactory.getNamingStrategy();
    ClusterId clusterId = new ClusterId("app", "cluster");
    MetricName name = strategy.createName(clusterId, "metric");
    assertEquals("metric", name.getName());
    assertEquals("app-cluster", name.getGroup());
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("Hello."));
    // make sure setting the environment prefix doesn't effect the -D option
    statsCollectorFactory.setEnvironmentPrefix("otherEnvPrefix");
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("Hello."));
    // make sure that without the system property the setEnvironmentPrefix value works
    System.getProperties().remove(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName);
    assertTrue(strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("otherEnvPrefix"));
    // make sure that delting the environmentPrefix doesn't create an issue.
    statsCollectorFactory.setEnvironmentPrefix(null);
    strategy.buildPrefix(clusterId, new Destination() {

        @Override
        public String toString() {
            return "destination";
        }
    }).startsWith("otherEnvPrefix");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) Destination(com.nokia.dempsy.messagetransport.Destination) ClusterId(com.nokia.dempsy.config.ClusterId) Test(org.junit.Test)

Example 3 with ClusterId

use of com.nokia.dempsy.config.ClusterId 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 4 with ClusterId

use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestDempsy method runMpKeyStoreTest.

public void runMpKeyStoreTest(final String methodName, final boolean disruptSession) throws Throwable {
    Checker checker = new Checker() {

        @Override
        public void check(ApplicationContext context) throws Throwable {
            // 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");
            // verify we haven't called it again, not that there's really
            // a way to given the code
            assertEquals(1, mp.startCalls.get());
            // wait for clone calls to reach at least 2
            assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {

                @Override
                public boolean conditionMet(TestMp mp) {
                    return mp.cloneCalls.get() == 2;
                }
            }));
            final TestAdaptor adaptor = (TestAdaptor) context.getBean("adaptor");
            // if the session has been disrupted then this may take some time to work again.
            // wait until it works again.
            assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {

                @Override
                public boolean conditionMet(TestMp mp) throws Throwable {
                    // this causes the container to clone the Mp
                    adaptor.pushMessage(new TestMessage("output"));
                    // wait for it to be received.
                    Thread.sleep(100);
                    // this will not go past 3 as long as the same TestMessage is sent.
                    return mp.cloneCalls.get() == 3;
                }
            }));
            // this WONT causes the container to clone the Mp because test1 was already pre-instantiated.
            adaptor.pushMessage(new TestMessage("test1"));
            // give it a little time.
            Thread.sleep(100);
            // wait for it to be received.
            assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {

                @Override
                public boolean conditionMet(TestMp mp) {
                    return mp.cloneCalls.get() == 3;
                }
            }));
            List<Node> nodes = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes();
            Assert.assertNotNull(nodes);
            Assert.assertTrue(nodes.size() > 0);
            Node node = nodes.get(0);
            Assert.assertNotNull(node);
            double duration = ((MetricGetters) node.getStatsCollector()).getPreInstantiationDuration();
            Assert.assertTrue(duration > 0.0);
        }

        public String toString() {
            return methodName;
        }

        @Override
        public void setup() {
            KeySourceImpl.disruptSession = disruptSession;
        }
    };
    runAllCombinations("SinglestageWithKeyStoreApplicationActx.xml", checker);
    runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClusterId(com.nokia.dempsy.config.ClusterId) Node(com.nokia.dempsy.Dempsy.Application.Cluster.Node) MetricGetters(com.nokia.dempsy.monitoring.coda.MetricGetters)

Example 5 with ClusterId

use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestUtils method getStatsCollector.

public static StatsCollector getStatsCollector(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.statsCollector;
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId)

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