qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject svn commit: r1153164 - in /qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ systests/src/main/java/org/apache/qpid/jms/ systests/src/main/java/org/apache/qpid/jms/xa/ test-profiles/
Date Tue, 02 Aug 2011 15:28:20 GMT
Author: rajith
Date: Tue Aug  2 15:28:19 2011
New Revision: 1153164

URL: http://svn.apache.org/viewvc?rev=1153164&view=rev
Log:
Merge branch 'QPID-3263' into trunk

Added:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
    qpid/trunk/qpid/java/test-profiles/JavaExcludes

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=1153164&r1=1153163&r2=1153164&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java Tue
Aug  2 15:28:19 2011
@@ -1435,7 +1435,18 @@ public class AMQConnection extends Close
     {
         return _delegate.getProtocolVersion();
     }
-
+    
+    public String getBrokerUUID()
+    {
+        if(getProtocolVersion().equals(ProtocolVersion.v0_10))
+        {
+            return ((AMQConnectionDelegate_0_10)_delegate).getUUID();
+        }
+        else
+        {
+            return null;
+        }
+    }
     public boolean isFailingOver()
     {
         return (_protocolHandler.getFailoverLatch() != null);

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=1153164&r1=1153163&r2=1153164&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
Tue Aug  2 15:28:19 2011
@@ -58,7 +58,11 @@ public class AMQConnectionDelegate_0_10 
      * This class logger.
      */
     private static final Logger _logger = LoggerFactory.getLogger(AMQConnectionDelegate_0_10.class);
-
+    
+    /**
+     * The name of the UUID property
+     */
+    private static final String UUID_NAME = "qpid.federation_tag";
     /**
      * The AMQ Connection.
      */
@@ -343,6 +347,11 @@ public class AMQConnectionDelegate_0_10 
         return ProtocolVersion.v0_10;
     }
     
