use of net.dempsy.lifecycle.simple.Mp in project Dempsy by Dempsy.
the class TestSimple method testSimple.
@Test
public void testSimple() throws Exception {
final AtomicLong count = new AtomicLong(0L);
try (final NodeManager nm = new NodeManager();
final DefaultThreadingModel tm = new DefaultThreadingModel("TB", -1, 1)) {
final Node n = new Node.Builder("test-app").defaultRoutingStrategyId("net.dempsy.router.simple").receiver(new Dummy()).cluster("start").adaptor(new Adaptor() {
private Dispatcher disp;
boolean done = false;
@Override
public void stop() {
done = true;
}
@Override
public void start() {
try {
while (!done) {
disp.dispatch(new KeyedMessageWithType(Integer.valueOf(1), "Hello", "string"));
// This is here for when the Container has a max pending and it gets starved for CPU cycles
// in this particular test.
Thread.yield();
}
} catch (final InterruptedException ie) {
if (!done)
LOGGER.error("Interrupted but not stopping.");
}
}
@Override
public void setDispatcher(final Dispatcher dispatcher) {
this.disp = dispatcher;
}
}).cluster("mp").mp(new MessageProcessor(MpFactory.make(() -> new Mp() {
@Override
public KeyedMessageWithType[] handle(final KeyedMessage message) {
count.incrementAndGet();
return null;
}
}, "string"))).build();
nm.node(n).collaborator(new LocalClusterSessionFactory().createSession()).threadingModel(tm.start("nodeid"));
nm.start();
assertTrue(ConditionPoll.poll(o -> count.get() > 100000));
}
}
Aggregations