Search in sources :

Example 31 with ClusterId

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

the class TcpTransportTest method testTransportInstantiation.

/**
    * Just send a simple message and make sure it gets through.
    */
@Test
public void testTransportInstantiation() throws Throwable {
    final AtomicBoolean batchedAtLeastOnce = new AtomicBoolean(false);
    runAllCombinations(new Checker() {

        @Override
        public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination() {
            });
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            try {
                boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
                if (shouldBatch)
                    batchedAtLeastOnce.set(true);
                TcpTransport transport = new TcpTransport();
                transport.setFailFast(getFailFast());
                // by default batching isn't disabled.
                assertFalse(transport.isBatchingDisabled());
                if (!shouldBatch)
                    transport.setDisableBatching(true);
                if (!shouldBatch)
                    assertTrue(transport.isBatchingDisabled());
                assertEquals(!shouldBatch, transport.isBatchingDisabled());
                //===========================================
                // setup the sender and receiver
                adaptor = (TcpReceiver) transport.createInbound(null);
                adaptor.setStatsCollector(statsCollector);
                StringListener receiver = new StringListener();
                adaptor.setListener(receiver);
                factory = transport.createOutbound(null, statsCollector);
                if (port > 0)
                    adaptor.setPort(port);
                if (localhost)
                    adaptor.setUseLocalhost(localhost);
                //===========================================
                // start the adaptor
                adaptor.start();
                // get the destination
                Destination destination = adaptor.getDestination();
                // send a message
                byte[] messageBytes = "Hello".getBytes();
                Sender sender = factory.getSender(destination);
                assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender) sender).getBatchOutgoingMessagesDelayMillis());
                sender.send(messageBytes);
                sender.send(messageBytes);
                // wait for it to be received.
                for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2; ) Thread.sleep(1);
                assertEquals(2, receiver.numMessages.get());
                // verify everything came over ok.
                assertEquals(1, receiver.receivedStringMessages.size());
                assertEquals("Hello", receiver.receivedStringMessages.iterator().next());
                if (shouldBatch) {
                    // verify the histogram
                    Histogram histogram = ((TcpSender) sender).getBatchingHistogram();
                    assertEquals(calcMean(2), histogram.mean(), 0.0000001);
                    assertEquals(1, histogram.count());
                }
            } finally {
                if (factory != null)
                    factory.stop();
                if (adaptor != null)
                    adaptor.stop();
            }
        }

        @Override
        public String toString() {
            return "testTransportInstantiation";
        }
    });
    assertTrue(batchedAtLeastOnce.get());
}
Also used : Destination(com.nokia.dempsy.messagetransport.Destination) Histogram(com.yammer.metrics.core.Histogram) ClusterId(com.nokia.dempsy.config.ClusterId) StatsCollector(com.nokia.dempsy.monitoring.StatsCollector) BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) Sender(com.nokia.dempsy.messagetransport.Sender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SenderFactory(com.nokia.dempsy.messagetransport.SenderFactory) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda) Test(org.junit.Test)

Example 32 with ClusterId

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

the class TestRouterClusterManagement method testChangingClusterInfo.

@Test
public void testChangingClusterInfo() throws Throwable {
    // check that the message didn't go through.
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/ClusterInfo-LocalActx.xml", "testDempsy/Serializer-KryoActx.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml");
    Dempsy dempsy = (Dempsy) context.getBean("dempsy");
    ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
    ClusterInfoSession session = factory.createSession();
    ClusterId curCluster = new ClusterId("test-app", "test-cluster1");
    TestUtils.createClusterLevel(curCluster, session);
    session.setData(curCluster.asPath(), new DecentralizedRoutingStrategy.DefaultRouterClusterInfo(20, 2));
    session.stop();
    dempsy.stop();
}
Also used : ClusterInfoSessionFactory(com.nokia.dempsy.cluster.ClusterInfoSessionFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(com.nokia.dempsy.config.ClusterId) Dempsy(com.nokia.dempsy.Dempsy) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) Test(org.junit.Test)

Example 33 with ClusterId

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

the class TestRouterClusterManagement method init.

@Before
public void init() throws Throwable {
    onodes = System.setProperty("min_nodes_for_cluster", "1");
    oslots = System.setProperty("total_slots_for_cluster", "20");
    final ClusterId clusterId = new ClusterId("test", "test-slot");
    Destination destination = new Destination() {
    };
    ApplicationDefinition app = new ApplicationDefinition(clusterId.getApplicationName());
    DecentralizedRoutingStrategy strategy = new DecentralizedRoutingStrategy(1, 1);
    app.setRoutingStrategy(strategy);
    app.setSerializer(new JavaSerializer<Object>());
    ClusterDefinition cd = new ClusterDefinition(clusterId.getMpClusterName());
    cd.setMessageProcessorPrototype(new GoodTestMp());
    app.add(cd);
    app.initialize();
    LocalClusterSessionFactory mpfactory = new LocalClusterSessionFactory();
    ClusterInfoSession session = mpfactory.createSession();
    TestUtils.createClusterLevel(clusterId, session);
    // fake the inbound side setup
    inbound = strategy.createInbound(session, clusterId, new Dempsy() {

        public List<Class<?>> gm(ClusterDefinition clusterDef) {
            return super.getAcceptedMessages(clusterDef);
        }
    }.gm(cd), destination, new RoutingStrategy.Inbound.KeyspaceResponsibilityChangeListener() {

        @Override
        public void keyspaceResponsibilityChanged(Inbound inbound, boolean less, boolean more) {
        }
    });
    routerFactory = new Router(app);
    routerFactory.setClusterSession(session);
    routerFactory.setCurrentCluster(clusterId);
    routerFactory.initialize();
}
Also used : Destination(com.nokia.dempsy.messagetransport.Destination) ClusterDefinition(com.nokia.dempsy.config.ClusterDefinition) ClusterId(com.nokia.dempsy.config.ClusterId) Dempsy(com.nokia.dempsy.Dempsy) LocalClusterSessionFactory(com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory) ClusterRouter(com.nokia.dempsy.router.Router.ClusterRouter) Inbound(com.nokia.dempsy.router.RoutingStrategy.Inbound) ApplicationDefinition(com.nokia.dempsy.config.ApplicationDefinition) ClusterInfoSession(com.nokia.dempsy.cluster.ClusterInfoSession) List(java.util.List) Before(org.junit.Before)

Example 34 with ClusterId

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

the class TestRouterClusterManagement method testGetRouterFound.

@Test
public void testGetRouterFound() {
    Set<ClusterRouter> routers = routerFactory.getRouter(java.lang.Exception.class);
    Assert.assertNotNull(routers);
    Assert.assertEquals(false, routerFactory.missingMsgTypes.containsKey(java.lang.Exception.class));
    Set<ClusterRouter> routers1 = routerFactory.getRouter(ClassNotFoundException.class);
    Assert.assertEquals(routers, routers1);
    Assert.assertEquals(new ClusterId("test", "test-slot"), routerFactory.getThisClusterId());
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) ClusterRouter(com.nokia.dempsy.router.Router.ClusterRouter) 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