use of net.dempsy.container.NodeMetricGetters 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")) {
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountHomogeneousProcessing", (r, c, s, t, ser) -> isElasticRoutingStrategy(r), ctxs, n -> {
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 for the ranks.
final List<ClusterMetricGetters> rankStats = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> nm.getClusterStatsCollector(new ClusterId(currentAppName, "test-cluster2"))).map(sc -> (ClusterMetricGetters) sc).collect(Collectors.toList());
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 -> {
final int totalRanked = rankStats.stream().map(sc -> Integer.valueOf((int) sc.getDispatchedMessageCount())).reduce(Integer.valueOf(0), (i1, i2) -> new Integer(i1.intValue() + i2.intValue())).intValue();
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));
}
});
}
}
use of net.dempsy.container.NodeMetricGetters 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 -> new Long(sc.getMessagesNotSentCount())).reduce(new Long(0), (v1, v2) -> new Long(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;
}
}
Aggregations