Search in sources :

Example 16 with ClusterId

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

the class TestMpContainer method testConfiguration.

//----------------------------------------------------------------------------
//  Test Cases
//----------------------------------------------------------------------------
@Test
public void testConfiguration() throws Exception {
    // this assertion is superfluous, since we deref container in setUp()
    assertNotNull("did not create container", container);
    assertEquals(new ClusterId("test", "test"), container.getClusterId());
    TestProcessor prototype = context.getBean(TestProcessor.class);
    assertEquals(1, prototype.startCalled.get());
    assertNotNull(prototype.clusterId);
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) Test(org.junit.Test)

Example 17 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 18 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 19 with ClusterId

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

the class Router method initialize.

/**
    * Prior to the {@link Router} being used it needs to be initialized.
    */
public void initialize() throws ClusterInfoException, DempsyException {
    // applicationDefinition cannot be null because the constructor checks
    // put all of the cluster definitions into a map for easy lookup
    Map<ClusterId, ClusterDefinition> defs = new HashMap<ClusterId, ClusterDefinition>();
    for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) defs.put(clusterDef.getClusterId(), clusterDef);
    // now see about the one that we are.
    ClusterDefinition currentClusterDef = null;
    if (currentCluster != null) {
        currentClusterDef = defs.get(currentCluster);
        if (currentClusterDef == null)
            throw new DempsyException("This Dempsy instance seems to be misconfigured. While this VM thinks it's an instance of " + currentCluster + " the application it's configured with doesn't contain this cluster definition. The application configuration consists of: " + applicationDefinition);
    }
    // get the set of explicit destinations if they exist
    Set<ClusterId> explicitClusterDestinations = (currentClusterDef != null && currentClusterDef.hasExplicitDestinations()) ? new HashSet<ClusterId>() : null;
    if (explicitClusterDestinations != null)
        explicitClusterDestinations.addAll(Arrays.asList(currentClusterDef.getDestinations()));
    //  then those are the only ones we want to consider
    for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) {
        if ((explicitClusterDestinations == null || explicitClusterDestinations.contains(clusterDef.getClusterId())) && !clusterDef.isRouteAdaptorType()) {
            RoutingStrategy strategy = (RoutingStrategy) clusterDef.getRoutingStrategy();
            ClusterId clusterId = clusterDef.getClusterId();
            if (strategy == null)
                throw new DempsyException("Could not retrieve the routing strategy for " + SafeString.valueOf(clusterId));
            // This create will result in a callback on the Router as the Outbound.Coordinator with a 
            // registration event. The Outbound may (will) call back on the Router to retrieve the 
            // MpClusterSession and register itself with the appropriate cluster.
            outbounds.add(strategy.createOutbound(this, mpClusterSession, clusterId));
        }
    }
//-------------------------------------------------------------------------------------
}
Also used : ClusterDefinition(com.nokia.dempsy.config.ClusterDefinition) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterId(com.nokia.dempsy.config.ClusterId) DempsyException(com.nokia.dempsy.DempsyException)

Example 20 with ClusterId

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

the class TestDempsy method testForkedFailure.

@Test
public void testForkedFailure() throws Throwable {
    runAllCombinations("SimpleMultistageApplicationActx.xml", new Checker() {

        @Override
        public void check(ApplicationContext context) throws Throwable {
            final AtomicBoolean stopIt = new AtomicBoolean(false);
            final AtomicBoolean failed = new AtomicBoolean(false);
            final AtomicBoolean stopped = new AtomicBoolean(false);
            try {
                // start things and verify that the init method was called
                Dempsy dempsy = (Dempsy) context.getBean("dempsy");
                final TestAdaptor adaptor = (TestAdaptor) getAdaptor(dempsy, "test-app", "test-cluster0");
                assertNotNull(adaptor);
                Thread adaptorThread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            long i = 0;
                            while (!stopIt.get()) {
                                adaptor.pushMessage(new TestMessage("" + i));
                                i++;
                                Thread.sleep(10);
                            }
                        } catch (Throwable th) {
                            failed.set(true);
                        } finally {
                            stopped.set(true);
                        }
                    }
                }, "testForkedFailure-Adaptor Thread ");
                adaptorThread.start();
                TestMp[] mps = new TestMp[3];
                DisruptibleSession[] sessions = new DisruptibleSession[3];
                for (int i = 0; i < mps.length; i++) {
                    String cluster = "test-cluster" + (i + 1);
                    mps[i] = (TestMp) getMp(dempsy, "test-app", cluster);
                    sessions[i] = (DisruptibleSession) (dempsy.getCluster(new ClusterId("test-app", cluster)).getNodes().get(0).retouRteg().getClusterSession());
                    assertEquals(1, mps[i].startCalls.get());
                }
                for (int i = 0; i < mps.length; i++) {
                    for (int j = 0; j < mps.length; j++) {
                        if (i != j)
                            assertTrue(mps[i] != mps[j]);
                    }
                }
                // now check to see that data is going to all 3.
                for (int i = 0; i < mps.length; i++) {
                    assertTrue(poll(baseTimeoutMillis, mps[i], new Condition<TestMp>() {

                        public boolean conditionMet(TestMp o) {
                            return o.handleCalls.get() > 0;
                        }
                    }));
                }
                int curPos = 0;
                for (int j = 0; j < 3; j++) {
                    // now kill a cluster or 2 (or 3)
                    for (int k = 0; k <= j; k++) sessions[curPos++ % sessions.length].disrupt();
                    for (int i = 0; i < mps.length; i++) {
                        final long curCalls = mps[i].handleCalls.get();
                        assertTrue(poll(baseTimeoutMillis, mps[i], new Condition<TestMp>() {

                            public boolean conditionMet(TestMp o) {
                                return o.handleCalls.get() > curCalls;
                            }
                        }));
                    }
                }
            } finally {
                stopIt.set(true);
                assertFalse(failed.get());
                assertTrue(poll(baseTimeoutMillis, stopped, new Condition<AtomicBoolean>() {

                    public boolean conditionMet(AtomicBoolean o) {
                        return o.get();
                    }
                }));
            }
        }

        public String toString() {
            return "testForkedFailure";
        }
    });
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) DisruptibleSession(com.nokia.dempsy.cluster.DisruptibleSession) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

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