Examples of XAConnection


Examples of javax.jms.XAConnection

   }


   public void testOneSessionTwoTransactionsCommitSend() throws Exception
   {
      XAConnection conn = null;

      Connection conn2 = null;

      try
      {

         conn = cf.createXAConnection();

         //Create a session
         XASession sess1 = conn.createXASession();
         XAResource res1 = sess1.getXAResource();

         MessageProducer prod1 = sess1.createProducer(queue);

         tm.begin();

         Transaction tx1 = tm.getTransaction();
         tx1.enlistResource(res1);

         //Send a message
         prod1.send(sess1.createTextMessage("kangaroo1"));

         //suspend the tx
         Transaction suspended = tm.suspend();

         tm.begin();

         //Send another message in another tx using the same session
         Transaction tx2 = tm.getTransaction();
         tx2.enlistResource(res1);

         //Send a message
         prod1.send(sess1.createTextMessage("kangaroo2"));

         tx2.delistResource(res1, XAResource.TMSUCCESS);
        
         //commit this transaction
         tm.commit();

         //verify only kangaroo2 message is sent
         conn2 = cf.createConnection();
         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         conn2.start();
         MessageConsumer cons = sess.createConsumer(queue);
         TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
         assertNotNull(r1);
         assertEquals("kangaroo2", r1.getText());
         TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
         assertNull(r2);

         //now resume the first tx and then commit it
         tm.resume(suspended);
        
         tx1.delistResource(res1, XAResource.TMSUCCESS);
        
         tm.commit();

         //verify that the first text message is received
         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
         assertNotNull(r3);
         assertEquals("kangaroo1", r3.getText());

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

Examples of javax.jms.XAConnection

   }


   public void testOneSessionTwoTransactionsRollbackSend() throws Exception
   {
      XAConnection conn = null;

      Connection conn2 = null;

      try
      {

         conn = cf.createXAConnection();

         //Create a session
         XASession sess1 = conn.createXASession();
         XAResource res1 = sess1.getXAResource();

         MessageProducer prod1 = sess1.createProducer(queue);

         tm.begin();

         Transaction tx1 = tm.getTransaction();
         tx1.enlistResource(res1);

         //Send a message
         prod1.send(sess1.createTextMessage("kangaroo1"));

         //suspend the tx
         Transaction suspended = tm.suspend();

         tm.begin();

         //Send another message in another tx using the same session
         Transaction tx2 = tm.getTransaction();
         tx2.enlistResource(res1);

         //Send a message
         prod1.send(sess1.createTextMessage("kangaroo2"));

         tx2.delistResource(res1, XAResource.TMSUCCESS);
        
         //rollback this transaction
         tm.rollback();

         //verify no messages are sent
         conn2 = cf.createConnection();
         Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         conn2.start();
         MessageConsumer cons = sess.createConsumer(queue);
         TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);

         assertNull(r1);


         //now resume the first tx and then commit it
         tm.resume(suspended);
        
         tx1.delistResource(res1, XAResource.TMSUCCESS);
        
         tm.commit();

         //verify that the first text message is received
         TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
         assertNotNull(r3);
         assertEquals("kangaroo1", r3.getText());

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

Examples of javax.jms.XAConnection

  
   //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

Examples of javax.jms.XAConnection

   }
  
   //See http://jira.jboss.com/jira/browse/JBMESSAGING-638
   public void testResourceManagerMemoryLeakOnRollback() 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.rollback();
         }                 
        
         assertEquals(1, rm.size());
        
         xaConn.close();
        
         xaConn = null;
        
         assertEquals(0, rm.size());

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

Examples of javax.jms.XAConnection

   //http://jira.jboss.com/jira/browse/JBMESSAGING-721
   public void testConvertFromLocalTx() throws Exception
   {
      Connection conn = null;
     
      XAConnection xaConn = null;
     
      try
      {
     
         //First send some messages to a queue
        
         conn = cf.createConnection();
        
         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod = sessSend.createProducer(queue);
        
         TextMessage tm1 = sessSend.createTextMessage("message1");
        
         TextMessage tm2 = sessSend.createTextMessage("message2");
        
         prod.send(tm1);
        
         prod.send(tm2);
        
        
         xaConn = cf.createXAConnection();
        
         XASession xaSession = xaConn.createXASession();
        
         xaConn.start();
        
         MessageConsumer cons = xaSession.createConsumer(queue);
        
         //Receive the two messages outside of a transaction
        
         TextMessage rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         Message rm3 = cons.receive(1000);
        
         assertNull(rm3);
        
         //Now we enlist the session in an xa transaction
        
         XAResource res = xaSession.getXAResource();
        
         tm.begin();
        
         Transaction tx = tm.getTransaction();
         tx.enlistResource(res);
        
         //This should cause the work done previously to be converted into work done in the xa transaction
         //this is what an MDB does
         //There is a difficulty in transactional delivery with an MDB.
         //The message is received from the destination and then sent to the mdb container so
         //it can call onMessage.
         //For transactional delivery the receipt of the message should be in a transaction but by the time
         //the mdb container is invoked the message has already been received it is too late - the message
         //has already been received and passed on (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration"
         //of Mark Little's book Java Transaction processing
         //for a discussion of how different app serves deal with this)
         //The way jboss messaging (and jboss mq) deals with this is to convert any work done
         //prior to when the xasession is enlisted in the tx, into work done in the xa tx
        
         tx.delistResource(res, XAResource.TMSUCCESS);
        
         //Now rollback the tx - this should cause redelivery of the two messages
         tx.rollback();
        
         rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         rm3 = cons.receive(1000);
        
         assertNull(rm3);
      }
      finally
      {        
         if (conn != null)
         {
            conn.close();
         }
        
         if (xaConn != null)
         {
            xaConn.close();
         }
      }
   }
