[jboss-cvs] JBoss Messaging SVN: r7969 - branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 4 12:43:07 EST 2010


Author: gaohoward
Date: 2010-03-04 12:43:06 -0500 (Thu, 04 Mar 2010)
New Revision: 7969

Modified:
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
Log:
JBMESSAGING-1786
test


Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2010-03-04 17:40:55 UTC (rev 7968)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2010-03-04 17:43:06 UTC (rev 7969)
@@ -21,6 +21,8 @@
   */
 package org.jboss.test.messaging.jms;
 
+import java.io.IOException;
+
 import javax.jms.*;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
@@ -4055,5 +4057,161 @@
       }
    }
 
+   //https://jira.jboss.org/jira/browse/JBMESSAGING-1786
+   public void testRollbackPreparedTxWithoutShutdownServer() throws Exception
+   {
+      log.trace("starting testRollbackPreparedTxWithoutShutdownServer");
+
+      Connection conn1 = null;
+
+      XAConnection conn2 = null;
+
+      XAConnection conn3 = null;
+      
+      try
+      {
+         //First send a message to the queue
+         conn1 = cf.createConnection();
+
+         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer prod = sess1.createProducer(queue4);
+
+         TextMessage tm1 = sess1.createTextMessage("tm1");
+
+         prod.send(tm1);
+
+         conn2 = cf.createXAConnection();
+
+         XASession sess2 = conn2.createXASession();
+
+         XAResource res1 = sess2.getXAResource();
+
+         //Pretend to be a transaction manager by interacting through the XAResources
+         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+
+         res1.start(xid1, XAResource.TMNOFLAGS);
+
+         MessageConsumer cons = sess2.createConsumer(queue4);
+
+         conn2.start();
+
+         //Consume the message
+
+         TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+         assertNotNull(rm1);
+
+         assertEquals(tm1.getText(), rm1.getText());
+
+         res1.end(xid1, XAResource.TMSUCCESS);
+
+         res1.prepare(xid1);
+
+         conn1.close();
+
+         conn2.close();
+
+         conn1 = null;
+
+         conn2 = null;
+
+         conn1 = cf.createConnection();
+
+         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer cons1 = sess1.createConsumer(queue4);
+
+         conn1.start();
+
+         TextMessage m = (TextMessage)cons1.receive(2000);
+
+         assertNull(m);
+
+         //Now recover
+
+         conn3 = cf.createXAConnection();
+
+         XASession sess3 = conn3.createXASession();
+
+         XAResource res3 = sess3.getXAResource();
+
+         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
+         assertEquals(1, xids.length);
+
+         //rollback
+         res3.rollback(xids[0]);
+
+         //The message should be acknowldged
+         conn3.close();
+
+         m = (TextMessage)cons1.receive(2000);
+         
+         assertNotNull(m);
+         
+         assertEquals("tm1", m.getText());
+
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn2 != null)
+         {
+            try
+            {
+               conn2.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+
+         if (conn3 != null)
+         {
+            try
+            {
+               conn3.close();
+            }
+            catch (Exception e)
+            {
+               //Ignore
+            }
+         }
+         
+         System.clearProperty("retain.oldxabehaviour");
+
+      }
+   }
+   
+   private void pause(String prompt)
+   {
+      
+      System.out.println(prompt);
+      
+      try
+      {
+         System.in.read();
+      }
+      catch (IOException e)
+      {
+         // TODO Auto-generated catch block
+         e.printStackTrace();
+      }
+      
+      System.out.println("going on...");
+   }
+
 }
 




More information about the jboss-cvs-commits mailing list