use of net.dempsy.container.mocks.MockInputMessage in project Dempsy by Dempsy.
the class TestContainerLoadHandling method runSimpleProcessingWithoutQueuing.
/*
* Actual Unit Tests
*/
public void runSimpleProcessingWithoutQueuing(final boolean block) throws Exception {
// set up a gate for starting
SendMessageThread.startLatch = new CountDownLatch(1);
// produce the initial MPs
final ArrayList<Thread> in = new ArrayList<Thread>();
final KeyedMessage[] messages = new KeyedMessage[NUMMPS];
for (int i = 0; i < NUMMPS; i++) messages[i] = km(new MockInputMessage("key" + i));
for (int j = 0; j < NUMMPS; j++) in.add(startMessagePump(container, messages, block));
// let the messages go.
SendMessageThread.startLatch.countDown();
assertTrue(poll(o -> container.getProcessorCount() == NUMMPS));
stillRunning = false;
assertTrue(poll(o -> in.stream().filter(t -> t.isAlive()).count() == 0));
final int numMessagePumped = dispatcher.messages.size();
final long initialDiscard = clusterStats.getMessageCollisionCount();
dispatcher.messages.clear();
// Send NTHREADS Messages and wait for them to come out, then repeat
for (int i = 0; i < NUMRUNS; i++) {
// set up a gate for starting
SendMessageThread.startLatch = new CountDownLatch(1);
SendMessageThread.finishedCount.set(0);
SendMessageThread.processingCount.set(0);
in.clear();
for (int j = 0; j < NUMTHREADS; j++) in.add(sendMessages(container, messages, block, MSGPERTHREAD));
assertTrue(poll(o -> SendMessageThread.processingCount.get() == NUMTHREADS));
// let the messages go.
SendMessageThread.startLatch.countDown();
// after sends are allowed to proceed
assertTrue("Timeout waiting on message to be sent", poll(o -> SendMessageThread.finishedCount.get() >= NUMTHREADS));
assertEquals(NUMTHREADS, SendMessageThread.finishedCount.get());
assertTrue(poll(o -> clusterStats.getInFlightMessageCount() == 0));
assertTrue(poll(o -> in.stream().filter(t -> t.isAlive() == true).count() == 0));
final long discarded = clusterStats.getMessageCollisionCount();
if (block)
assertEquals(0L, discarded);
final int iter = i;
assertEquals((NUMTHREADS * MSGPERTHREAD) * (iter + 1), dispatcher.messages.size() + discarded - initialDiscard);
assertEquals((NUMTHREADS * MSGPERTHREAD) * (iter + 1) + numMessagePumped, clusterStats.getProcessedMessageCount() + discarded - initialDiscard);
}
checkStat(clusterStats);
}
use of net.dempsy.container.mocks.MockInputMessage in project Dempsy by Dempsy.
the class TestContainerLoadHandling method runSimpleProcessingWithoutQueuing.
/*
* Actual Unit Tests
*/
public void runSimpleProcessingWithoutQueuing() throws Exception {
// set up a gate for starting
SendMessageThread.startLatch = new CountDownLatch(1);
// produce the initial MPs
final ArrayList<Thread> in = new ArrayList<Thread>();
final KeyedMessage[] messages = new KeyedMessage[NUMMPS];
for (int i = 0; i < NUMMPS; i++) messages[i] = km(new MockInputMessage("key" + i));
for (int j = 0; j < NUMMPS; j++) in.add(startMessagePump(container, messages));
// let the messages go.
SendMessageThread.startLatch.countDown();
assertTrue(poll(o -> container.getProcessorCount() == NUMMPS));
stillRunning = false;
assertTrue(poll(o -> in.stream().filter(t -> t.isAlive()).count() == 0));
final int numMessagePumped = dispatcher.messages.size();
final long initialDiscard = clusterStats.getMessageCollisionCount();
dispatcher.messages.clear();
// Send NTHREADS Messages and wait for them to come out, then repeat
for (int i = 0; i < NUMRUNS; i++) {
// set up a gate for starting
SendMessageThread.startLatch = new CountDownLatch(1);
SendMessageThread.finishedCount.set(0);
SendMessageThread.processingCount.set(0);
in.clear();
for (int j = 0; j < NUMTHREADS; j++) in.add(sendMessages(container, messages, MSGPERTHREAD));
assertTrue(poll(o -> SendMessageThread.processingCount.get() == NUMTHREADS));
// let the messages go.
SendMessageThread.startLatch.countDown();
// after sends are allowed to proceed
assertTrue("Timeout waiting on message to be sent", poll(o -> SendMessageThread.finishedCount.get() >= NUMTHREADS));
assertEquals(NUMTHREADS, SendMessageThread.finishedCount.get());
assertTrue(poll(o -> clusterStats.getInFlightMessageCount() == 0));
assertTrue(poll(o -> in.stream().filter(t -> t.isAlive() == true).count() == 0));
final long discarded = clusterStats.getMessageCollisionCount();
assertEquals(0L, discarded);
final int iter = i;
assertEquals((NUMTHREADS * MSGPERTHREAD) * (iter + 1), dispatcher.messages.size() + discarded - initialDiscard);
assertEquals((NUMTHREADS * MSGPERTHREAD) * (iter + 1) + numMessagePumped, clusterStats.getProcessedMessageCount() + discarded - initialDiscard);
}
checkStat(clusterStats);
}
use of net.dempsy.container.mocks.MockInputMessage in project Dempsy by Dempsy.
the class TestContainerLoadHandling method testMessagesCanQueueWithinLimitsBlocking.
/**
* Test the case where messages arrive faster than they are processed but the queue never exceeds the Thread Pool Size * 2, so no messages are discarded.
*/
@Test
public void testMessagesCanQueueWithinLimitsBlocking() throws Exception {
// produce the initial MPs
final ArrayList<Thread> in = new ArrayList<Thread>();
final KeyedMessage[] messages = new KeyedMessage[NUMMPS];
for (int i = 0; i < NUMMPS; i++) messages[i] = km(new MockInputMessage("key" + i));
for (int j = 0; j < NUMMPS; j++) in.add(sendMessages(container, new KeyedMessage[] { messages[j] }, 1));
// let the messages go.
SendMessageThread.startLatch.countDown();
assertTrue(poll(o -> in.stream().filter(t -> t.isAlive()).count() == 0));
assertEquals(NUMMPS, container.getProcessorCount());
final int numMessagePumped = dispatcher.messages.size();
assertEquals(numMessagePumped, clusterStats.getProcessedMessageCount());
dispatcher.messages.clear();
for (int i = 0; i < NUMRUNS; i++) {
final int iter = i;
final long initialMessagesDispatched = clusterStats.getDispatchedMessageCount();
// set up a gate for starting
SendMessageThread.startLatch = new CountDownLatch(1);
SendMessageThread.finishedCount.set(0);
SendMessageThread.processingCount.set(0);
commonLongRunningHandler = new CountDownLatch(1);
in.clear();
for (int j = 0; j < NUMMPS; j++) in.add(sendMessages(container, new KeyedMessage[] { km(new MockInputMessage("key" + j % NUMMPS)) }, DUPFACTOR));
assertTrue(poll(o -> SendMessageThread.processingCount.get() == NUMMPS));
// let the messages go.
SendMessageThread.startLatch.countDown();
// NUMMPS messages should be "dispatched"
assertTrue(poll(o -> (clusterStats.getDispatchedMessageCount() - initialMessagesDispatched) == NUMMPS));
// 1 message from each thread should be "in flight"
assertTrue(poll(o -> container.getMessageWorkingCount() == NUMMPS));
Thread.sleep(50);
// NUMMPS messages should STILL be "dispatched"
assertTrue(poll(o -> (clusterStats.getDispatchedMessageCount() - initialMessagesDispatched) == NUMMPS));
// let the rest of them go
commonLongRunningHandler.countDown();
assertTrue("Timeout waiting on message to be sent", poll(o -> in.stream().filter(t -> t.isAlive() == true).count() == 0));
// after sends are allowed to proceed
assertEquals(NUMMPS, SendMessageThread.finishedCount.get());
assertEquals(0, clusterStats.getInFlightMessageCount());
assertEquals((DUPFACTOR * NUMMPS) * (iter + 1), dispatcher.messages.size());
assertEquals((DUPFACTOR * NUMMPS) * (iter + 1) + numMessagePumped, clusterStats.getProcessedMessageCount());
assertEquals(0L, clusterStats.getMessageCollisionCount());
checkStat(clusterStats);
}
}
Aggregations