Program: 90236
Project: 90236
Buggy source:
/** 
 * Verify that multiple messages sent almost simultaneously works
 */
public void testLotsOfMessages(){
  MessageTestHandler handler=new MessageTestHandler();
  JMSConnectionFactory.getInstance().setListener(Channels.getTheArcrepos(),handler);
  JMSConnectionFactory.getInstance().setListener(Channels.getThisHaco(),handler);
  Settings.set(Settings.REMOTE_FILE_CLASS,"String_Node_Str");
  assertTrue("String_Node_Str" + FILE_TO_UPLOAD,FILE_TO_UPLOAD.exists());
  int beforeCount=Thread.activeCount();
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    bac.get(FILENAME_TO_GET,0);
    bac.upload(RemoteFileFactory.getInstance(FILE_TO_UPLOAD,true,false,true));
    BatchMessage bMsg=new BatchMessage(THE_BAMON,Channels.getThisHaco(),new TestBatchJobRuns(),Settings.get(Settings.ENVIRONMENT_THIS_LOCATION));
    bac.batch(bMsg);
    RemoveAndGetFileMessage rMsg=new RemoveAndGetFileMessage(FILENAME_TO_GET,"String_Node_Str","String_Node_Str","String_Node_Str");
    bac.removeAndGetFile(rMsg);
  }
  while (Thread.activeCount() > beforeCount) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
  ((JMSConnectionTestMQ)JMSConnectionFactory.getInstance()).waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.getMsg,LARGE_MESSAGE_COUNT,handler.getMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.uploadMsg,LARGE_MESSAGE_COUNT,handler.uploadMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.removeMsg,LARGE_MESSAGE_COUNT,handler.removeMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.batchReplyMsg,LARGE_MESSAGE_COUNT,handler.batchReplyMsg.size());
  assertEquals("String_Node_Str",LARGE_MESSAGE_COUNT * 4,handler.getTotalCount());
  int countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    GetMessage msg=handler.getMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.getMsg,LARGE_MESSAGE_COUNT,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    UploadMessage msg=handler.uploadMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.uploadMsg,1,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    BatchReplyMessage msg=handler.batchReplyMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.batchReplyMsg,LARGE_MESSAGE_COUNT,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    RemoveAndGetFileMessage msg=handler.removeMsg.get(i);
    if (!msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.removeMsg,LARGE_MESSAGE_COUNT,countok);
}

Fixed version (ground truth):
/** 
 * Verify that multiple messages sent almost simultaneously works
 */
public void testLotsOfMessages(){
  MessageTestHandler handler=new MessageTestHandler();
  JMSConnectionFactory.getInstance().setListener(Channels.getTheArcrepos(),handler);
  JMSConnectionFactory.getInstance().setListener(Channels.getThisHaco(),handler);
  assertTrue("String_Node_Str" + FILE_TO_UPLOAD,FILE_TO_UPLOAD.exists());
  int beforeCount=Thread.activeCount();
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    bac.get(FILENAME_TO_GET,0);
    bac.upload(RemoteFileFactory.getInstance(FILE_TO_UPLOAD,true,false,true));
    BatchMessage bMsg=new BatchMessage(THE_BAMON,Channels.getThisHaco(),new TestBatchJobRuns(),Settings.get(Settings.ENVIRONMENT_THIS_LOCATION));
    bac.batch(bMsg);
    RemoveAndGetFileMessage rMsg=new RemoveAndGetFileMessage(FILENAME_TO_GET,"String_Node_Str","String_Node_Str","String_Node_Str");
    bac.removeAndGetFile(rMsg);
  }
  while (Thread.activeCount() > beforeCount) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
  ((JMSConnectionTestMQ)JMSConnectionFactory.getInstance()).waitForConcurrentTasksToFinish();
  try {
    Thread.sleep(1000);
  }
 catch (  InterruptedException e) {
  }
  ((JMSConnectionTestMQ)JMSConnectionFactory.getInstance()).waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.getMsg,LARGE_MESSAGE_COUNT,handler.getMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.uploadMsg,LARGE_MESSAGE_COUNT,handler.uploadMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.removeMsg,LARGE_MESSAGE_COUNT,handler.removeMsg.size());
  assertEquals("String_Node_Str" + LARGE_MESSAGE_COUNT + "String_Node_Str"+ handler.batchReplyMsg,LARGE_MESSAGE_COUNT,handler.batchReplyMsg.size());
  assertEquals("String_Node_Str",LARGE_MESSAGE_COUNT * 4,handler.getTotalCount());
  int countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    GetMessage msg=handler.getMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.getMsg,LARGE_MESSAGE_COUNT,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    UploadMessage msg=handler.uploadMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.uploadMsg,1,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    BatchReplyMessage msg=handler.batchReplyMsg.get(i);
    if (msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.batchReplyMsg,LARGE_MESSAGE_COUNT,countok);
  countok=0;
  for (int i=0; i < LARGE_MESSAGE_COUNT; ++i) {
    RemoveAndGetFileMessage msg=handler.removeMsg.get(i);
    if (!msg.isOk()) {
      ++countok;
    }
  }
  assertEquals("String_Node_Str" + handler.removeMsg,LARGE_MESSAGE_COUNT,countok);
}