Search in sources :

Example 6 with Mp

use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.

the class TestContainer method createAndGet.

private TestProcessor createAndGet(final String foo) throws Exception {
    cache = new HashMap<>();
    final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
    assertNotNull(adaptor.dispatcher);
    adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage(foo));
    assertTrue(poll(o -> container.getProcessorCount() > 0));
    Thread.sleep(100);
    assertEquals("did not create MP", 1, container.getProcessorCount());
    assertTrue(poll(cache, c -> c.get(foo) != null));
    final TestProcessor mp = cache.get(foo);
    assertNotNull("MP not associated with expected key", mp);
    assertEquals("activation count, 1st message", 1, mp.activationCount);
    assertEquals("invocation count, 1st message", 1, mp.invocationCount);
    return mp;
}
Also used : Arrays(java.util.Arrays) Node(net.dempsy.config.Node) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Collection(java.util.Collection) Operation(net.dempsy.container.Container.Operation) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) LockingContainer(net.dempsy.container.locking.LockingContainer) OutputMessage(net.dempsy.container.mocks.OutputMessage) Output(net.dempsy.lifecycle.annotation.Output) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) AccessUtil.canReach(net.dempsy.AccessUtil.canReach) Start(net.dempsy.lifecycle.annotation.Start) Assert.assertFalse(org.junit.Assert.assertFalse) Evictable(net.dempsy.lifecycle.annotation.Evictable) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) AccessUtil.getRouter(net.dempsy.AccessUtil.getRouter) Mp(net.dempsy.lifecycle.annotation.Mp) BlockingQueueReceiver(net.dempsy.transport.blockingqueue.BlockingQueueReceiver) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DempsyException(net.dempsy.DempsyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Functional.recheck(net.dempsy.util.Functional.recheck) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessage(net.dempsy.messages.KeyedMessage) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterStatsCollector(net.dempsy.monitoring.ClusterStatsCollector) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage)

Example 7 with Mp

use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.

the class TestContainer method testMtInvokeOutput.

