Package javax.jms

Examples of javax.jms.XAConnection


   validate that both sets of work W1 and W2 get applied.
    */
   // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
   public void testMemoryLeakForLocalTXsWithWork() throws Exception
   {
      XAConnection conn = null;

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         // Create a session
         JBossSession sess1 = (JBossSession)conn.createXASession();
         DummyListener listener = new DummyListener();
         sess1.setMessageListener(listener);
         conn.start();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         tm.begin();

         Transaction trans = tm.getTransaction();
         trans.enlistResource(res1);
         trans.delistResource(res1, XAResource.TMSUCCESS);
         MessageProducer p = sess1.createProducer(queue1);
         MessageConsumer cons = sess1.createConsumer(queue1);
         conn.start();
         // send 10 messages
         for (int i = 0; i < 10; i++)
         {
            TextMessage message = sess1.createTextMessage("delistedwork" + i);
            p.send(message);
         }
         // now receive 5
         for (int i = 0; i < 5; i++)
         {
            TextMessage textMessage = (TextMessage)cons.receive();
            assertEquals("delistedwork" + i, textMessage.getText());
         }
         // once we enlist ensure that the 5 acks are merged ok, the first timne we do this there is nothing to merge in
         // the global tx
         // so all acks are just copied
         trans.enlistResource(res1);
         SessionState sstate = (SessionState)((DelegateSupport)sess1.getDelegate()).getState();
         ClientTransaction clientTransaction = rm.getTx(sstate.getCurrentTxId());
         assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
         ClientTransaction.SessionTxState sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates()
                                                                                                              .get(0);
         assertEquals("wrong number of acks", 5, sessionTxState.getAcks().size());

         trans.delistResource(res1, XAResource.TMSUCCESS);
         for (int i = 5; i < 10; i++)
         {
            TextMessage textMessage = (TextMessage)cons.receive();
            assertEquals("delistedwork" + i, textMessage.getText());
         }
         // now reenlist and make sure that there are now 10 acks, this time around a merge will be done with the first
         // 5 acks
         //
         trans.enlistResource(res1);

         clientTransaction = rm.getTx(sstate.getCurrentTxId());
         assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
         sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates().get(0);
         assertEquals("wrong number of acks", 10, sessionTxState.getAcks().size());

         tm.commit();

      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }

      }

   }
View Full Code Here


   }

   // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
   public void testMemoryLeakForLocalTXsOnJoinOnePhase() throws Exception
   {
      XAConnection conn = null;

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         // Create a session
         XASession sess1 = conn.createXASession();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
         int rmSizeBeforeStart = rm.size();
         Xid xid = new MessagingXid(branchQualifier, 12435, globalTxId);
         res1.start(xid, XAResource.TMNOFLAGS);
         res1.end(xid, XAResource.TMSUCCESS);
         int rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.start(xid, XAResource.TMJOIN);
         res1.end(xid, XAResource.TMSUCCESS);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.commit(xid, true);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart == rmAfter);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }

      }

   }
View Full Code Here

   }

   // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
   public void testMemoryLeakForLocalTXsOnJoinTwoPhase() throws Exception
   {
      XAConnection conn = null;

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         // Create a session
         XASession sess1 = conn.createXASession();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
         int rmSizeBeforeStart = rm.size();
         Xid xid = new MessagingXid(branchQualifier, 12435, globalTxId);
         res1.start(xid, XAResource.TMNOFLAGS);
         res1.end(xid, XAResource.TMSUCCESS);
         int rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.start(xid, XAResource.TMJOIN);
         res1.end(xid, XAResource.TMSUCCESS);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.prepare(xid);
         res1.commit(xid, false);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart == rmAfter);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }

      }

   }
View Full Code Here

   }

   // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
   public void testMemoryLeakForLocalTXsOnResumeOnePhase() throws Exception
   {
      XAConnection conn = null;

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         // Create a session
         XASession sess1 = conn.createXASession();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
         int rmSizeBeforeStart = rm.size();
         Xid xid = new MessagingXid(branchQualifier, 12435, globalTxId);
         res1.start(xid, XAResource.TMNOFLAGS);
         res1.end(xid, XAResource.TMSUCCESS);
         int rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.start(xid, XAResource.TMRESUME);
         res1.end(xid, XAResource.TMSUCCESS);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.commit(xid, true);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart == rmAfter);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }

      }

   }
View Full Code Here

   }

   // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
   public void testMemoryLeakForLocalTXsOnJResumeTwoPhase() throws Exception
   {
      XAConnection conn = null;

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         // Create a session
         XASession sess1 = conn.createXASession();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
         byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
         int rmSizeBeforeStart = rm.size();
         Xid xid = new MessagingXid(branchQualifier, 12435, globalTxId);
         res1.start(xid, XAResource.TMNOFLAGS);
         res1.end(xid, XAResource.TMSUCCESS);
         int rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.start(xid, XAResource.TMRESUME);
         res1.end(xid, XAResource.TMSUCCESS);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart + 1 == rmAfter);
         res1.prepare(xid);
         res1.commit(xid, false);
         rmAfter = rm.size();
         assertTrue(rmSizeBeforeStart == rmAfter);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }

      }

   }
