String ProdSequenceNo = null;
String mapKey = null;
int expectedNoOfMessages = ConsumerSysTest.noOfMessages;
int consumerCount = ConsumerSysTest.ConsumerCount;
boolean dowhile = true;
Map consumerMap = new ConcurrentHashMap();
Map prodNameMap = new TreeMap();
Map prodMsgMap = new TreeMap();
while (dowhile) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ConsumerSysTest consumer = new ConsumerSysTest();
currentProducerMap = Collections.synchronizedMap(consumer.resetProducerMap());
//System.out.println("CURR MAP = " + currentProducerMap);
// ConsumerSysTest.ProducerMap.clear();
if (currentProducerMap.size() == 0) {
dowhile = false;
}
// Put the map values to another map for parsing.
for (int i = 1; i <= currentProducerMap.size(); i++) {
String ProdMsg = (String) currentProducerMap.get(String.valueOf(i));
//System.out.println("");
ProducerName = ProdMsg.substring(0, ProdMsg.indexOf("#"));
MsgBody = ProdMsg.substring(ProdMsg.indexOf("#")+1, ProdMsg.indexOf("#", ProdMsg.indexOf("#")+1));
ProdSequenceNo = ProdMsg.substring(ProdMsg.indexOf("#", ProdMsg.indexOf("#", ProdMsg.indexOf("#")+1)) + 1, ProdMsg.lastIndexOf("#"));
ConsumerName = ProdMsg.substring(ProdMsg.lastIndexOf("#") +1, ProdMsg.length());
if (ConsumerSysTest.destination) {
mapKey = ConsumerName + ProducerName;
} else {
mapKey = ProducerName;
}
if (ProducerTextMap.containsKey(mapKey)) {
// Increment the counter value
Integer value = (Integer) ProducerTextMap.get(mapKey);
ProducerTextMap.put(mapKey, new Integer(value.intValue()+1));
} else {
// Put the Producer Name in the map
ProducerTextMap.put(mapKey, new Integer(1));
}
Integer ConsumerSeqID = (Integer) ProducerTextMap.get(mapKey);
Integer ProducerSeqID = Integer.valueOf(ProdSequenceNo);
if (ConsumerSysTest.destination) {
// Check for duplicate message.
if (ConsumerSeqID.intValue() > expectedNoOfMessages) {
messageField.setText(JMeterUtils.getResString("duplicate_message"));
} else if (MsgBody.equals(ProducerSysTest.LAST_MESSAGE)) {
// Check for message order.
if (ConsumerSeqID.intValue() != expectedNoOfMessages) {
messageField.setText(JMeterUtils.getResString("not_in_order_message"));
} else if (currentProducerMap.size() == i) {
if (messageField.getText().length() == 0) {
messageField.setText(JMeterUtils.getResString("system_test_pass"));
}
}
}
} else {
//Create map for each consumer
for (int j = 0 ; j < consumerCount ; j++) {
if (!consumerMap.containsKey(new String(ConsumerName))) {
consumerMap.put(new String(ConsumerName), new LinkedHashMap());
}
}
//create Producer Name Map
if (!prodNameMap.containsKey(ProducerName)) {
prodNameMap.put(ProducerName, (null));
}
//Get the current size of consumer
int seqVal = 0;
Object[] cObj = consumerMap.keySet().toArray();
for (int k = 0; k < cObj.length; k++) {
String cMapKey = (String)cObj[k];
Map cMapVal = (Map)consumerMap.get(cObj[k]);
if (cMapKey.equals(ConsumerName)) {
seqVal = cMapVal.size();
break;
}
}
//Put object to its designated consumer map
Object[] consumerObj = consumerMap.keySet().toArray();
for (int j = 0; j < consumerObj.length; j++) {
String cMapKey = (String)consumerObj[j];
Map cMapVal = (LinkedHashMap)consumerMap.get(consumerObj[j]);
if (cMapKey.equals(ConsumerName)) {
cMapVal.put(new Integer(seqVal), (ProducerName + "/" + ProducerSeqID));
}
}
}