+    public String getUUID()
+    {
+        return (String)_qpidConnection.getServerProperties().get(UUID_NAME);        
+    }
+    
     private void retriveConnectionSettings(ConnectionSettings conSettings, BrokerDetails
brokerDetail)
     {
 

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java?rev=1153164&r1=1153163&r2=1153164&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java Tue
Aug  2 15:28:19 2011
@@ -21,10 +21,14 @@ import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.apache.qpid.AMQInvalidArgumentException;
 import org.apache.qpid.dtx.XidImpl;
-import org.apache.qpid.transport.*;
-
+import org.apache.qpid.transport.DtxXaStatus;
+import org.apache.qpid.transport.ExecutionErrorCode;
+import org.apache.qpid.transport.Future;
+import org.apache.qpid.transport.Option;
+import org.apache.qpid.transport.RecoverResult;
+import org.apache.qpid.transport.SessionException;
+import org.apache.qpid.transport.XaResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -211,9 +215,28 @@ public class XAResourceImpl implements X
      * @throws XAException An error has occurred. Possible exception values are XAER_RMERR,
XAER_RMFAIL.
      */
     public boolean isSameRM(XAResource xaResource) throws XAException
-    {
-        // TODO : get the server identity of xaResource and compare it with our own one
-        return false;
+    {       
+        if(this == xaResource)
+        {
+            return true;            
+        }       
+        if(!(xaResource instanceof XAResourceImpl))
+        {
+            return false;           
+        }
+        
+        XAResourceImpl other = (XAResourceImpl)xaResource;
+
+        String myUUID = ((AMQSession_0_10)_xaSession).getAMQConnection().getBrokerUUID();
+        String otherUUID = ((AMQSession_0_10)other._xaSession).getAMQConnection().getBrokerUUID();
+        
+        if(_logger.isDebugEnabled())
+        {
+            _logger.debug("Comparing my UUID " + myUUID + " with other UUID " + otherUUID);
+        }
+        
+        return (myUUID != null && otherUUID != null && myUUID.equals(otherUUID));
+                
     }
 
     /**

Added: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java?rev=1153164&view=auto
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
(added)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
Tue Aug  2 15:28:19 2011
@@ -0,0 +1,116 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.xa;
+
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XASession;
+import javax.transaction.xa.XAResource;
+
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.util.FileUtils;
+
+public class XAResourceTest extends QpidBrokerTestCase
+{
+
+    private static final String FACTORY_NAME = "default";
+    private static final String ALT_FACTORY_NAME = "connection2";
+
+    /*
+     * Test with multiple XAResources originating from the same connection factory. XAResource(s)
will be equal,
+     * as they originate from the same session. 
+     */
+    public void testIsSameRMSingleCF() throws Exception
+    {
+        XAConnectionFactory factory = getConnectionFactory(FACTORY_NAME);
+        XAConnection conn = factory.createXAConnection();
+        XASession session = conn.createXASession();
+        XAResource xaResource1 = session.getXAResource();
+        XAResource xaResource2 = session.getXAResource();
+        
+        assertEquals("XAResource objects not equal", xaResource1, xaResource2);
+        assertTrue("isSameRM not true for identical objects", xaResource1.isSameRM(xaResource2));
+        
+        session.close();
+        conn.close();
+    }
+    
+    /*
+     * Test with multiple XAResources originating from different connection factory's and
different sessions. XAResources will not be
+     * equal as they do not originate from the same session. As the UUID from the broker
will be the same, isSameRM will be true.
+     *
+     */
+    public void testIsSameRMMultiCF() throws Exception
+    {
+        startBroker(FAILING_PORT);
+        ConnectionURL url = getConnectionFactory(FACTORY_NAME).getConnectionURL();
+        XAConnectionFactory factory = new AMQConnectionFactory(url);
+        XAConnectionFactory factory2 = new AMQConnectionFactory(url);
+        XAConnectionFactory factory3 = getConnectionFactory(ALT_FACTORY_NAME);
+        
+        XAConnection conn = factory.createXAConnection();
+        XAConnection conn2 = factory2.createXAConnection();
+        XAConnection conn3 = factory3.createXAConnection();
+        
+        XASession session = conn.createXASession();
+        XASession session2 = conn2.createXASession();
+        XASession session3 = conn3.createXASession();
+
+        XAResource xaResource1 = session.getXAResource();
+        XAResource xaResource2 = session2.getXAResource();
+        XAResource xaResource3 = session3.getXAResource();
+        
+        assertFalse("XAResource objects should not be equal", xaResource1.equals(xaResource2));
+        assertTrue("isSameRM not true for identical objects", xaResource1.isSameRM(xaResource2));
+        assertFalse("isSameRM true for XA Resources created by two different brokers", xaResource1.isSameRM(xaResource3));
+        
+        conn.close();
+        conn2.close();
+        conn3.close();                
+    }
+
+    @Override
+    public void stopBroker(int port) throws Exception
+    {
+        if (isBrokerPresent(port))
+        {
+            super.stopBroker(port);
+        }
+    }
+
+    @Override
+    public void tearDown() throws Exception
+    {
+        try
+        {
+            super.tearDown();
+        }
+        finally
+        {
+            // Ensure we shutdown any secondary brokers
+            stopBroker(FAILING_PORT);
+            FileUtils.deleteDirectory(System.getProperty("QPID_WORK") + "/" + getFailingPort());
+        }
+    }
+    
+}

Modified: qpid/trunk/qpid/java/test-profiles/JavaExcludes
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/JavaExcludes?rev=1153164&r1=1153163&r2=1153164&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/JavaExcludes (original)
+++ qpid/trunk/qpid/java/test-profiles/JavaExcludes Tue Aug  2 15:28:19 2011
@@ -87,3 +87,4 @@ org.apache.qpid.server.persistent.NoLoca
 org.apache.qpid.server.configuration.ServerConfigurationFileTest#*
 
 org.apache.qpid.test.unit.client.connection.ConnectionTest#testClientIDVerification
+org.apache.qpid.jms.xa.XAResourceTest#*



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message