[jboss-cvs] JBoss Messaging SVN: r1678 - branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 1 21:24:06 EST 2006


Author: juha at jboss.org
Date: 2006-12-01 21:24:04 -0500 (Fri, 01 Dec 2006)
New Revision: 1678

Modified:
   branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
Log:
run the mock coordinator test using JbossTS XID implementation

Modified: branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2006-12-02 02:23:02 UTC (rev 1677)
+++ branches/Branch_1_0_XARecovery/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2006-12-02 02:24:04 UTC (rev 1678)
@@ -31,6 +31,7 @@
 import javax.jms.XASession;
 import javax.naming.InitialContext;
 import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
@@ -40,6 +41,9 @@
 import org.jboss.test.messaging.tools.ServerManagement;
 import org.jboss.test.messaging.util.TransactionManagerLocator;
 
+import com.arjuna.ats.jta.xa.XidImple;
+import com.arjuna.ats.arjuna.common.Uid;
+
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
@@ -96,7 +100,7 @@
 
    // Public --------------------------------------------------------
    
-   /*
+
    public void testJBossTSCoordinator() throws Exception
    {
       UserTransaction ut = com.arjuna.ats.jta.UserTransaction.userTransaction();
@@ -106,8 +110,8 @@
 
       ut.commit();
    }
-   */
 
+
    public void testMockCoordinatorRecovery() throws Exception
    {
 
@@ -200,5 +204,196 @@
    }
 
 
+   public void testMockCoordinatorRecoveryWithJBossTSXids() throws Exception
+   {
+
+      XAConnection conn1 = cf.createXAConnection();
+
+      XAConnection conn2 = cf.createXAConnection();
+
+      XASession sess1 = conn1.createXASession();
+
+      XASession sess2 = conn2.createXASession();
+
+      XAResource res1 = sess1.getXAResource();
+
+      XAResource res2 = sess2.getXAResource();
+
+      //Pretend to be a transaction manager by interacting through the XAResources
+      Xid xid1 = new XidImple(new Uid("gbtxid1"), new Uid("bq1"), 123);
+      Xid xid2 = new XidImple(new Uid("gbtxid2"), new Uid("bq2"), 124);
+
+
+      //    Send a message in each tx
+
+      res1.start(xid1, XAResource.TMNOFLAGS);
+
+      MessageProducer prod1 = sess1.createProducer(queue);
+
+      TextMessage tm1 = sess1.createTextMessage("testing1");
+
+      prod1.send(tm1);
+
+      res1.end(xid1, XAResource.TMSUCCESS);
+
+
+      res2.start(xid2, XAResource.TMNOFLAGS);
+
+      MessageProducer prod2 = sess2.createProducer(queue);
+
+      TextMessage tm2 = sess2.createTextMessage("testing2");
+
+      prod2.send(tm2);
+
+      res2.end(xid2, XAResource.TMSUCCESS);
+
+      //prepare both txs
+
+
+      res1.prepare(xid1);
+      res2.prepare(xid2);
+
+      //Now "crash" the server
+
+      ServerManagement.stopServerPeer();
+
+      ServerManagement.startServerPeer();
+
+
+      XAResource res = cf.createXAConnection().createXASession().getXAResource();
+
+      Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
+      assertEquals(2, xids.length);
+
+      Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
+      assertEquals(0, xids2.length);
+
+      assertTrue(xids[0].equals(xid1) || xids[1].equals(xid1));
+      assertTrue(xids[0].equals(xid2) || xids[1].equals(xid2));
+
+
+      res.commit(xid1, false);
+
+      res.commit(xid2, false);
+
+      ServerManagement.deployQueue("Queue");
+
+      Connection conn3 = cf.createConnection();
+
+      Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageConsumer cons = sessRec.createConsumer(queue);
+      conn3.start();
+
+      TextMessage m1 = (TextMessage)cons.receiveNoWait();
+      assertNotNull(m1);
+      assertEquals("testing1", m1.getText());
+
+      TextMessage m2 = (TextMessage)cons.receiveNoWait();
+      assertNotNull(m2);
+
+      assertEquals("testing2", m2.getText());
+
+      conn3.close();
+
+   }
+/*
+   public void testMockCoordinatorRecovery3() throws Exception
+   {
+
+      XAConnection conn1 = cf.createXAConnection();
+
+      XAConnection conn2 = cf.createXAConnection();
+
+      XASession sess1 = conn1.createXASession();
+
+      XASession sess2 = conn2.createXASession();
+
+      XAResource res1 = sess1.getXAResource();
+
+      XAResource res2 = sess2.getXAResource();
+
+      //Pretend to be a transaction manager by interacting through the XAResources
+      Xid xid1 = new XidImpl("bq1".getBytes(), 123, "gbtxid1".getBytes());
+      Xid xid2 = new XidImpl("bq2".getBytes(), 124, "gbtxid2".getBytes());
+
+      //    Send a message in each tx
+
+      res1.start(xid1, XAResource.TMNOFLAGS);
+
+      MessageProducer prod1 = sess1.createProducer(queue);
+
+      TextMessage tm1 = sess1.createTextMessage("testing1");
+
+      prod1.send(tm1);
+
+      res1.end(xid1, XAResource.TMSUCCESS);
+
+
+      res2.start(xid2, XAResource.TMNOFLAGS);
+
+      MessageProducer prod2 = sess2.createProducer(queue);
+
+      TextMessage tm2 = sess2.createTextMessage("testing2");
+
+      prod2.send(tm2);
+
+      res2.end(xid2, XAResource.TMSUCCESS);
+
+      //prepare both txs
+
+
+      res1.prepare(xid1);
+      res2.prepare(xid2);
+
+      //Now "crash" the server
+
+      ServerManagement.stopServerPeer();
+
+      ServerManagement.startServerPeer();
+
+      XAResource res = cf.createXAConnection().createXASession().getXAResource();
+
+      Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
+      assertEquals(2, xids.length);
+
+      Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
+      assertEquals(0, xids2.length);
+
+      assertTrue(xids[0].equals(xid1) || xids[1].equals(xid1));
+      assertTrue(xids[0].equals(xid2) || xids[1].equals(xid2));
+
+      res.commit(xids[0], false);
+
+      res.commit(xids[1], false);
+
+      ServerManagement.deployQueue("Queue");
+
+      Connection conn3 = cf.createConnection();
+
+      Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageConsumer cons = sessRec.createConsumer(queue);
+      conn3.start();
+
+      TextMessage m1 = (TextMessage)cons.receiveNoWait();
+      assertNotNull(m1);
+      assertEquals("testing1", m1.getText());
+
+      TextMessage m2 = (TextMessage)cons.receiveNoWait();
+      assertNotNull(m2);
+
+      assertEquals("testing2", m2.getText());
+
+      conn3.close();
+
+   }
+*/
+   public void testXidEquals()
+   {
+      Xid xid1 = new XidImple(new Uid("gbtxid1"), new Uid("bq1"), 123);
+      Xid xid2 = new XidImpl("bq1".getBytes(), 123, "gbtxid1".getBytes());
+
+      assertEquals(xid1, xid2);
+
+   }
 }
 




More information about the jboss-cvs-commits mailing list