Program: 90246
Project: 90246
Buggy source:
/** 
 * Tests what happens if we have a blocking listener. It appears that by default, a listener may pre-queue messages even while it is blocked processing the previous message. This is not desirable behaviour.
 * @throws InterruptedException
 * @throws JMSException
 */
public void testNotListeningWhileProcessingSunMQ() throws InterruptedException, JMSException {
  if (!Settings.get(Settings.JMS_BROKER_CLASS).equals("String_Node_Str")) {
    return;
  }
  JMSConnectionFactory.getInstance().cleanup();
  JMSConnectionFactory.getInstance();
  long blockingTime=1000l;
  int messagesSent=10;
  BlockingListener nonBlocker=new BlockingListener();
  BlockingListener blocker=new BlockingListener(true,blockingTime);
  ChannelID theQueue=Channels.getTheBamon();
  JMSConnection con=JMSConnectionFactory.getInstance();
  MiniConnectionSunMQ con2=new MiniConnectionSunMQ();
  con.setListener(theQueue,blocker);
  con2.setListener(theQueue,nonBlocker);
  for (int i=0; i < messagesSent; i++) {
    NetarkivetMessage msg=new BatchMessage(theQueue,new ChecksumJob(),"String_Node_Str");
    con.send(msg);
  }
  while (HangingListenerTest.messages_received < messagesSent) {
  }
  Thread.sleep(2 * blockingTime);
  assertEquals("String_Node_Str",1,blocker.called);
  System.out.println("String_Node_Str");
  for (int i=0; i < messagesSent; i++) {
    NetarkivetMessage msg=new BatchMessage(theQueue,new ChecksumJob(),"String_Node_Str");
    con.send(msg);
  }
  while (HangingListenerTest.messages_received < messagesSent) {
  }
  Thread.sleep(2 * blockingTime);
  assertEquals("String_Node_Str",2,blocker.called);
  con.cleanup();
  con2.cleanup();
}

Fixed version (ground truth):
/** 
 * Tests what happens if we have a blocking listener. It appears that by default, a listener may pre-queue messages even while it is blocked processing the previous message. This is not desirable behaviour.
 * @throws InterruptedException
 * @throws JMSException
 */
public void testNotListeningWhileProcessingSunMQ() throws InterruptedException, JMSException {
  if (!Settings.get(Settings.JMS_BROKER_CLASS).equals(JMSConnectionSunMQ.class.getName())) {
    fail("String_Node_Str");
  }
  JMSConnectionFactory.getInstance().cleanup();
  JMSConnectionFactory.getInstance();
  long blockingTime=1000l;
  int messagesSent=10;
  BlockingListener nonBlocker=new BlockingListener();
  BlockingListener blocker=new BlockingListener(true,blockingTime);
  ChannelID theQueue=Channels.getTheBamon();
  JMSConnection con=JMSConnectionFactory.getInstance();
  MiniConnectionSunMQ con2=new MiniConnectionSunMQ();
  con.setListener(theQueue,blocker);
  con2.setListener(theQueue,nonBlocker);
  for (int i=0; i < messagesSent; i++) {
    NetarkivetMessage msg=new BatchMessage(theQueue,new ChecksumJob(),"String_Node_Str");
    con.send(msg);
  }
  while (HangingListenerTest.messages_received < messagesSent) {
  }
  Thread.sleep(2 * blockingTime);
  assertEquals("String_Node_Str",1,blocker.called);
  System.out.println("String_Node_Str");
  for (int i=0; i < messagesSent; i++) {
    NetarkivetMessage msg=new BatchMessage(theQueue,new ChecksumJob(),"String_Node_Str");
    con.send(msg);
  }
  while (HangingListenerTest.messages_received < messagesSent) {
  }
  Thread.sleep(2 * blockingTime);
  assertEquals("String_Node_Str",2,blocker.called);
  con.cleanup();
  con2.cleanup();
}