View Full Code Here

         // send a message to the queue using an XASession that's not enlisted in a global tx

         XAConnectionFactory xcf = (XAConnectionFactory)cf;

         XAConnection xconn = xcf.createXAConnection();

         XASession xs = xconn.createXASession();

         MessageProducer p = xs.createProducer(queue1);
         Message m = xs.createTextMessage("one");

         p.send(m);

         xconn.close();

         // receive the message
         Connection conn = cf.createConnection();
         conn.start();
         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
View Full Code Here

         ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
         Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(1, count.intValue());

         XAConnectionFactory xcf = (XAConnectionFactory)cf;
         XAConnection xconn = xcf.createXAConnection();
         xconn.start();

         // no active JTA transaction here

         XASession xs = xconn.createXASession();

         MessageConsumer c = xs.createConsumer(queue1);

         // the message should be store unacked in the local session
         TextMessage rm = (TextMessage)c.receive(1000);

         assertEquals("one", rm.getText());

         // messages should be acked
         count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(0, count.intValue());

         xconn.close();
      }
      finally
      {

         if (suspended != null)
View Full Code Here

    * http://jira.jboss.org/jira/browse/JBMESSAGING-946
    *
    */
   public void testConsumeGlobalTransaction() throws Exception
   {
      XAConnection xaconn = null;

      try
      {
         // send a message to the queue

         Connection conn = cf.createConnection();
         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer p = s.createProducer(queue1);
         p.setDeliveryMode(DeliveryMode.PERSISTENT);
         Message m = s.createTextMessage("one");
         p.send(m);
         conn.close();

         ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
         Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(1, count.intValue());

         tm.begin();

         Transaction trans = tm.getTransaction();

         XAConnectionFactory xacf = (XAConnectionFactory)cf;

         xaconn = xacf.createXAConnection();

         xaconn.start();

         XASession xasession = xaconn.createXASession();

         XAResource resouce = xasession.getXAResource();

         trans.enlistResource(resouce);

         MessageConsumer consumer = xasession.createConsumer(queue1);

         TextMessage messageReceived = (TextMessage)consumer.receive(1000);

         assertNotNull(messageReceived);

         assertEquals("one", messageReceived.getText());

         assertNull(consumer.receive(1000));

         count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");

         assertEquals(1, count.intValue());

         trans.delistResource(resouce, XAResource.TMSUCCESS);

         tm.rollback();

         tm.begin();
         trans = tm.getTransaction();
         trans.enlistResource(resouce);

         messageReceived = (TextMessage)consumer.receive(1000);

         assertNotNull(messageReceived);

         assertEquals("one", messageReceived.getText());

         count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(1, count.intValue());

         trans.commit();

         count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(0, count.intValue());

      }
      finally
      {
         if (xaconn != null)
         {
            xaconn.close();
         }
      }
   }
View Full Code Here

    *            This was done as per: http://jira.jboss.org/jira/browse/JBMESSAGING-946
    *
    */
   public void testRecoverOnXA() throws Exception
   {
      XAConnection xaconn = null;

      try
      {
         // send a message to the queue

         Connection conn = cf.createConnection();
         Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer p = s.createProducer(queue1);
         p.setDeliveryMode(DeliveryMode.PERSISTENT);
         Message m = s.createTextMessage("one");
         p.send(m);
         m = s.createTextMessage("two");
         p.send(m);
         conn.close();

         ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
         Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(2, count.intValue());

         XAConnectionFactory xacf = (XAConnectionFactory)cf;

         xaconn = xacf.createXAConnection();

         xaconn.start();

         XASession xasession = xaconn.createXASession();

         MessageConsumer consumer = xasession.createConsumer(queue1);

         TextMessage messageReceived = (TextMessage)consumer.receive(1000);

         assertNotNull(messageReceived);

         assertEquals("one", messageReceived.getText());

         xasession.recover();

         messageReceived = (TextMessage)consumer.receive(1000);

         assertEquals("two", messageReceived.getText());

         consumer.close();

         // I can't call xasession.close for this test as JCA layer would cache the session
         // So.. keep this close commented!
         // xasession.close();

         count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
         assertEquals(0, count.intValue());
      }
      finally
      {
         if (xaconn != null)
         {
            xaconn.close();
         }
      }
   }
View Full Code Here

   }

   // See http://jira.jboss.com/jira/browse/JBMESSAGING-638
   public void testResourceManagerMemoryLeakOnCommit() throws Exception
   {
      XAConnection xaConn = null;

      try
      {
         xaConn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)xaConn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         XASession xaSession = xaConn.createXASession();

         xaConn.start();

         XAResource res = xaSession.getXAResource();

         XAResource dummy = new DummyXAResource();

         for (int i = 0; i < 100; i++)
         {
            tm.begin();

            Transaction tx = tm.getTransaction();

            tx.enlistResource(res);

            tx.enlistResource(dummy);

            assertEquals(1, rm.size());

            tx.delistResource(res, XAResource.TMSUCCESS);

            tx.delistResource(dummy, XAResource.TMSUCCESS);

            tm.commit();
         }

         assertEquals(1, rm.size());

         xaConn.close();

         xaConn = null;

         assertEquals(0, rm.size());

      }
      finally
      {
         if (xaConn != null)
         {
            xaConn.close();
         }
      }
   }
View Full Code Here

TOP

Related Classes of javax.jms.XAConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.