[jboss-cvs] JBoss Messaging SVN: r4444 - in trunk: src/main/org/jboss/messaging/core/remoting/impl/wireformat and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 12 08:35:29 EDT 2008


Author: timfox
Date: 2008-06-12 08:35:29 -0400 (Thu, 12 Jun 2008)
New Revision: 4444

Modified:
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXACommitMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAEndMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAForgetMessage.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientSessionImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
More tests


Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -629,6 +629,7 @@
    
    public void commit(final Xid xid, final boolean onePhase) throws XAException
    {
+      checkXA();
       try
       { 
          SessionXACommitMessage packet = new SessionXACommitMessage(xid, onePhase);
@@ -650,6 +651,7 @@
 
    public void end(final Xid xid, final int flags) throws XAException
    {
+      checkXA();
       try
       {
          Packet packet;
@@ -691,6 +693,7 @@
 
    public void forget(final Xid xid) throws XAException
    {
+      checkXA();
       try
       {                              
          //Need to flush any acks to server first
@@ -712,6 +715,7 @@
 
    public int getTransactionTimeout() throws XAException
    {
+      checkXA();
       try
       {                              
          SessionXAGetTimeoutResponseMessage response =
@@ -728,6 +732,7 @@
 
    public boolean isSameRM(final XAResource xares) throws XAException
    {
+      checkXA();
       if (!(xares instanceof ClientSessionImpl))
       {
          return false;
@@ -746,6 +751,7 @@
 
    public int prepare(final Xid xid) throws XAException
    {
+      checkXA();
       try
       {
          SessionXAPrepareMessage packet = new SessionXAPrepareMessage(xid);
@@ -771,6 +777,7 @@
 
    public Xid[] recover(final int flag) throws XAException
    {
+      checkXA();
       try
       {
          SessionXAGetInDoubtXidsResponseMessage response = (SessionXAGetInDoubtXidsResponseMessage)remotingConnection.sendBlocking(serverTargetID, serverTargetID, new EmptyPacket(EmptyPacket.SESS_XA_INDOUBT_XIDS));
@@ -790,6 +797,7 @@
 
    public void rollback(final Xid xid) throws XAException
    {
+      checkXA();
       try
       {
          SessionXARollbackMessage packet = new SessionXARollbackMessage(xid);
@@ -811,6 +819,7 @@
 
    public boolean setTransactionTimeout(final int seconds) throws XAException
    {
+      checkXA();
       try
       {                              
          SessionXASetTimeoutResponseMessage response =
@@ -827,6 +836,7 @@
 
    public void start(final Xid xid, final int flags) throws XAException
    {
+      checkXA();
       try
       {
          Packet packet;
@@ -883,6 +893,15 @@
 
    // Private --------------------------------------------------------------------------------------
    
+   private void checkXA() throws XAException
+   {
+      if (!xa)
+      {
+         log.error("Session is not XA");
+         throw new XAException(XAException.XAER_RMERR);
+      }
+   }
+   
    private void acknowledgeInternal(final boolean block) throws MessagingException
    {
       if (acked)

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXACommitMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXACommitMessage.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXACommitMessage.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -73,6 +73,19 @@
       return getParentString() + ", xid=" + xid + ", onePhase=" + onePhase + "]";
    }
    
+   public boolean equals(Object other)
+   {
+      if (other instanceof SessionXACommitMessage == false)
+      {
+         return false;
+      }
+            
+      SessionXACommitMessage r = (SessionXACommitMessage)other;
+      
+      return this.xid.equals(r.xid) &&
+             this.onePhase == r.onePhase;
+   }
+   
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAEndMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAEndMessage.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAEndMessage.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -73,6 +73,19 @@
    {
       return getParentString() + ", xid=" + xid + ", failed=" + failed + "]";
    }
+   
+   public boolean equals(Object other)
+   {
+      if (other instanceof SessionXAEndMessage == false)
+      {
+         return false;
+      }
+            
+      SessionXAEndMessage r = (SessionXAEndMessage)other;
+      
+      return this.xid.equals(r.xid) &&
+             this.failed == r.failed;
+   }
 
    // Package protected ---------------------------------------------
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAForgetMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAForgetMessage.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionXAForgetMessage.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -57,6 +57,18 @@
       xid = XidCodecSupport.decodeXid(buffer);
    }
    
+   public boolean equals(Object other)
+   {
+      if (other instanceof SessionXAForgetMessage == false)
+      {
+         return false;
+      }
+            
+      SessionXAForgetMessage r = (SessionXAForgetMessage)other;
+      
+      return this.xid.equals(r.xid);
+   }
+   
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientSessionImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientSessionImplTest.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/ClientSessionImplTest.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -21,7 +21,11 @@
  */
 package org.jboss.messaging.tests.unit.core.client.impl;
 
+import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
+
+import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
 
 import org.easymock.EasyMock;
 import org.jboss.messaging.core.client.ClientBrowser;
@@ -34,7 +38,9 @@
 import org.jboss.messaging.core.client.impl.ClientProducerPacketHandler;
 import org.jboss.messaging.core.client.impl.ClientSessionImpl;
 import org.jboss.messaging.core.client.impl.ClientSessionInternal;
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.RemotingConnection;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowCreditMessage;
@@ -53,6 +59,10 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionRemoveDestinationMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResponseMessage;
 import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.util.SimpleString;
 
@@ -495,7 +505,7 @@
       assertTrue(producer2 == producer3);
       assertFalse(producer1 == producer4);
       assertFalse(producer2 == producer4);
-      assertFalse(producer3 == producer4);
+      assertFalse(producer3 == producer4);      
    }
    
    public void testProducerNoCaching() throws Exception
@@ -826,7 +836,7 @@
       
       EasyMock.verify(conn, rc, prod1, prod2, cons1, cons2, browser1, browser2);
       
-      assertTrue(session.isClosed());
+      assertTrue(session.isClosed());           
    }
    
    public void testAddRemoveConsumer() throws Exception
@@ -913,9 +923,206 @@
       assertEquals(0, session.getBrowsers().size()); 
    }
    
+   public void testXACommit() throws Exception
+   {
+      testXACommit(false, false);
+      testXACommit(false, true);
+      testXACommit(true, false);
+      testXACommit(true, true);
+   }
    
+   public void testXAEnd() throws Exception
+   {
+      testXAEnd(XAResource.TMSUSPEND, false);
+      testXAEnd(XAResource.TMSUSPEND, true);
+      testXAEnd(XAResource.TMSUCCESS, false);
+      testXAEnd(XAResource.TMSUCCESS, true);
+      testXAEnd(XAResource.TMFAIL, false);
+      testXAEnd(XAResource.TMFAIL, true);
+   }
+   
+   public void testXAForget() throws Exception
+   {
+      testXAForget(false);
+      testXAForget(true);
+   }
+   
+   
+   
+   
+   
+   
    // Private -------------------------------------------------------------------------------------------
 
+   private void testXAForget(final boolean error) throws Exception
+   {
+      ClientConnectionInternal conn = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+          
+      //In ClientSessionImpl constructor
+      EasyMock.expect(conn.getRemotingConnection()).andReturn(rc);
+        
+      final long sessionTargetID = 9121892;
+      
+      Xid xid = randomXid();
+      
+      Packet packet = new SessionXAForgetMessage(xid);
+
+      final int numMessages = 10;
+      
+      SessionAcknowledgeMessage msg = new SessionAcknowledgeMessage(numMessages - 1, true);
+      
+      rc.sendOneWay(sessionTargetID, sessionTargetID, msg);
+      
+      SessionXAResponseMessage resp = new SessionXAResponseMessage(error, XAException.XAER_RMERR, "blah");
+      
+      EasyMock.expect(rc.sendBlocking(sessionTargetID, sessionTargetID, packet)).andReturn(resp);
+                       
+      EasyMock.replay(conn, rc);
+      
+      ClientSessionInternal session = new ClientSessionImpl(conn, sessionTargetID, true, -1, false, false, false, false);
+      
+      //Simulate some unflushed messages
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         session.delivered(i, false);
+         session.acknowledge();
+      }
+      
+      if (error)
+      {
+         try
+         {
+            session.forget(xid);
+            fail("Should throw exception");
+         }
+         catch (XAException e)
+         {
+            assertEquals(XAException.XAER_RMERR, e.errorCode);
+         }
+      }
+      else
+      {
+         session.forget(xid);
+      }
+      
+      EasyMock.verify(conn, rc);           
+   }
+   
+   private void testXAEnd(int flags, boolean error) throws Exception
+   {
+      ClientConnectionInternal conn = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+          
+      //In ClientSessionImpl constructor
+      EasyMock.expect(conn.getRemotingConnection()).andReturn(rc);
+        
+      final long sessionTargetID = 9121892;
+      
+      Xid xid = randomXid();
+      
+      Packet packet = null;
+      if (flags == XAResource.TMSUSPEND)
+      {
+         packet = new EmptyPacket(EmptyPacket.SESS_XA_SUSPEND);                  
+      }
+      else if (flags == XAResource.TMSUCCESS)
+      {
+         packet = new SessionXAEndMessage(xid, false);
+      }
+      else if (flags == XAResource.TMFAIL)
+      {
+         packet = new SessionXAEndMessage(xid, true);
+      }
+
+      final int numMessages = 10;
+      
+      SessionAcknowledgeMessage msg = new SessionAcknowledgeMessage(numMessages - 1, true);
+      
+      rc.sendOneWay(sessionTargetID, sessionTargetID, msg);
+      
+      SessionXAResponseMessage resp = new SessionXAResponseMessage(error, XAException.XAER_RMERR, "blah");
+      
+      EasyMock.expect(rc.sendBlocking(sessionTargetID, sessionTargetID, packet)).andReturn(resp);
+                       
+      EasyMock.replay(conn, rc);
+      
+      ClientSessionInternal session = new ClientSessionImpl(conn, sessionTargetID, true, -1, false, false, false, false);
+      
+      //Simulate some unflushed messages
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         session.delivered(i, false);
+         session.acknowledge();
+      }
+      
+      if (error)
+      {
+         try
+         {
+            session.end(xid, flags);
+            fail("Should throw exception");
+         }
+         catch (XAException e)
+         {
+            assertEquals(XAException.XAER_RMERR, e.errorCode);
+         }
+      }
+      else
+      {
+         session.end(xid, flags);
+      }
+      
+      EasyMock.verify(conn, rc);          
+   }
+   
+   private void testXACommit(boolean onePhase, boolean error) throws Exception
+   {
+      ClientConnectionInternal conn = EasyMock.createStrictMock(ClientConnectionInternal.class);
+      
+      RemotingConnection rc = EasyMock.createStrictMock(RemotingConnection.class);
+          
+      //In ClientSessionImpl constructor
+      EasyMock.expect(conn.getRemotingConnection()).andReturn(rc);
+        
+      final long sessionTargetID = 9121892;
+      
+      Xid xid = randomXid();
+      
+      SessionXACommitMessage packet = new SessionXACommitMessage(xid, onePhase);
+      
+      SessionXAResponseMessage resp = new SessionXAResponseMessage(error, XAException.XAER_RMERR, "blah");
+      
+      EasyMock.expect(rc.sendBlocking(sessionTargetID, sessionTargetID, packet)).andReturn(resp);
+                       
+      EasyMock.replay(conn, rc);
+      
+      ClientSessionInternal session = new ClientSessionImpl(conn, sessionTargetID, true, -1, false, false, false, false);
+      
+      if (error)
+      {
+         try
+         {
+            session.commit(xid, onePhase);
+            fail("Should throw exception");
+         }
+         catch (XAException e)
+         {
+            assertEquals(XAException.XAER_RMERR, e.errorCode);
+         }
+      }
+      else
+      {
+         session.commit(xid, onePhase);
+      }
+      
+      EasyMock.verify(conn, rc);  
+   }
+   
    private void testAddRemoveConsumer(boolean delivered) throws Exception
    {
       ClientConnectionInternal conn = EasyMock.createStrictMock(ClientConnectionInternal.class);

Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2008-06-12 11:25:16 UTC (rev 4443)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2008-06-12 12:35:29 UTC (rev 4444)
@@ -263,6 +263,4 @@
       return ((size / alignment) + (size % alignment != 0 ? 1 : 0)) * alignment;
    }
 
-   
-
 }




More information about the jboss-cvs-commits mailing list