use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.
the class TestWordCount method testWordCountNoRankMultinode.
@Test
public void testWordCountNoRankMultinode() throws Throwable {
try (@SuppressWarnings("resource") final SystemPropertyManager props = new SystemPropertyManager().set("min_nodes", "2")) {
final String[][] ctxs = { { "classpath:/word-count/adaptor-kjv.xml", "classpath:/word-count/mp-word-count.xml" }, { "classpath:/word-count/mp-word-count.xml" } };
WordCounter.aliveWordsToTestPassivate.clear();
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountNoRankMultinode", (r, c, s, t, ser) -> isElasticRoutingStrategy(r) && isContainerOkay(c), ctxs, n -> {
final ClusterId countCId = new ClusterId(currentAppName, "test-cluster1");
final List<NodeManagerWithContext> nodes = n.nodes;
final NodeManager[] manager = Arrays.asList(nodes.get(0).manager, nodes.get(1).manager).toArray(new NodeManager[2]);
final ClassPathXmlApplicationContext[] ctx = Arrays.asList(nodes.get(0).ctx, nodes.get(1).ctx).toArray(new ClassPathXmlApplicationContext[2]);
// wait until I can reach the cluster from the adaptor.
assertTrue(poll(o -> manager[0].getRouter().allReachable("test-cluster1").size() == 2));
assertTrue(poll(o -> manager[1].getRouter().allReachable("test-cluster1").size() == 2));
WordProducer.latch.countDown();
final WordProducer adaptor = ctx[0].getBean(WordProducer.class);
assertTrue(waitForAllSent(adaptor));
assertTrue(poll(o -> adaptor.done.get()));
final var statsByNode = Arrays.asList(manager).stream().map(nm -> Pair.with((NodeMetricGetters) nm.getNodeStatsCollector(), (ClusterMetricGetters) nm.getClusterStatsCollector(countCId))).collect(Collectors.toList());
assertTrue(poll(o -> {
final int allDiscardedMessagesCount = allDiscardedMessagesCount(null, castToTupleList2(statsByNode));
return adaptor.numDispatched == allDiscardedMessagesCount + statsByNode.stream().mapToInt(sc -> (int) sc.getValue1().getDispatchedMessageCount()).sum();
}));
});
final int remaining = WordCounter.aliveWordsToTestPassivate.size();
WordCounter.aliveWordsToTestPassivate.clear();
assertEquals(0, remaining);
}
}
use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.
the class TestWordCount method testWordCountHomogeneousProcessing.
@Test
public void testWordCountHomogeneousProcessing() throws Throwable {
final String[][] ctxs = { // adaptor only node
{ "classpath:/word-count/adaptor-kjv.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" } };
// the adaptor is the first one.
final int NUM_WC = ctxs.length - 1;
try (@SuppressWarnings("resource") final SystemPropertyManager props = new SystemPropertyManager().set("min_nodes", Integer.toString(NUM_WC)).set("routing-group", ":group").set("send_threads", "1").set("receive_threads", "1").set("blocking-queue-size", "500000")) {
WordCounter.aliveWordsToTestPassivate.clear();
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountHomogeneousProcessing", (r, c, s, t, ser) -> isElasticRoutingStrategy(r) && isContainerOkay(c), ctxs, n -> {
final ClusterId countCId = new ClusterId(currentAppName, "test-cluster1");
final ClusterId rankCId = new ClusterId(currentAppName, "test-cluster2");
final List<NodeManagerWithContext> nodes = n.nodes;
final NodeManager[] managers = nodes.stream().map(nm -> nm.manager).toArray(NodeManager[]::new);
// wait until I can reach the cluster from the adaptor.
assertTrue(poll(o -> managers[0].getRouter().allReachable("test-cluster1").size() == NUM_WC));
assertTrue(poll(o -> managers[0].getRouter().allReachable("test-cluster2").size() == NUM_WC));
WordProducer.latch.countDown();
final WordProducer adaptor = nodes.get(0).ctx.getBean(WordProducer.class);
waitForAllSent(adaptor);
// get all of the stats collectors.
final List<Triplet<NodeMetricGetters, ClusterMetricGetters, ClusterMetricGetters>> statsByNode = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> Triplet.with((NodeMetricGetters) nm.getNodeStatsCollector(), (ClusterMetricGetters) nm.getClusterStatsCollector(countCId), (ClusterMetricGetters) nm.getClusterStatsCollector(rankCId))).collect(Collectors.toList());
final NodeMetricGetters adaptorStats = (NodeMetricGetters) managers[0].getNodeStatsCollector();
final int totalSent = adaptor.numDispatched;
// now wait for the sum of all messages received by the ranking to be the number sent
assertTrue(poll(o -> {
// System.out.println("" + adaptor.numDispatched + " ==? ");
final int allDiscardedMessagesCount = allDiscardedMessagesCount(adaptorStats, castToTupleList3(statsByNode));
final int totalRanked = allDiscardedMessagesCount + statsByNode.stream().mapToInt(sc -> (int) sc.getValue2().getDispatchedMessageCount()).sum();
// System.out.println(": " + totalRanked + " == " + totalSent);
return totalRanked == totalSent;
}));
// no nodes (except the adaptor node) should have sent any messages.
// IOW, messages got to the Rank processor never leaving the node the Count was executed.
final List<NodeMetricGetters> nodeStats = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> nm.getNodeStatsCollector()).map(s -> (NodeMetricGetters) s).collect(Collectors.toList());
// if the routing id isn't a group id then there should be cross talk.
assertEquals(NUM_WC, nodeStats.size());
for (final NodeMetricGetters mg : nodeStats) assertEquals(0, mg.getMessagesNotSentCount());
if (isGroupRoutingStrategy(routerId)) {
for (final NodeMetricGetters mg : nodeStats) assertEquals(0, mg.getMessagesSentCount());
} else {
assertNotNull(nodeStats.stream().filter(mg -> mg.getMessagesSentCount() > 0).findFirst().orElse(null));
}
});
final int remaining = WordCounter.aliveWordsToTestPassivate.size();
WordCounter.aliveWordsToTestPassivate.clear();
assertEquals(0, remaining);
}
}
use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.
the class TestWordCount method testWordCountNoRank.
// ========================================================================
@Test
public void testWordCountNoRank() throws Throwable {
try (@SuppressWarnings("resource") final SystemPropertyManager props = new SystemPropertyManager().set("min_nodes", "1")) {
final String[][] ctxs = { { "classpath:/word-count/adaptor-kjv.xml", "classpath:/word-count/mp-word-count.xml" } };
WordCounter.aliveWordsToTestPassivate.clear();
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountNoRank", (r, c, s, t, ser) -> isContainerOkay(c), ctxs, n -> {
final List<NodeManagerWithContext> nodes = n.nodes;
final NodeManager manager = nodes.get(0).manager;
// wait until I can reach the cluster from the adaptor.
assertTrue(poll(o -> manager.getRouter().allReachable("test-cluster1").size() == 1));
final ClassPathXmlApplicationContext ctx = nodes.get(0).ctx;
final WordProducer adaptor;
final ClusterMetricGetters stats;
WordProducer.latch.countDown();
adaptor = ctx.getBean(WordProducer.class);
stats = (ClusterMetricGetters) manager.getClusterStatsCollector(new ClusterId(currentAppName, "test-cluster1"));
assertTrue(poll(o -> adaptor.done.get()));
assertTrue(poll(o -> {
// System.out.println("" + adaptor.numDispatched + " == " + stats.getProcessedMessageCount());
return adaptor.numDispatched == (stats.getProcessedMessageCount() + stats.getMessageDiscardedCount());
}));
});
final int remaining = WordCounter.aliveWordsToTestPassivate.size();
WordCounter.aliveWordsToTestPassivate.clear();
assertEquals(0, remaining);
}
}
use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.
the class TestContainer method addOutputCatchStage.
public NodeManager addOutputCatchStage() throws InterruptedException {
// =======================================================
// configure an output catcher tier
final Node out = new Node.Builder("test-app").defaultRoutingStrategyId("net.dempsy.router.simple").receiver(new BlockingQueueReceiver(new ArrayBlockingQueue<>(16))).nodeStatsCollector(new BasicNodeStatsCollector()).cluster("output-catch").mp(new MessageProcessor<OutputCatcher>(new OutputCatcher())).build();
out.validate();
final NodeManager nman = track(new NodeManager()).node(out).collaborator(track(sessionFactory.createSession())).start();
// wait until we can actually reach the output-catch cluster from the main node
assertTrue(poll(o -> {
try {
return canReach(getRouter(manager), "output-catch", new KeyExtractor().extract(new OutputMessage("foo", 1, 1)).iterator().next());
} catch (final Exception e) {
return false;
}
}));
// =======================================================
return nman;
}
use of net.dempsy.lifecycle.annotation.Mp in project Dempsy by Dempsy.
the class TestContainer method testEvictableWithPassivateException.
@Test
public void testEvictableWithPassivateException() throws Exception {
final TestProcessor mp = createAndGet("foo");
mp.throwPassivateException.set(true);
final TestProcessor prototype = context.getBean(TestProcessor.class);
final int tmpCloneCount = prototype.cloneCount.intValue();
mp.evict.set(true);
container.evict();
assertTrue(poll(o -> mp.passivateExceptionCount.get() > 0));
Thread.sleep(100);
assertEquals("Passivate Exception Thrown", 1, mp.passivateExceptionCount.get());
final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
assertTrue(poll(o -> prototype.cloneCount.intValue() > tmpCloneCount));
Thread.sleep(1000);
assertEquals("Clone count, 2nd message", tmpCloneCount + 1, prototype.cloneCount.intValue());
}
Aggregations