use of net.dempsy.container.mocks.ContainerTestMessage 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() > 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.container.mocks.ContainerTestMessage in project Dempsy by Dempsy.
the class TestContainer method testEvictableWithPassivateException.
@Test
public void testEvictableWithPassivateException() throws Exception {
final TestProcessor mp = createAndGet("foo");
mp.throwPassivateException.set(true);
final TestProcessor prototype = context.getBean(TestProcessor.class);
final int tmpCloneCount = prototype.cloneCount.intValue();
mp.evict.set(true);
container.evict();
assertTrue(poll(o -> mp.passivateExceptionCount.get() > 0));
Thread.sleep(100);
assertEquals("Passivate Exception Thrown", 1, mp.passivateExceptionCount.get());
final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
assertTrue(poll(o -> prototype.cloneCount.intValue() > tmpCloneCount));
Thread.sleep(1000);
assertEquals("Clone count, 2nd message", tmpCloneCount + 1, prototype.cloneCount.intValue());
}
use of net.dempsy.container.mocks.ContainerTestMessage in project Dempsy by Dempsy.
the class TestContainer method createAndGet.
private TestProcessor createAndGet(final String foo) throws Exception {
cache = new HashMap<>();
final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
assertNotNull(adaptor.dispatcher);
adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage(foo));
assertTrue(poll(o -> container.getProcessorCount() > 0));
Thread.sleep(100);
assertEquals("did not create MP", 1, container.getProcessorCount());
assertTrue(poll(cache, c -> c.get(foo) != null));
final TestProcessor mp = cache.get(foo);
assertNotNull("MP not associated with expected key", mp);
assertEquals("activation count, 1st message", 1, mp.activationCount);
assertEquals("invocation count, 1st message", 1, mp.invocationCount);
return mp;
}
use of net.dempsy.container.mocks.ContainerTestMessage 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 int concurrency = 5;
container.setOutputConcurrency(concurrency);
final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
assertNotNull(adaptor.dispatcher);
for (int i = 0; i < numInstances; i++) adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo" + i));
assertTrue(poll(container, c -> c.getProcessorCount() > 19));
Thread.sleep(100);
assertEquals("number of MP instances", 20, container.getProcessorCount());
try (NodeManager nman = addOutputCatchStage()) {
container.outputPass();
assertTrue(poll(outputMessages, o -> o.size() > 19));
Thread.sleep(100);
assertEquals(20, outputMessages.size());
}
}
use of net.dempsy.container.mocks.ContainerTestMessage in project Dempsy by Dempsy.
the class TestContainer method testEvictCollisionWithBlocking.
@Test
public void testEvictCollisionWithBlocking() throws Throwable {
final TestProcessor mp = createAndGet("foo");
// now we're going to cause the passivate to be held up.
mp.blockPassivate = new CountDownLatch(1);
// allow eviction
mp.evict.set(true);
// now kick off the evict in a separate thread since we expect it to hang
// until the mp becomes unstuck.
// this will allow us to see the evict pass complete
final AtomicBoolean evictIsComplete = new AtomicBoolean(false);
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
container.evict();
evictIsComplete.set(true);
}
});
thread.start();
// let it get going.
Thread.sleep(500);
// check to see we're hung.
assertFalse(evictIsComplete.get());
final ClusterMetricGetters sc = (ClusterMetricGetters) statsCollector;
assertEquals(0, sc.getMessageCollisionCount());
// sending it a message will now cause it to have the collision tick up
final TestAdaptor adaptor = context.getBean(TestAdaptor.class);
adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
// give it some time.
Thread.sleep(100);
// make sure there's no collision
assertEquals(0, sc.getMessageCollisionCount());
// make sure no message got handled
// 1 is the initial invocation that caused the instantiation.
assertEquals(1, mp.invocationCount);
// now let the evict finish
mp.blockPassivate.countDown();
// wait until the eviction completes
assertTrue(poll(evictIsComplete, o -> o.get()));
// Once the poll finishes a new Mp is instantiated and handling messages.
assertTrue(poll(cache, c -> c.get("foo") != null));
final TestProcessor mp2 = cache.get("foo");
assertNotNull("MP not associated with expected key", mp);
// invocationCount should be 1 from the initial invocation that caused the clone, and no more
assertEquals(1, mp.invocationCount);
assertEquals(1, mp2.invocationCount);
assertTrue(mp != mp2);
// send a message that should go through
adaptor.dispatcher.dispatchAnnotated(new ContainerTestMessage("foo"));
assertTrue(poll(o -> mp2.invocationCount > 1));
Thread.sleep(100);
assertEquals(1, mp.invocationCount);
assertEquals(2, mp2.invocationCount);
}
Aggregations