View Full Code Here

Examples of javax.jms.XAConnection

   //http://jira.jboss.com/jira/browse/JBMESSAGING-721
   public void testTransactionIdSetAfterCommit() throws Exception
   {
      Connection conn = null;
     
      XAConnection xaConn = null;
     
      try
      {
     
         //First send some messages to a queue
        
         conn = cf.createConnection();
        
         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod = sessSend.createProducer(queue);
        
         TextMessage tm1 = sessSend.createTextMessage("message1");
        
         TextMessage tm2 = sessSend.createTextMessage("message2");
        
         prod.send(tm1);
        
         prod.send(tm2);
        
        
         xaConn = cf.createXAConnection();
        
         XASession xaSession = xaConn.createXASession();
        
         xaConn.start();
        
         MessageConsumer cons = xaSession.createConsumer(queue);
        
         //Now we enlist the session in an xa transaction
        
         XAResource res = xaSession.getXAResource();
        
         tm.begin();
        
         Transaction tx = tm.getTransaction();
         tx.enlistResource(res);
        
         tx.delistResource(res, XAResource.TMSUCCESS);
        
         //Then we do a commit
         tm.commit();
                             
         //Then we receive the messages outside the tx
        
         TextMessage rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         Message rm3 = cons.receive(1000);
        
         assertNull(rm3);
        
         //And enlist again - this should convert the work done in the local tx
         //into the global branch
        
         tx = tm.getTransaction();
        
         tm.begin();
        
         tx = tm.getTransaction();
         tx.enlistResource(res);
        
         tx.delistResource(res, XAResource.TMSUCCESS);        
              
         //Now rollback the tx - this should cause redelivery of the two messages
         tx.rollback();
        
         rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         rm3 = cons.receive(1000);
        
         assertNull(rm3);
      }
      finally
      {        
         if (conn != null)
         {
            conn.close();
         }
        
         if (xaConn != null)
         {
            xaConn.close();
         }
      }

   }
View Full Code Here

Examples of javax.jms.XAConnection

   //http://jira.jboss.com/jira/browse/JBMESSAGING-721
   public void testTransactionIdSetAfterRollback() throws Exception
   {
      Connection conn = null;
     
      XAConnection xaConn = null;
     
      try
      {
     
         //First send some messages to a queue
        
         conn = cf.createConnection();
        
         Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod = sessSend.createProducer(queue);
        
         TextMessage tm1 = sessSend.createTextMessage("message1");
        
         TextMessage tm2 = sessSend.createTextMessage("message2");
        
         prod.send(tm1);
        
         prod.send(tm2);
        
        
         xaConn = cf.createXAConnection();
        
         XASession xaSession = xaConn.createXASession();
        
         xaConn.start();
        
         MessageConsumer cons = xaSession.createConsumer(queue);
        
         //Now we enlist the session in an xa transaction
        
         XAResource res = xaSession.getXAResource();
        
         tm.begin();
        
         Transaction tx = tm.getTransaction();
         tx.enlistResource(res);
         tx.delistResource(res, XAResource.TMSUCCESS);
        
         //Then we do a rollback
         tm.rollback();                
        
         //Then we receive the messages outside the global tx
        
         TextMessage rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         Message rm3 = cons.receive(1000);
        
         assertNull(rm3);
        
         tm.begin();
        
         //And enlist again - the work should then be converted into the global tx branch
        
         tx = tm.getTransaction();
        
         tx.enlistResource(res);
        
         tx.delistResource(res, XAResource.TMSUCCESS);
              
         //Now rollback the tx - this should cause redelivery of the two messages
         tx.rollback();
        
         rm1 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm1);
        
         assertEquals("message1", rm1.getText());
        
         rm2 = (TextMessage)cons.receive(1000);
        
         assertNotNull(rm2);
        
         assertEquals("message2", rm2.getText());
        
         rm3 = cons.receive(1000);
        
         assertNull(rm3);
      }
      finally
      {        
         if (conn != null)
         {
            conn.close();
         }
        
         if (xaConn != null)
         {
            xaConn.close();
         }
      }

   }
