use of net.dempsy.NodeManager 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.NodeManager 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);
}
}
use of net.dempsy.NodeManager 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"));
}
}
use of net.dempsy.NodeManager in project Dempsy by Dempsy.
the class TestContainer method setUp.
@Before
public void setUp() throws Exception {
justThrowMe = null;
throwMeInActivation = null;
track(new SystemPropertyManager()).set("container-type", containerId);
context = track(new ClassPathXmlApplicationContext(ctx));
sessionFactory = new LocalClusterSessionFactory();
final Node node = context.getBean(Node.class);
manager = track(new NodeManager()).node(node).collaborator(track(sessionFactory.createSession())).start();
statsCollector = manager.getClusterStatsCollector(new ClusterId("test-app", "test-cluster"));
container = manager.getContainers().get(0);
assertTrue(poll(manager, m -> m.isReady()));
}
Aggregations