/**
   * Check for equality
   *
   * @param object The other object
   * @return True / false
   */
  @Override
  public boolean equals(final Object object) {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("equals(" + object + ")");
    }

    if (object != null && object instanceof ActiveMQRAMessage) {
      return message.equals(((ActiveMQRAMessage) object).message);
    } else {
      return message.equals(object);
    }
  }
  /**
   * Check a session is rollbacked on a Session close();
   *
   * @throws Exception
   */
  public void xtestTransactionRollbackOnSessionClose() throws Exception {
    Destination destination = createDestination(getClass().getName());
    Connection connection = createConnection();
    connection.setClientID(idGen.generateId());
    connection.start();
    Session consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = null;
    if (topic) {
      consumer = consumerSession.createDurableSubscriber((Topic) destination, "TESTRED");
    } else {
      consumer = consumerSession.createConsumer(destination);
    }
    Session producerSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSession.createProducer(destination);
    producer.setDeliveryMode(deliveryMode);

    TextMessage sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg1");
    producer.send(sentMsg);

    producerSession.commit();

    Message recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertFalse(recMsg.getJMSRedelivered());
    consumerSession.close();
    consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    consumer = consumerSession.createConsumer(destination);

    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    consumerSession.commit();
    assertTrue(recMsg.equals(sentMsg));
    connection.close();
  }
  /**
   * check messages are actuallly sent on a tx rollback
   *
   * @throws Exception
   */
  public void testTransactionRollbackOnSend() throws Exception {
    Destination destination = createDestination(getClass().getName());
    Connection connection = createConnection();
    connection.setClientID(idGen.generateId());
    connection.start();
    Session consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(destination);
    Session producerSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSession.createProducer(destination);
    producer.setDeliveryMode(deliveryMode);

    TextMessage sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg1");
    producer.send(sentMsg);
    producerSession.commit();

    Message recMsg = consumer.receive(RECEIVE_TIMEOUT);
    consumerSession.commit();
    assertTrue(recMsg.equals(sentMsg));

    sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg2");
    producer.send(sentMsg);
    producerSession.rollback();

    sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg3");
    producer.send(sentMsg);
    producerSession.commit();

    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertTrue(recMsg.equals(sentMsg));
    consumerSession.commit();

    connection.close();
  }
  public void testNoExceptionOnRedeliveryAckWithSimpleTopicConsumer() throws Exception {
    Destination destination = createDestination(getClass().getName());
    Connection connection = createConnection();
    final AtomicBoolean gotException = new AtomicBoolean();
    connection.setExceptionListener(
        new ExceptionListener() {
          @Override
          public void onException(JMSException exception) {
            LOG.error("unexpected ex:" + exception);
            gotException.set(true);
          }
        });
    connection.setClientID(idGen.generateId());
    connection.start();
    Session consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = null;
    if (topic) {
      consumer = consumerSession.createConsumer(destination);
    } else {
      consumer = consumerSession.createConsumer(destination);
    }
    Session producerSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSession.createProducer(destination);
    producer.setDeliveryMode(deliveryMode);

    TextMessage sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg1");
    producer.send(sentMsg);
    producerSession.commit();

    Message recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertFalse(recMsg.getJMSRedelivered());
    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    consumerSession.rollback();
    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertTrue(recMsg.getJMSRedelivered());
    consumerSession.rollback();
    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertTrue(recMsg.getJMSRedelivered());
    consumerSession.commit();
    assertTrue(recMsg.equals(sentMsg));
    assertTrue(recMsg.getJMSRedelivered());
    connection.close();

    assertFalse("no exception", gotException.get());
  }