View Full Code Here

Examples of javax.jms.XAConnection

      if (!ServerManagement.isRemote())
      {
         return;
      }
     
      XAConnection conn1 = null;
     
      try
      {     
         conn1 = cf.createXAConnection();
  
         XASession sess1 = conn1.createXASession();
  
         XAResource res1 = 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 };
                 
         Xid trailing = new MessagingXid(branchQualifier, 12435, globalTxId);
        
         res1.start(trailing, XAResource.TMNOFLAGS);
  
         MessageProducer prod1 = sess1.createProducer(queue);
  
         TextMessage tm1 = sess1.createTextMessage("testing1");
  
         prod1.send(tm1);
  
         res1.end(trailing, XAResource.TMSUCCESS);
  
  
         res1.prepare(trailing);

  
         //Now "crash" the server
  
         ServerManagement.stopServerPeer();
  
         ServerManagement.startServerPeer();
  
         ServerManagement.deployQueue("Queue");
  
  
         XAResource res = cf.createXAConnection().createXASession().getXAResource();
  
         Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
         assertEquals(1, xids.length);
  
         Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
         assertEquals(0, xids2.length);
        
         Xid trailing2 = xids[0];
        
         assertTrue(trailing.getFormatId() == trailing2.getFormatId());
        
         assertEqualByteArrays(trailing.getGlobalTransactionId(), trailing2.getGlobalTransactionId());
        
         assertEqualByteArrays(trailing.getBranchQualifier(), trailing2.getBranchQualifier());
  
         res.commit(trailing, false);
           
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
      }
      finally
      {
         if (conn1 != null)
         {
            try
            {
               conn1.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
View Full Code Here

Examples of javax.jms.XAConnection

  
   public void test2PCSendCommit1PCOptimization() throws Exception
   {
      //Since both resources have some RM, TM will probably use 1PC optimization
     
      XAConnection conn = null;
      Connection conn2 = null;
     
      try
      {     
         conn = cf.createXAConnection();
        
         tm.begin();
        
         XASession sess = conn.createXASession();
         XAResource res = sess.getXAResource();
        
         XAResource res2 = new DummyXAResource();
        
         Transaction tx = tm.getTransaction();
         tx.enlistResource(res);
         tx.enlistResource(res2);
        
         MessageProducer prod = sess.createProducer(queue);
         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
         Message m = sess.createTextMessage("XATest1");
         prod.send(queue, m);
         m = sess.createTextMessage("XATest2");
         prod.send(queue, m);
        
         tx.delistResource(res, XAResource.TMSUCCESS);
         tx.delistResource(res2, XAResource.TMSUCCESS);
        
         tm.commit();
        
         conn2 = cf.createConnection();
         conn2.start();
         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons = sessReceiver.createConsumer(queue);
         TextMessage m2 = (TextMessage)cons.receive(1000);
         assertNotNull(m2);
         assertEquals("XATest1", m2.getText());
         m2 = (TextMessage)cons.receive(1000);
         assertNotNull(m2);
         assertEquals("XATest2", m2.getText());
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
         if (conn2 != null)
         {
            conn2.close();
         }
View Full Code Here

Examples of javax.jms.XAConnection



   public void test2PCSendCommit() throws Exception
   {
      XAConnection conn = null;
      Connection conn2 = null;

      try
      {

         conn = cf.createXAConnection();

         tm.begin();

         XASession sess = conn.createXASession();

         MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
         XAResource res2 = new DummyXAResource();

         //To prevent 1PC optimization being used
         res.setPreventJoining(true);

         Transaction tx = tm.getTransaction();
         tx.enlistResource(res);
         tx.enlistResource(res2);

         MessageProducer prod = sess.createProducer(queue);
         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
         Message m = sess.createTextMessage("XATest1");
         prod.send(queue, m);
         m = sess.createTextMessage("XATest2");
         prod.send(queue, m);
        
         tx.delistResource(res, XAResource.TMSUCCESS);
         tx.delistResource(res2, XAResource.TMSUCCESS);

         tm.commit();

         conn2 = cf.createConnection();
         conn2.start();
         Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons = sessReceiver.createConsumer(queue);
         TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
         assertNotNull(m2);
         assertEquals("XATest1", m2.getText());
         m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
         assertNotNull(m2);
         assertEquals("XATest2", m2.getText());
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
         if (conn2 != null)
         {
            conn2.close();
         }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.