Program: 4794
Project: 4794
Buggy source:
/** 
 * Tests that: - uploads upto maxUploads get slots - uploader after that but upto uploadQueueSize get queued - uploads beyond that get try again later - when an uploade with slot terminates first uploader gets slot - when an uploader with slot terminates, everyone in queue advances.
 */
public void testNormalQueueing(){
  UploadManager upManager=new UploadManager();
  SettingsManager.instance().setMaxUploads(2);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(99999);
  SettingsManager.instance().setUploadQueueSize(2);
  HTTPDownloader d3=null;
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    connectDloader(d2,true,rfd2,true);
    try {
      d3=addUploader(upManager,rfd3,"String_Node_Str",true);
      connectDloader(d3,true,rfd3,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception ioe) {
      ioe.printStackTrace();
      fail("String_Node_Str");
    }
    HTTPDownloader d4=null;
    try {
      d4=addUploader(upManager,rfd4,"String_Node_Str",true);
      connectDloader(d4,true,rfd4,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(2,qx.getQueuePosition());
    }
catch (    Exception ioe) {
      fail("String_Node_Str");
    }
    HTTPDownloader d5=null;
    try {
      d5=addUploader(upManager,rfd5,"String_Node_Str",true);
      connectDloader(d5,true,rfd5,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException tax) {
    }
catch (    IOException ioe) {
    }
catch (    Exception e) {
      e.printStackTrace();
      fail("String_Node_Str");
    }
    kill(d1);
    Thread.sleep((UploadManager.MIN_POLL_TIME + UploadManager.MAX_POLL_TIME) / 2);
    try {
      connectDloader(d4,false,rfd4,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException talx) {
    }
catch (    Exception e) {
      e.printStackTrace();
      fail("String_Node_Str");
    }
    try {
      connectDloader(d3,false,rfd3,true);
    }
 catch (    QueuedException e) {
      e.printStackTrace();
      fail("String_Node_Str" + e.getQueuePosition());
    }
catch (    TryAgainLaterException tlx) {
      fail("String_Node_Str");
    }
catch (    Exception ign) {
      ign.printStackTrace();
    }
    Thread.sleep((UploadManager.MIN_POLL_TIME + UploadManager.MAX_POLL_TIME) / 2);
    try {
      connectDloader(d4,false,rfd4,true);
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception other) {
      other.printStackTrace();
      fail("String_Node_Str");
    }
    System.out.println("String_Node_Str");
  }
 catch (  Exception anyother) {
    System.out.println("String_Node_Str");
    anyother.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * Tests that: - uploads upto maxUploads get slots - uploader after that but upto uploadQueueSize get queued - uploads beyond that get try again later - when an uploade with slot terminates first uploader gets slot - when an uploader with slot terminates, everyone in queue advances.
 */
public void testNormalQueueing(){
  UploadManager upManager=new UploadManager();
  setUploadManager(upManager);
  SettingsManager.instance().setMaxUploads(2);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(99999);
  SettingsManager.instance().setUploadQueueSize(2);
  HTTPDownloader d3=null;
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    connectDloader(d2,true,rfd2,true);
    try {
      d3=addUploader(upManager,rfd3,"String_Node_Str",true);
      connectDloader(d3,true,rfd3,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception ioe) {
      ioe.printStackTrace();
      fail("String_Node_Str");
    }
    HTTPDownloader d4=null;
    try {
      d4=addUploader(upManager,rfd4,"String_Node_Str",true);
      connectDloader(d4,true,rfd4,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(2,qx.getQueuePosition());
    }
catch (    Exception ioe) {
      fail("String_Node_Str");
    }
    HTTPDownloader d5=null;
    try {
      d5=addUploader(upManager,rfd5,"String_Node_Str",true);
      connectDloader(d5,true,rfd5,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException tax) {
    }
catch (    IOException ioe) {
    }
catch (    Exception e) {
      e.printStackTrace();
      fail("String_Node_Str");
    }
    kill(d1);
    Thread.sleep((UploadManager.MIN_POLL_TIME + UploadManager.MAX_POLL_TIME) / 2);
    try {
      connectDloader(d4,false,rfd4,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException talx) {
    }
catch (    Exception e) {
      e.printStackTrace();
      fail("String_Node_Str");
    }
    try {
      connectDloader(d3,false,rfd3,true);
    }
 catch (    QueuedException e) {
      e.printStackTrace();
      fail("String_Node_Str" + e.getQueuePosition());
    }
catch (    TryAgainLaterException tlx) {
      fail("String_Node_Str");
    }
catch (    Exception ign) {
      ign.printStackTrace();
    }
    Thread.sleep((UploadManager.MIN_POLL_TIME + UploadManager.MAX_POLL_TIME) / 2);
    try {
      connectDloader(d4,false,rfd4,true);
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception other) {
      other.printStackTrace();
      fail("String_Node_Str");
    }
    System.out.println("String_Node_Str");
  }
 catch (  Exception anyother) {
    System.out.println("String_Node_Str");
    anyother.printStackTrace();
  }
}