Search in sources :

Example 6 with Node

use of net.dempsy.config.Node in project Dempsy by Dempsy.

the class TestSimple method testSimple.

@Test
public void testSimple() throws Exception {
    final AtomicLong count = new AtomicLong(0L);
    try (final NodeManager nm = new NodeManager();
        final DefaultThreadingModel tm = new DefaultThreadingModel("TB", -1, 1)) {
        final Node n = new Node.Builder("test-app").defaultRoutingStrategyId("net.dempsy.router.simple").receiver(new Dummy()).cluster("start").adaptor(new Adaptor() {

            private Dispatcher disp;

            boolean done = false;

            @Override
            public void stop() {
                done = true;
            }

            @Override
            public void start() {
                try {
                    while (!done) {
                        disp.dispatch(new KeyedMessageWithType(Integer.valueOf(1), "Hello", "string"));
                        // This is here for when the Container has a max pending and it gets starved for CPU cycles
                        // in this particular test.
                        Thread.yield();
                    }
                } catch (final InterruptedException ie) {
                    if (!done)
                        LOGGER.error("Interrupted but not stopping.");
                }
            }

            @Override
            public void setDispatcher(final Dispatcher dispatcher) {
                this.disp = dispatcher;
            }
        }).cluster("mp").mp(new MessageProcessor(MpFactory.make(() -> new Mp() {

            @Override
            public KeyedMessageWithType[] handle(final KeyedMessage message) {
                count.incrementAndGet();
                return null;
            }
        }, "string"))).build();
        nm.node(n).collaborator(new LocalClusterSessionFactory().createSession()).threadingModel(tm.start("nodeid"));
        nm.start();
        assertTrue(ConditionPoll.poll(o -> count.get() > 100000));
    }
}
Also used : Adaptor(net.dempsy.messages.Adaptor) Logger(org.slf4j.Logger) Node(net.dempsy.config.Node) MessageProcessor(net.dempsy.lifecycle.simple.MessageProcessor) Mp(net.dempsy.lifecycle.simple.Mp) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) NodeAddress(net.dempsy.transport.NodeAddress) Listener(net.dempsy.transport.Listener) LoggerFactory(org.slf4j.LoggerFactory) KeyedMessage(net.dempsy.messages.KeyedMessage) Assert.assertTrue(org.junit.Assert.assertTrue) ConditionPoll(net.dempsy.utils.test.ConditionPoll) Test(org.junit.Test) MpFactory(net.dempsy.lifecycle.simple.MpFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) Adaptor(net.dempsy.messages.Adaptor) MessageTransportException(net.dempsy.transport.MessageTransportException) Receiver(net.dempsy.transport.Receiver) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Mp(net.dempsy.lifecycle.simple.Mp) Node(net.dempsy.config.Node) MessageProcessor(net.dempsy.lifecycle.simple.MessageProcessor) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Dispatcher(net.dempsy.messages.Dispatcher) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) AtomicLong(java.util.concurrent.atomic.AtomicLong) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) KeyedMessage(net.dempsy.messages.KeyedMessage) Test(org.junit.Test)

Aggregations

Node (net.dempsy.config.Node)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 List (java.util.List)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 LocalClusterSessionFactory (net.dempsy.cluster.local.LocalClusterSessionFactory)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Arrays (java.util.Arrays)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Adaptor (net.dempsy.messages.Adaptor)4 Functional.uncheck (net.dempsy.util.Functional.uncheck)4 RunWith (org.junit.runner.RunWith)4 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 ClusterId (net.dempsy.config.ClusterId)3 NonLockingAltContainer (net.dempsy.container.altnonlocking.NonLockingAltContainer)3 LockingContainer (net.dempsy.container.locking.LockingContainer)3 Dispatcher (net.dempsy.messages.Dispatcher)3