use of net.dempsy.config.ClusterId 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.config.ClusterId 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" } };
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountNoRankMultinode", (r, c, s, t, ser) -> isElasticRoutingStrategy(r), ctxs, n -> {
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);
final ClusterMetricGetters[] stats = Arrays.asList((ClusterMetricGetters) manager[0].getClusterStatsCollector(new ClusterId(currentAppName, "test-cluster1")), (ClusterMetricGetters) manager[1].getClusterStatsCollector(new ClusterId(currentAppName, "test-cluster1"))).toArray(new ClusterMetricGetters[2]);
assertTrue(waitForAllSent(adaptor));
assertTrue(poll(o -> {
// System.out.println(stats[0].getProcessedMessageCount() + ", " + stats[1].getProcessedMessageCount());
return adaptor.numDispatched == Arrays.stream(stats).map(c -> c.getProcessedMessageCount()).reduce((c1, c2) -> c1.longValue() + c2.longValue()).get().longValue();
}));
});
}
}
use of net.dempsy.config.ClusterId 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" } };
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountNoRank", 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();
}));
});
}
}
use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestContainerLoadHandling method setUp.
@Before
public void setUp() throws Exception {
final ClusterId cid = new ClusterId("TestContainerLoadHandling", "test" + sequence++);
dispatcher = new MockDispatcher();
final BasicClusterStatsCollector sc = new BasicClusterStatsCollector();
clusterStats = sc;
nodeStats = new BasicNodeStatsCollector();
container = tr.track(new Manager<Container>(Container.class).getAssociatedInstance(containerId)).setMessageProcessor(new MessageProcessor<TestMessageProcessor>(new TestMessageProcessor())).setClusterId(cid);
container.setDispatcher(dispatcher);
container.setInbound(new DummyInbound());
container.start(new TestInfrastructure(null, null) {
@Override
public ClusterStatsCollector getClusterStatsCollector(final ClusterId clusterId) {
return sc;
}
@Override
public NodeStatsCollector getNodeStatsCollector() {
return nodeStats;
}
});
forceOutputException = false;
stillRunning = true;
}
use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestManagedRoutingStrategy method testInboundWithOutbound.
@Test
public void testInboundWithOutbound() throws Exception {
final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
final ClusterId cid = setTestName("testInboundWithOutbound");
final ContainerAddress oca = new ContainerAddress(new DummyNodeAddress("here"), 0);
final Infrastructure infra = makeInfra(session, sched);
final Utils<ContainerAddress> msutils = new Utils<>(infra, cid.clusterName, oca);
ib.setContainerDetails(cid, oca, (l, m) -> {
});
ib.start(infra);
checkForShardDistribution(session, msutils, numShardsToExpect, 1);
try (final ClusterInfoSession ses2 = sessFact.createSession();
final RoutingStrategyManager obman = chain(new RoutingStrategyManager(), o -> o.start(makeInfra(ses2, sched)));
final RoutingStrategy.Factory obf = obman.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
obf.start(makeInfra(ses2, sched));
assertTrue(poll(o -> obf.isReady()));
final RoutingStrategy.Router ob = obf.getStrategy(cid);
assertTrue(poll(o -> obf.isReady()));
final KeyedMessageWithType km = new KeyedMessageWithType(new Object(), new Object(), "");
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
final ContainerAddress ca = ob.selectDestinationForMessage(km);
assertNotNull(ca);
assertEquals("here", ((DummyNodeAddress) ca.node).name);
// now disrupt the session
session.close();
try (ClusterInfoSession ses3 = sessFact.createSession();
RoutingStrategy.Inbound ib2 = manager.getAssociatedInstance(ManagedInbound.class.getPackage().getName())) {
ib2.setContainerDetails(cid, ca, (l, m) -> {
});
ib2.start(makeInfra(ses3, sched));
assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
}
}
}
}
Aggregations