Search in sources :

Example 6 with Destination

use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.

the class TcpTransportTest method transportMultipleConnectionsFailedClient.

/**
    * This test checks the various behaviors of a tcp transport when the 
    * client is disrupted at the 5th byte. Multiple senders are started from
    * multiple threads and ONLY ONE fails at the 5th byte. All senders should
    * be able to continue on when that happens and so the message counts should
    * increase.
    */
@Test
public void transportMultipleConnectionsFailedClient() throws Throwable {
    runAllCombinations(new Checker() {

        @Override
        public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            BasicStatsCollector statsCollector = new BasicStatsCollector();
            try {
                //===========================================
                // setup the sender and receiver
                adaptor = new TcpReceiver(null, getFailFast());
                adaptor.setStatsCollector(statsCollector);
                // distruptible sender factory
                factory = makeSenderFactory(true, statsCollector, batchOutgoingMessagesDelayMillis);
                if (port > 0)
                    adaptor.setPort(port);
                if (localhost)
                    adaptor.setUseLocalhost(localhost);
                //===========================================
                // start the adaptor
                adaptor.start();
                // get the destination
                Destination destination = adaptor.getDestination();
                //===========================================
                // Start up sender threads and save the off
                ArrayList<Thread> threadsToJoinOn = new ArrayList<Thread>();
                SenderRunnable[] senders = new SenderRunnable[numThreads];
                for (int i = 0; i < numThreads; i++) threadsToJoinOn.add(i, new Thread(senders[i] = new SenderRunnable(destination, i, factory), "Test Sender for " + i));
                for (Thread thread : threadsToJoinOn) thread.start();
                //===========================================
                //===========================================
                // check that one sender has failed since this is disruptable.
                assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector, new TestUtils.Condition<BasicStatsCollector>() {

                    @Override
                    public boolean conditionMet(BasicStatsCollector o) throws Throwable {
                        return o.getMessagesNotSentCount() > 0;
                    }
                }));
                //===========================================
                //===========================================
                // check that ONLY one failed (the others didn't) when we're not batching. Otherwise
                //  more may fail.
                Thread.sleep(10);
                if (// if we're batching then we only expect a failure but we don't know how many
                batchOutgoingMessagesDelayMillis >= 0)
                    assertTrue(statsCollector.getMessagesNotSentCount() > 0);
                else
                    assertEquals(1, statsCollector.getMessagesNotSentCount());
                //===========================================
                // all of the counts should increase.
                long[] curCounts = new long[numThreads];
                int i = 0;
                for (SenderRunnable sender : senders) curCounts[i++] = sender.sentMessageCount.get();
                // ==========================================
                // go until they are all higher. The Senders should still be running
                // and sending successfully (only one failed once) so all counts should
                // be increasing.
                boolean allHigher = false;
                for (long endTime = System.currentTimeMillis() + numThreads * (baseTimeoutMillis); endTime > System.currentTimeMillis() && !allHigher; ) {
                    allHigher = true;
                    Thread.sleep(1);
                    i = 0;
                    for (SenderRunnable sender : senders) if (curCounts[i++] >= sender.sentMessageCount.get())
                        allHigher = false;
                }
                assertTrue(allHigher);
                // Stop the senders.
                for (SenderRunnable sender : senders) sender.keepGoing.set(false);
                // wait until all threads are stopped
                for (Thread t : threadsToJoinOn) t.join(5000);
                // make sure everything actually stopped.
                for (SenderRunnable sender : senders) assertTrue(sender.isStopped.get());
            // ==========================================
            } finally {
                if (factory != null)
                    factory.stop();
                if (adaptor != null)
                    adaptor.stop();
            }
        }

        @Override
        public String toString() {
            return "transportMultipleConnectionsFailedClient";
        }
    });
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) Destination(com.nokia.dempsy.messagetransport.Destination) ArrayList(java.util.ArrayList) TestUtils(com.nokia.dempsy.TestUtils) SenderFactory(com.nokia.dempsy.messagetransport.SenderFactory) Test(org.junit.Test)

Example 7 with Destination

use of com.nokia.dempsy.messagetransport.Destination 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)

Aggregations

Destination (com.nokia.dempsy.messagetransport.Destination)7 Test (org.junit.Test)5 SenderFactory (com.nokia.dempsy.messagetransport.SenderFactory)4 ClusterId (com.nokia.dempsy.config.ClusterId)3 MessageTransportException (com.nokia.dempsy.messagetransport.MessageTransportException)2 Sender (com.nokia.dempsy.messagetransport.Sender)2 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)2 BasicStatsCollector (com.nokia.dempsy.monitoring.basic.BasicStatsCollector)2 Dempsy (com.nokia.dempsy.Dempsy)1 TestUtils (com.nokia.dempsy.TestUtils)1 ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)1 LocalClusterSessionFactory (com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory)1 ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)1 ClusterDefinition (com.nokia.dempsy.config.ClusterDefinition)1 Listener (com.nokia.dempsy.messagetransport.Listener)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1 ClusterRouter (com.nokia.dempsy.router.Router.ClusterRouter)1 Inbound (com.nokia.dempsy.router.RoutingStrategy.Inbound)1 Histogram (com.yammer.metrics.core.Histogram)1 MetricName (com.yammer.metrics.core.MetricName)1