Program: 90237
Project: 90237
Buggy source:
/** 
 * Test that monitor can receive and aggregate data from more than one BitarchiveServer and aggregate the data and upload it via FTPRemoteFile
 */
public void testBatchEndedMessageAggregation(){
  Settings.set(Settings.REMOTE_FILE_CLASS,FTPRemoteFile.class.getName());
  bas.close();
  JMSConnection con=JMSConnectionFactory.getInstance();
  TestMessageListener listener=new TestMessageListener();
  con.setListener(Channels.getTheArcrepos(),listener);
  con.setListener(Channels.getAllBa(),listener);
  File output_file=new File(WORKING,"String_Node_Str");
  BatchMessage bm=new BatchMessage(Channels.getTheBamon(),Channels.getTheArcrepos(),new ChecksumJob(),Settings.get(Settings.ENVIRONMENT_THIS_LOCATION));
  JMSConnectionTestMQ.updateMsgID(bm,"String_Node_Str");
  String baID1="String_Node_Str";
  HeartBeatMessage hbm=new HeartBeatMessage(Channels.getTheBamon(),baID1);
  JMSConnectionTestMQ.updateMsgID(hbm,"String_Node_Str");
  String baID2="String_Node_Str";
  HeartBeatMessage hbm2=new HeartBeatMessage(Channels.getTheBamon(),baID2);
  JMSConnectionTestMQ.updateMsgID(hbm2,"String_Node_Str");
  bam.visit(hbm);
  bam.visit(hbm2);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  bam.visit(bm);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  String forwardedID=((BatchMessage)listener.getAllReceived().get(0)).getID();
  File data1=new File(WORKING,"String_Node_Str");
  File data2=new File(WORKING,"String_Node_Str");
  RemoteFile rf1=RemoteFileFactory.getInstance(data1,true,false,true);
  BatchEndedMessage bem1=new BatchEndedMessage(Channels.getTheBamon(),baID1,forwardedID,rf1);
  RemoteFile rf2=RemoteFileFactory.getInstance(data2,true,false,true);
  BatchEndedMessage bem2=new BatchEndedMessage(Channels.getTheBamon(),baID2,forwardedID,rf2);
  JMSConnectionTestMQ.updateMsgID(bem1,"String_Node_Str");
  bam.visit(bem1);
  JMSConnectionTestMQ.updateMsgID(bem2,"String_Node_Str");
  bam.visit(bem2);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str" + listener.getAllReceived(),2,listener.getNumReceived());
  List received=listener.getAllReceived();
  for (Iterator i=received.iterator(); i.hasNext(); ) {
    Object o=i.next();
    if (o instanceof BatchReplyMessage) {
      ((BatchReplyMessage)o).getResultFile().copyTo(output_file);
    }
  }
  FileAsserts.assertFileNumberOfLines("String_Node_Str" + "String_Node_Str",output_file,2);
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",output_file);
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",output_file);
  int expected_length=FileUtils.readBinaryFile(data1).length + FileUtils.readBinaryFile(data2).length;
  int actual_length=FileUtils.readBinaryFile(output_file).length;
  assertEquals("String_Node_Str",expected_length,actual_length);
  File a_file=new File(WORKING,"String_Node_Str");
  try {
    rf1.copyTo(a_file);
    fail("String_Node_Str" + rf1.toString());
  }
 catch (  IOFailure e) {
  }
  try {
    rf2.copyTo(a_file);
    fail("String_Node_Str" + rf2.toString());
  }
 catch (  IOFailure e) {
  }
  con.removeListener(Channels.getTheArcrepos(),listener);
  con.removeListener(Channels.getAllBa(),listener);
}

Fixed version (ground truth):
/** 
 * Test that monitor can receive and aggregate data from more than one BitarchiveServer and aggregate the data and upload it via FTPRemoteFile
 */
public void testBatchEndedMessageAggregation() throws InterruptedException {
  Settings.set(Settings.REMOTE_FILE_CLASS,FTPRemoteFile.class.getName());
  bas.close();
  JMSConnection con=JMSConnectionFactory.getInstance();
  TestMessageListener listener=new TestMessageListener();
  con.setListener(Channels.getTheArcrepos(),listener);
  con.setListener(Channels.getAllBa(),listener);
  File output_file=new File(WORKING,"String_Node_Str");
  BatchMessage bm=new BatchMessage(Channels.getTheBamon(),Channels.getTheArcrepos(),new ChecksumJob(),Settings.get(Settings.ENVIRONMENT_THIS_LOCATION));
  JMSConnectionTestMQ.updateMsgID(bm,"String_Node_Str");
  String baID1="String_Node_Str";
  HeartBeatMessage hbm=new HeartBeatMessage(Channels.getTheBamon(),baID1);
  JMSConnectionTestMQ.updateMsgID(hbm,"String_Node_Str");
  String baID2="String_Node_Str";
  HeartBeatMessage hbm2=new HeartBeatMessage(Channels.getTheBamon(),baID2);
  JMSConnectionTestMQ.updateMsgID(hbm2,"String_Node_Str");
  bam.visit(hbm);
  bam.visit(hbm2);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  bam.visit(bm);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  String forwardedID=((BatchMessage)listener.getAllReceived().get(0)).getID();
  File data1=new File(WORKING,"String_Node_Str");
  File data2=new File(WORKING,"String_Node_Str");
  RemoteFile rf1=RemoteFileFactory.getInstance(data1,true,false,true);
  BatchEndedMessage bem1=new BatchEndedMessage(Channels.getTheBamon(),baID1,forwardedID,rf1);
  RemoteFile rf2=RemoteFileFactory.getInstance(data2,true,false,true);
  BatchEndedMessage bem2=new BatchEndedMessage(Channels.getTheBamon(),baID2,forwardedID,rf2);
  JMSConnectionTestMQ.updateMsgID(bem1,"String_Node_Str");
  bam.visit(bem1);
  JMSConnectionTestMQ.updateMsgID(bem2,"String_Node_Str");
  bam.visit(bem2);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  Thread.sleep(5000);
  ((JMSConnectionTestMQ)con).waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str" + listener.getAllReceived(),2,listener.getNumReceived());
  List received=listener.getAllReceived();
  for (Iterator i=received.iterator(); i.hasNext(); ) {
    Object o=i.next();
    if (o instanceof BatchReplyMessage) {
      ((BatchReplyMessage)o).getResultFile().copyTo(output_file);
    }
  }
  FileAsserts.assertFileNumberOfLines("String_Node_Str" + "String_Node_Str",output_file,2);
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",output_file);
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",output_file);
  int expected_length=FileUtils.readBinaryFile(data1).length + FileUtils.readBinaryFile(data2).length;
  int actual_length=FileUtils.readBinaryFile(output_file).length;
  assertEquals("String_Node_Str",expected_length,actual_length);
  File a_file=new File(WORKING,"String_Node_Str");
  try {
    rf1.copyTo(a_file);
    fail("String_Node_Str" + rf1.toString());
  }
 catch (  IOFailure e) {
  }
  try {
    rf2.copyTo(a_file);
    fail("String_Node_Str" + rf2.toString());
  }
 catch (  IOFailure e) {
  }
  con.removeListener(Channels.getTheArcrepos(),listener);
  con.removeListener(Channels.getAllBa(),listener);
}