use of org.goldenorb.types.message.TextMessage in project goldenorb by jzachr.
the class MessageThread method testInboundMessageQueue.
/**
* Tests mapping many messages to many Vertices using threads.
*
* @throws Exception
*/
@Test
public void testInboundMessageQueue() throws Exception {
int numOfThreads = 100;
int numOfMessages = 10000;
InboundMessageQueue imq = new InboundMessageQueue();
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch everyoneDoneLatch = new CountDownLatch(numOfThreads);
// create new MessageThreads that add the passed message to the inbound message queue
for (int i = 0; i < numOfThreads; i++) {
Messages msgs = new Messages(TextMessage.class);
for (int p = 0; p < numOfMessages; p++) {
TextMessage txtmsg = new TextMessage(Integer.toString(i), new Text("test message " + Integer.toString(p)));
msgs.add(txtmsg);
}
MessageThread mThread = new MessageThread(msgs, imq, startLatch, everyoneDoneLatch);
mThread.start();
}
// start the threads simultaneously
startLatch.countDown();
// wait until all threads are done
everyoneDoneLatch.await();
Iterator<String> iter = imq.getVerticesWithMessages().iterator();
int count = 0;
while (iter.hasNext()) {
iter.next();
count++;
}
// check a random Vertex
int randomVertex = (int) (Math.random() * (numOfThreads));
Iterator<Message<? extends Writable>> iter2 = imq.getMessage(Integer.toString(randomVertex)).iterator();
int count2 = 0;
while (iter2.hasNext()) {
iter2.next();
count2++;
}
assertTrue(count == numOfThreads);
assertTrue(count2 == numOfMessages);
assertThat(imq.getMessage(Integer.toString(randomVertex)), notNullValue());
}
use of org.goldenorb.types.message.TextMessage in project goldenorb by jzachr.
the class OutboundMessageThread method testOutBoundMessageQueue.
@Test
public void testOutBoundMessageQueue() throws Exception {
// OutboundMessageQueue settings
int numberOfPartitions = 100;
// max number of Messages to be sent by a Thread
int numOfMessagesToSendPerThread = 10500;
// max number of Messages to trigger a send operation by the queue
int numOfMessagesPerBlock = 1000;
int partitionId = 1;
Class<? extends Message<? extends Writable>> messageClass = TextMessage.class;
Map<Integer, OrbPartitionCommunicationProtocol> orbClients = new HashMap<Integer, OrbPartitionCommunicationProtocol>();
for (int i = 0; i < numberOfPartitions; i++) {
orbClients.put(new Integer(i), infoCollector);
}
OutboundMessageQueue omq = new OutboundMessageQueue(numberOfPartitions, numOfMessagesPerBlock, orbClients, messageClass, partitionId);
// initialize the Threads and pass them their test Messages
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch everyoneDoneLatch = new CountDownLatch(numberOfPartitions);
for (int i = 0; i < numberOfPartitions; i++) {
Messages msgs = new Messages(TextMessage.class);
for (int p = 0; p < numOfMessagesToSendPerThread; p++) {
TextMessage txtmsg = new TextMessage(Integer.toString(i), new Text("test message " + Integer.toString(p)));
msgs.add(txtmsg);
}
OutboundMessageThread obmThread = new OutboundMessageThread(msgs, omq, startLatch, everyoneDoneLatch);
// initialize a Thread
obmThread.start();
}
// start all Threads simultaneously
startLatch.countDown();
// wait until all Threads are done
everyoneDoneLatch.await();
omq.sendRemainingMessages();
assertThat(omq, notNullValue());
assertTrue(infoCollector.mList.size() == (numberOfPartitions * numOfMessagesToSendPerThread));
}
Aggregations