Hi,

  I'm trying to build a standalone environment for unit test that
provide JTA and JMS through JOTM and ActiveMQ.

Does anybody tried to work with ActiveMQ queues under JOTM
transaction?

I wrote this test but I can't receive a message I've previously wrote
on a queue:

public class SimpleTest extends TestCase{
    private TMService jotm;
    private ActiveMQXAConnectionFactory xaConnectionFactory;

    public void setUp() throws Exception {
        try {
            jotm = new Jotm(true, false);
        } catch (NamingException e) {
          // thrown only if JOTM is started with a remote transaction
          // factory or if it has to be bound.
        }
        xaConnectionFactory = new
ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false&broker.useJmx=false");
    }

    public void testSimple() throws JMSException, NotSupportedException,
SystemException, RollbackException, HeuristicRollbackException,
HeuristicMixedException {
        TransactionManager tm = jotm.getTransactionManager();
        XAResource jmsXAResource;

        XAQueueConnection mqXAConn =
xaConnectionFactory.createXAQueueConnection();
        mqXAConn.start();
        XAQueueSession mqXAQSess = mqXAConn.createXAQueueSession();
        QueueSession mqQSess = mqXAQSess.getQueueSession();
        jmsXAResource = mqXAQSess.getXAResource();

        tm.begin();
        tm.getTransaction().enlistResource(jmsXAResource);

        // do stuff
        Queue q = mqQSess.createQueue("queue1");
        QueueSender qs = mqQSess.createSender(q);
        Message m = mqQSess.createTextMessage("Hello");
        qs.send(m);
                
        mqQSess.close();
        qs.close();
                
        tm.getTransaction().delistResource(jmsXAResource,
XAResource.TMSUCCESS);

        tm.commit();

        /////////////////////////////////////////////
        //////// Here starts the test ///////////////

        mqXAConn = xaConnectionFactory.createXAQueueConnection();
        mqXAConn.start();
        mqXAQSess = mqXAConn.createXAQueueSession();
        mqQSess = mqXAQSess.getQueueSession();
        jmsXAResource = mqXAQSess.getXAResource();
                
        tm.begin();
        tm.getTransaction().enlistResource(jmsXAResource);

        
        QueueBrowser qb = mqQSess.createBrowser(q);
        if (!qb.getEnumeration().hasMoreElements()) {
            fail();
        } else {
            for (Enumeration e = qb.getEnumeration(); e.hasMoreElements();)
{
                Message ith = (Message)e.nextElement();
                //ith.acknowledge();
            }
        }

        QueueReceiver qr = mqQSess.createReceiver(q);
        m = qr.receive(2000);
        if (m == null) {
            fail();    //// always fails... why??
        }
        mqQSess.close();
        qr.close();
                
        tm.getTransaction().delistResource(jmsXAResource,
XAResource.TMSUCCESS);
                
        tm.commit();
    }
}

TIA,
  Paolo.
-- 
View this message in context: 
http://www.nabble.com/receive-message-under-JOTM-tf2926279.html#a8180602
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to