@Test
public void testMtInvokeOutput() throws Exception {
    outputMessages = Collections.newSetFromMap(new ConcurrentHashMap<>());
    final int numInstances = 20;
    final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
    assertNotNull(adaptor.dispatcher);
    for (int i = 0; i < numInstances; i++) {
        adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo" + i));
        // help the container when it has a limited queue
        Thread.yield();
    }
    assertTrue(poll(container, c -> (c.getProcessorCount() + ((ClusterMetricGetters) c.statCollector).getMessageDiscardedCount()) > 19));
    Thread.sleep(100);
    final long messagesDiscarded = ((ClusterMetricGetters) container.statCollector).getMessageDiscardedCount();
    assertEquals("number of MP instances", 20, container.getProcessorCount() + messagesDiscarded);
    try (NodeManager nman = addOutputCatchStage()) {
        container.outputPass();
        assertTrue(poll(outputMessages, o -> (o.size() + messagesDiscarded) > 19));
        Thread.sleep(100);
        assertEquals(20, outputMessages.size() + messagesDiscarded);
    }
}
Also used : Arrays(java.util.Arrays) Node(net.dempsy.config.Node) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Collection(java.util.Collection) Operation(net.dempsy.container.Container.Operation) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) LockingContainer(net.dempsy.container.locking.LockingContainer) OutputMessage(net.dempsy.container.mocks.OutputMessage) Output(net.dempsy.lifecycle.annotation.Output) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) AccessUtil.canReach(net.dempsy.AccessUtil.canReach) Start(net.dempsy.lifecycle.annotation.Start) Assert.assertFalse(org.junit.Assert.assertFalse) Evictable(net.dempsy.lifecycle.annotation.Evictable) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) AccessUtil.getRouter(net.dempsy.AccessUtil.getRouter) Mp(net.dempsy.lifecycle.annotation.Mp) BlockingQueueReceiver(net.dempsy.transport.blockingqueue.BlockingQueueReceiver) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DempsyException(net.dempsy.DempsyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Functional.recheck(net.dempsy.util.Functional.recheck) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessage(net.dempsy.messages.KeyedMessage) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterStatsCollector(net.dempsy.monitoring.ClusterStatsCollector) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 8 with Mp

use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.

the class TestContainer method testInvokeOutput.

@Test
public void testInvokeOutput() throws Exception {
    outputMessages = Collections.newSetFromMap(new ConcurrentHashMap<>());
    cache = new ConcurrentHashMap<>();
    final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
    assertNotNull(adaptor.dispatcher);
    adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
    adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("bar"));
    assertTrue(poll(container, c -> (c.getProcessorCount() + ((ClusterMetricGetters) c.statCollector).getMessageDiscardedCount()) > 1));
    Thread.sleep(100);
    assertEquals("number of MP instances", 2, container.getProcessorCount());
    try (NodeManager nman = addOutputCatchStage()) {
        final TestProcessor mp = cache.get("foo");
        assertTrue(poll(mp, m -> mp.invocationCount > 0));
        Thread.sleep(100);
        assertEquals("invocation count, 1st message", 1, mp.invocationCount);
        // because the sessionFactory is shared and the appname is the same, we should be in the same app
        container.outputPass();
        assertTrue(poll(outputMessages, o -> o.size() > 1));
        Thread.sleep(100);
        assertEquals(2, outputMessages.size());
        // no new mps created in the first one
        assertEquals("did not create MP", 2, container.getProcessorCount());
        // but the invocation count should have increased since the output cycles feeds messages back to this cluster
        assertTrue(poll(mp, m -> mp.invocationCount > 1));
        Thread.sleep(100);
        assertEquals("invocation count, 1st message", 2, mp.invocationCount);
        // // order of messages is not guaranteed, so we need to aggregate keys
        final HashSet<String> messageKeys = new HashSet<String>();
        final Iterator<OutputMessage> iter = outputMessages.iterator();
        messageKeys.add(iter.next().getKey());
        messageKeys.add(iter.next().getKey());
        assertTrue("first MP sent output", messageKeys.contains("foo"));
        assertTrue("second MP sent output", messageKeys.contains("bar"));
    }
}
Also used : Arrays(java.util.Arrays) Node(net.dempsy.config.Node) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Collection(java.util.Collection) Operation(net.dempsy.container.Container.Operation) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) LockingContainer(net.dempsy.container.locking.LockingContainer) OutputMessage(net.dempsy.container.mocks.OutputMessage) Output(net.dempsy.lifecycle.annotation.Output) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) AccessUtil.canReach(net.dempsy.AccessUtil.canReach) Start(net.dempsy.lifecycle.annotation.Start) Assert.assertFalse(org.junit.Assert.assertFalse) Evictable(net.dempsy.lifecycle.annotation.Evictable) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) AccessUtil.getRouter(net.dempsy.AccessUtil.getRouter) Mp(net.dempsy.lifecycle.annotation.Mp) BlockingQueueReceiver(net.dempsy.transport.blockingqueue.BlockingQueueReceiver) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DempsyException(net.dempsy.DempsyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Functional.recheck(net.dempsy.util.Functional.recheck) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessage(net.dempsy.messages.KeyedMessage) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterStatsCollector(net.dempsy.monitoring.ClusterStatsCollector) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NodeManager(net.dempsy.NodeManager) OutputMessage(net.dempsy.container.mocks.OutputMessage) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Mp

use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.

the class TestContainer method testEvictCollisionWithBlocking.

@Test
public void testEvictCollisionWithBlocking() throws Throwable {
    final TestProcessor mp = createAndGet("foo");
    // now we're going to cause the passivate to be held up.
    mp.blockPassivate = new CountDownLatch(1);
    // allow eviction
    mp.evict.set(true);
    // now kick off the evict in a separate thread since we expect it to hang
    // until the mp becomes unstuck.
    // this will allow us to see the evict pass complete
    final AtomicBoolean evictIsComplete = new AtomicBoolean(false);
    final Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            container.evict();
            evictIsComplete.set(true);
        }
    });
    thread.start();
    // let it get going.
    Thread.sleep(500);
    // check to see we're hung.
    assertFalse(evictIsComplete.get());
    final ClusterMetricGetters sc = (ClusterMetricGetters) statsCollector;
    assertEquals(0, sc.getMessageCollisionCount());
    // sending it a message will now cause it to have the collision tick up
    final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
    adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
    // give it some time.
    Thread.sleep(100);
    // make sure there's no collision
    assertEquals(0, sc.getMessageCollisionCount());
    // make sure no message got handled
    // 1 is the initial invocation that caused the instantiation.
    assertEquals(1, mp.invocationCount);
    // now let the evict finish
    mp.blockPassivate.countDown();
    // wait until the eviction completes
    assertTrue(poll(evictIsComplete, o -> o.get()));
    // Once the poll finishes a new Mp is instantiated and handling messages.
    assertTrue(poll(cache, c -> c.get("foo") != null));
    final TestProcessor mp2 = cache.get("foo");
    assertNotNull("MP not associated with expected key", mp);
    // invocationCount should be 1 from the initial invocation that caused the clone, and no more
    assertEquals(1, mp.invocationCount);
    assertEquals(1, mp2.invocationCount);
    assertTrue(mp != mp2);
    // send a message that should go through
    adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
    assertTrue(poll(o -> mp2.invocationCount > 1));
    Thread.sleep(100);
    assertEquals(1, mp.invocationCount);
    assertEquals(2, mp2.invocationCount);
}
Also used : Arrays(java.util.Arrays) Node(net.dempsy.config.Node) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Collection(java.util.Collection) Operation(net.dempsy.container.Container.Operation) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) LockingContainer(net.dempsy.container.locking.LockingContainer) OutputMessage(net.dempsy.container.mocks.OutputMessage) Output(net.dempsy.lifecycle.annotation.Output) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) AccessUtil.canReach(net.dempsy.AccessUtil.canReach) Start(net.dempsy.lifecycle.annotation.Start) Assert.assertFalse(org.junit.Assert.assertFalse) Evictable(net.dempsy.lifecycle.annotation.Evictable) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) AccessUtil.getRouter(net.dempsy.AccessUtil.getRouter) Mp(net.dempsy.lifecycle.annotation.Mp) BlockingQueueReceiver(net.dempsy.transport.blockingqueue.BlockingQueueReceiver) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DempsyException(net.dempsy.DempsyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Functional.recheck(net.dempsy.util.Functional.recheck) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessage(net.dempsy.messages.KeyedMessage) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterStatsCollector(net.dempsy.monitoring.ClusterStatsCollector) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with Mp

use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.

the class TestElasticity method testForProfiler.

@Test
public void testForProfiler() throws Throwable {
    try {
        // set up the test.
        final Number[] numbers = new Number[profilerTestNumberCount];
        final Random random = new Random();
        for (int i = 0; i < numbers.length; i++) numbers[i] = new Number(random.nextInt(1000), 0);
        final KeyExtractor ke = new KeyExtractor();
        runCombos("testForProfiler", (r, c, s, t, ser) -> isElasticRoutingStrategy(r), actxPath, new String[][][] { null, { { "min_nodes", "3" } }, { { "min_nodes", "3" } }, { { "min_nodes", "3" } }, null }, ns -> {
            final List<NodeManagerWithContext> nodes = ns.nodes;
            // Grab the one NumberRank Mp from the single Node in the third (0 base 2nd) cluster.
            final NumberRank rank = nodes.get(4).ctx.getBean(NumberRank.class);
            try (final ClusterInfoSession session = ns.sessionFactory.createSession()) {
                waitForEvenShardDistribution(session, "test-cluster1", 3, nodes);
                // get the Adaptor Router's statCollector
                final List<NodeMetricGetters> scs = nodes.stream().map(nwm -> nwm.manager).map(nm -> nm.getNodeStatsCollector()).map(sc -> (NodeMetricGetters) sc).collect(Collectors.toList());
                // grab the adaptor from the 0'th cluster + the 0'th (only) node.
                final NumberProducer adaptor = nodes.get(0).ctx.getBean(NumberProducer.class);
                // grab access to the Dispatcher from the Adaptor
                final Dispatcher dispatcher = adaptor.dispatcher;
                final long startTime = System.currentTimeMillis();
                for (int i = 0; i < numbers.length; i++) dispatcher.dispatch(ke.extract(numbers[i]));
                LOGGER.info("====> Checking exact count.");
                // keep going as long as they are trickling in.
                assertTrue(() -> {
                    IntStream.range(0, scs.size()).forEach(i -> {
                        System.out.println("======> " + i);
                        final NodeMetricGetters mg = scs.get(i);
                        if (mg != null) {
                            System.out.println("discarded: " + mg.getDiscardedMessageCount());
                            System.out.println("not sent: " + mg.getMessagesNotSentCount());
                        }
                    });
                    return "expected: " + profilerTestNumberCount + " but was: " + (rank.totalMessages.get() + scs.get(0).getMessagesNotSentCount()) + ", (delivered: " + rank.totalMessages.get() + ", not sent: " + scs.get(0).getMessagesNotSentCount() + ")";
                }, poll(o -> profilerTestNumberCount == (rank.totalMessages.get() + scs.stream().map(sc -> Long.valueOf(sc.getMessagesNotSentCount())).reduce(Long.valueOf(0), (v1, v2) -> Long.valueOf(v1.longValue() + v2.longValue()).longValue()))));
                // assert that at least SOMETHING went through
                assertTrue(rank.totalMessages.get() > 0);
                LOGGER.info("testForProfiler time " + (System.currentTimeMillis() - startTime));
                @SuppressWarnings("unchecked") final AtomicLong count = nodes.stream().map(// get the NumberCounter Mp
                nmwc -> (MessageProcessor<NumberCounter>) nmwc.manager.getMp("test-cluster1")).filter(// if it exists
                l -> l != null).map(// pull the prototype
                l -> l.getPrototype().messageCount).reduce(new AtomicLong(0), // sum up all of the counts
                (v1, v2) -> new AtomicLong(v1.get() + v2.get()));
                assertEquals(profilerTestNumberCount, count.get());
            }
        });
    } catch (final Throwable th) {
        th.printStackTrace();
        throw th;
    }
}
Also used : IntStream(java.util.stream.IntStream) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) Mp(net.dempsy.lifecycle.annotation.Mp) ClusterInfoSession(net.dempsy.cluster.ClusterInfoSession) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) NodeAddress(net.dempsy.transport.NodeAddress) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ThreadingModel(net.dempsy.threading.ThreadingModel) ClusterId(net.dempsy.config.ClusterId) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) Logger(org.slf4j.Logger) NodeMetricGetters(net.dempsy.container.NodeMetricGetters) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterMetricGetters(net.dempsy.container.ClusterMetricGetters) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Functional.chain(net.dempsy.util.Functional.chain) ConditionPoll.assertTrue(net.dempsy.utils.test.ConditionPoll.assertTrue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) NodeMetricGetters(net.dempsy.container.NodeMetricGetters) Dispatcher(net.dempsy.messages.Dispatcher) AtomicLong(java.util.concurrent.atomic.AtomicLong) Random(java.util.Random) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) ClusterInfoSession(net.dempsy.cluster.ClusterInfoSession) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)19 List (java.util.List)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 Activation (net.dempsy.lifecycle.annotation.Activation)19 MessageHandler (net.dempsy.lifecycle.annotation.MessageHandler)19 MessageKey (net.dempsy.lifecycle.annotation.MessageKey)19 MessageProcessor (net.dempsy.lifecycle.annotation.MessageProcessor)19 MessageType (net.dempsy.lifecycle.annotation.MessageType)19 Mp (net.dempsy.lifecycle.annotation.Mp)19 Adaptor (net.dempsy.messages.Adaptor)19 Dispatcher (net.dempsy.messages.Dispatcher)19 Assert.assertEquals (org.junit.Assert.assertEquals)19 Assert.assertTrue (org.junit.Assert.assertTrue)19 Test (org.junit.Test)19 Collections (java.util.Collections)18 Map (java.util.Map)18 Set (java.util.Set)18 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)18 ClusterId (net.dempsy.config.ClusterId)18 KeyExtractor (net.dempsy.lifecycle.annotation.utils.KeyExtractor)18