Search in sources :

Example 1 with ApplicationDefinition

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

the class TestRouterInstantiation method testDispatchBadMessage.

@Test
public void testDispatchBadMessage() throws Throwable {
    ApplicationDefinition app = new ApplicationDefinition("test");
    Router router = new Router(app);
    Object o;
    router.dispatch(o = new Object() {

        @MessageKey
        public String getKey() {
            return "hello";
        }
    });
    assertTrue(router.stopTryingToSendTheseTypes.contains(o.getClass()));
    MessageThatFailsOnKeyRetrieve message = new MessageThatFailsOnKeyRetrieve();
    router.dispatch(message);
    assertTrue(message.threw);
    // this should just warn
    router.dispatch(null);
}
Also used : ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) Test(org.junit.Test)

Example 2 with ApplicationDefinition

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

the class TestRouterInstantiation method testGetMessages.

@Test
public void testGetMessages() throws Throwable {
    ApplicationDefinition app = new ApplicationDefinition("test");
    Router router = new Router(app);
    List<Object> messages = new ArrayList<Object>();
    Object first = new Object();
    router.getMessages(first, messages);
    Assert.assertEquals(1, messages.size());
    Assert.assertSame(first, messages.get(0));
}
Also used : ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ApplicationDefinition

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

the class TestFullApp method testSeparateClustersInOneVm.

@Test
public void testSeparateClustersInOneVm() throws Throwable {
    // now start each cluster
    ctx[0] = "fullApp/Dempsy-FullUp.xml";
    Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>();
    try {
        ApplicationDefinition ad = new FullApplication().getTopology();
        ad.initialize();
        List<ClusterDefinition> clusters = ad.getClusterDefinitions();
        for (int i = clusters.size() - 1; i >= 0; i--) {
            ClusterDefinition cluster = clusters.get(i);
            CheckCluster.toCheckAgainst = cluster.getClusterId();
            DempsyHolder cur = new DempsyHolder();
            cur.clusterid = cluster.getClusterId();
            cur.actx = new ClassPathXmlApplicationContext(ctx);
            cur.actx.registerShutdownHook();
            cur.dempsy = (Dempsy) cur.actx.getBean("dempsy");
            cur.dempsy.start();
            dempsys.put(cluster.getClusterId(), cur);
        }
        // get the last FullApplication in the processing chain.
        ClassPathXmlApplicationContext actx = dempsys.get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx;
        final FullApplication app = (FullApplication) actx.getBean("app");
        // this checks that the throughput works.
        assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {

            @Override
            public boolean conditionMet(Object o) {
                return app.finalMessageCount.get() > 100;
            }
        }));
    } finally {
        ctx[0] = dempsyConfig;
        for (DempsyHolder cur : dempsys.values()) {
            cur.dempsy.stop();
            cur.actx.close();
        }
    }
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) ClusterDefinition(com.nokia.dempsy.config.ClusterDefinition) HashMap(java.util.HashMap) ClusterId(com.nokia.dempsy.config.ClusterId) ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MyRankMp(com.nokia.dempsy.cluster.zookeeper.FullApplication.MyRankMp) Test(org.junit.Test)

Example 4 with ApplicationDefinition

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

the class TestZookeeperClusterResilience method getDempsyFor.

private static Dempsy getDempsyFor(ClusterId clusterId, ApplicationDefinition ad) throws Throwable {
    //------------------------------------------------------------------------------
    // here is a complete non-spring, non-DI Dempsy instantiation
    //------------------------------------------------------------------------------
    List<ApplicationDefinition> ads = new ArrayList<ApplicationDefinition>();
    ads.add(ad);
    Dempsy dempsy = new Dempsy();
    dempsy.setApplicationDefinitions(ads);
    dempsy.setClusterCheck(new SpecificClusterCheck(clusterId));
    dempsy.setDefaultRoutingStrategy(new DecentralizedRoutingStrategy(20, 1));
    dempsy.setDefaultSerializer(new JavaSerializer<Object>());
    dempsy.setDefaultStatsCollectorFactory(new StatsCollectorFactoryCoda());
    dempsy.setDefaultTransport(new TcpTransport());
    return dempsy;
}
Also used : DecentralizedRoutingStrategy(com.nokia.dempsy.router.DecentralizedRoutingStrategy) ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) SpecificClusterCheck(com.nokia.dempsy.router.SpecificClusterCheck) Dempsy(com.nokia.dempsy.Dempsy) ArrayList(java.util.ArrayList) TcpTransport(com.nokia.dempsy.messagetransport.tcp.TcpTransport) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)

Example 5 with ApplicationDefinition

use of com.nokia.dempsy.config.ApplicationDefinition 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)

Aggregations

ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)9 Test (org.junit.Test)6 Dempsy (com.nokia.dempsy.Dempsy)4 ClusterId (com.nokia.dempsy.config.ClusterId)4 Condition (com.nokia.dempsy.TestUtils.Condition)3 ClusterDefinition (com.nokia.dempsy.config.ClusterDefinition)3 ArrayList (java.util.ArrayList)3 ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)2 MyRankMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyRankMp)2 HashMap (java.util.HashMap)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)1 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)1 ClusterInfoWatcher (com.nokia.dempsy.cluster.ClusterInfoWatcher)1 LocalClusterSessionFactory (com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory)1 MyMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyMp)1 Destination (com.nokia.dempsy.messagetransport.Destination)1 TcpTransport (com.nokia.dempsy.messagetransport.tcp.TcpTransport)1 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1