use of net.dempsy.container.ClusterMetricGetters in project Dempsy by Dempsy.
the class TestWordCount method testWordCountNoRankAdaptorOnlyNode.
@Test
public void testWordCountNoRankAdaptorOnlyNode() throws Throwable {
try (@SuppressWarnings("resource") final SystemPropertyManager props = new SystemPropertyManager().set("min_nodes", "2")) {
final String[][] ctxs = { // adaptor only node
{ "classpath:/word-count/adaptor-kjv.xml" }, { "classpath:/word-count/mp-word-count.xml" }, { "classpath:/word-count/mp-word-count.xml" }, { "classpath:/word-count/mp-word-count.xml" }, { "classpath:/word-count/mp-word-count.xml" }, { "classpath:/word-count/mp-word-count.xml" } };
// the adaptor is the first one.
final int NUM_WC = ctxs.length - 1;
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[] 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));
WordProducer.latch.countDown();
final WordProducer adaptor = nodes.get(0).ctx.getBean(WordProducer.class);
waitForAllSent(adaptor);
assertTrue(poll(o -> adaptor.done.get()));
final var statsByNode = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> Pair.with((NodeMetricGetters) nm.getNodeStatsCollector(), (ClusterMetricGetters) nm.getClusterStatsCollector(countCId))).collect(Collectors.toList());
final NodeMetricGetters adaptorStats = (NodeMetricGetters) managers[0].getNodeStatsCollector();
assertTrue(poll(o -> {
final int allDiscardedMessagesCount = allDiscardedMessagesCount(adaptorStats, 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.container.ClusterMetricGetters in project Dempsy by Dempsy.
the class TestWordCount method testWordCountWithRank.
@Test
public void testWordCountWithRank() 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", "classpath:/word-count/mp-word-rank.xml" } };
WordCounter.aliveWordsToTestPassivate.clear();
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountWithRank", (r, c, s, t, ser) -> 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 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;
WordProducer.latch.countDown();
adaptor = ctx.getBean(WordProducer.class);
assertTrue(poll(o -> adaptor.done.get()));
final var statsByNode = Triplet.with((NodeMetricGetters) manager.getNodeStatsCollector(), (ClusterMetricGetters) manager.getClusterStatsCollector(countCId), (ClusterMetricGetters) manager.getClusterStatsCollector(rankCId));
// wait until all of the counts are also passed to WordRank
assertTrue(poll(o -> {
final int allDiscardedMessagesCount = allDiscardedMessagesCount(null, castToTupleList3(List.of(statsByNode)));
final ClusterMetricGetters rstat = statsByNode.getValue2();
return adaptor.numDispatched == allDiscardedMessagesCount + rstat.getDispatchedMessageCount();
}));
stopSystem();
// pull the Rank mp from the manager
final MessageProcessorLifecycle<?> mp = AccessUtil.getMp(manager, "test-cluster2");
@SuppressWarnings("unchecked") final WordRank prototype = ((MessageProcessor<WordRank>) mp).getPrototype();
final List<Rank> ranks = prototype.getPairs();
Collections.sort(ranks, (o1, o2) -> o2.rank.compareTo(o1.rank));
final int top10OrSo = (ranks.size() < 10) ? ranks.size() : 10;
final List<Rank> top10 = ranks.subList(0, top10OrSo);
final String errStr = "expected the top 10 results: " + top10 + " to all be in:" + finalResults;
top10.stream().forEach(r -> assertTrue(errStr, finalResults.contains(r.word)));
});
final int remaining = WordCounter.aliveWordsToTestPassivate.size();
WordCounter.aliveWordsToTestPassivate.clear();
assertEquals(0, remaining);
}
}
Aggregations