failed = true; latch.release(); } if (!tm.getJMSRedelivered()) {
      public void onMessage(Message m)      {         TextMessage tm = (TextMessage)m;         count++;                  log.trace("Got message:" + count);                           try         {            log.trace("message:" + tm.getText());            if (count == 1)            {               if (!("a".equals(tm.getText())))               {                  log.trace("Should be a but was " + tm.getText());                  failed = true;                  latch.release();               }               log.trace("Throwing exception");               throw new RuntimeException("Aardvark");            }            else if (count == 2)            {               log.trace("ack mode:" + sess.getAcknowledgeMode());               if (sess.getAcknowledgeMode() == Session.AUTO_ACKNOWLEDGE || sess.getAcknowledgeMode() == Session.DUPS_OK_ACKNOWLEDGE)               {                  //Message should be immediately redelivered                  if (!("a".equals(tm.getText())))                  {                     log.trace("Should be a but was " + tm.getText());                     failed = true;                     latch.release();                  }               }               else               {                  //Transacted or CLIENT_ACKNOWLEDGE - next message should be delivered                  if (!("b".equals(tm.getText())))                  {                     log.trace("Should be b but was " + tm.getText());                     failed = true;                     latch.release();                  }               }            }            else if (count == 3)            {               if (sess.getAcknowledgeMode() == Session.AUTO_ACKNOWLEDGE || sess.getAcknowledgeMode() == Session.DUPS_OK_ACKNOWLEDGE)               {                  if (!("b".equals(tm.getText())))                  {                     log.trace("Should be b but was " + tm.getText());                     failed = true;                     latch.release();                  }               }               else               {                  if (!("c".equals(tm.getText())))                  {                     log.trace("Should be c but was " + tm.getText());                     failed = true;                     latch.release();                  }                  latch.release();               }            }                        else if (count == 4)            {               if (sess.getAcknowledgeMode() == Session.AUTO_ACKNOWLEDGE || sess.getAcknowledgeMode() == Session.DUPS_OK_ACKNOWLEDGE)               {                  if (!("c".equals(tm.getText())))                  {                     log.trace("Should be c but was " + tm.getText());                     failed = true;                     latch.release();                  }                  latch.release();               }               else               {                  //Shouldn't get a 4th messge                  failed = true;                  latch.release();               }            }         }         catch (JMSException e)         {                       failed = true;            latch.release();         }      }