Search in sources :

Example 1 with MpContainer

use of com.nokia.dempsy.container.MpContainer 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 MpContainer

use of com.nokia.dempsy.container.MpContainer in project Dempsy by Dempsy.

the class TestDempsy method testOverlappingKeyStoreCalls.

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

        @Override
        public void check(ApplicationContext context) throws Throwable {
            // wait until the KeySourceImpl has been created
            assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {

                @Override
                public boolean conditionMet(Object mp) {
                    return KeySourceImpl.lastCreated != null;
                }
            }));
            final KeySourceImpl.KSIterable firstCreated = KeySourceImpl.lastCreated;
            // 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");
            Dempsy.Application.Cluster c = dempsy.getCluster(new ClusterId("test-app", "test-cluster1"));
            assertNotNull(c);
            Dempsy.Application.Cluster.Node node = c.getNodes().get(0);
            assertNotNull(node);
            MpContainer container = node.getMpContainer();
            // let it go and wait until there's a few keys.
            firstCreated.m_pause.countDown();
            // as the KeySource iterates, this will increase
            assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {

                @Override
                public boolean conditionMet(TestMp mp) {
                    return mp.cloneCalls.get() > 10000;
                }
            }));
            // prepare the next countdown latch
            // just let the 2nd one go
            KeySourceImpl.pause = new CountDownLatch(0);
            // I want the next one to stop at 2
            KeySourceImpl.infinite = false;
            // Now force another call while the first is running
            container.keyspaceResponsibilityChanged(node.strategyInbound, false, true);
            // wait until the second one is created
            assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {

                @Override
                public boolean conditionMet(Object mp) {
                    return KeySourceImpl.lastCreated != null && firstCreated != KeySourceImpl.lastCreated;
                }
            }));
            // now the first one should be done and therefore no longer incrementing.
            String lastKeyOfFirstCreated = firstCreated.lastKey;
            // and the second one should be done also and stopped at 2.
            final KeySourceImpl.KSIterable secondCreated = KeySourceImpl.lastCreated;
            assertTrue(firstCreated != secondCreated);
            assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {

                @Override
                public boolean conditionMet(Object mp) {
                    return "test2".equals(secondCreated.lastKey);
                }
            }));
            Thread.sleep(50);
            // make sure the first one isn't still moving on
            assertEquals(lastKeyOfFirstCreated, firstCreated.lastKey);
            assertEquals("test2", secondCreated.lastKey);
            // prepare for the next run
            KeySourceImpl.pause = new CountDownLatch(1);
            KeySourceImpl.infinite = true;
            KeySourceImpl.lastCreated = null;
        }

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

        public void setup() {
            KeySourceImpl.pause = new CountDownLatch(1);
            KeySourceImpl.infinite = true;
            KeySourceImpl.lastCreated = null;
        }
    };
    runAllCombinations("SinglestageWithKeyStoreApplicationActx.xml", checker);
    runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) MpContainer(com.nokia.dempsy.container.MpContainer) ClusterId(com.nokia.dempsy.config.ClusterId) CountDownLatch(java.util.concurrent.CountDownLatch) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Node(com.nokia.dempsy.Dempsy.Application.Cluster.Node) Test(org.junit.Test)

Aggregations

ClusterId (com.nokia.dempsy.config.ClusterId)2 MpContainer (com.nokia.dempsy.container.MpContainer)2 Node (com.nokia.dempsy.Dempsy.Application.Cluster.Node)1 Condition (com.nokia.dempsy.TestUtils.Condition)1 StatsCollectorCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorCoda)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1 JavaSerializer (com.nokia.dempsy.serialization.java.JavaSerializer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1