summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2011-08-02 15:28:19 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2011-08-02 15:28:19 +0000
commit0162322d42698aa2c7b99a82c55a16fcccee38c8 (patch)
tree9c61f1c316c3eb71daa3520f243d1f8776a0807f /java
parent91a104cfe511c4448a6aaaed6308632d912e9594 (diff)
downloadqpid-python-0162322d42698aa2c7b99a82c55a16fcccee38c8.tar.gz
QPID-3263 Applying patch from Weston Price with the following modifications.
1. The test case now extends QpidBrokerTestCase instead of TestCase to ensure that it can run under the automated ant builds. 2. Added an additional case to testIsSameRMMultiCF to ensure that isSameRM() returns false for two XAResources created from two different brokers. 3. Excluded this test from the Java test profiles. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1153164 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnection.java13
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java11
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java35
-rw-r--r--java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java116
-rw-r--r--java/test-profiles/JavaExcludes1
5 files changed, 168 insertions, 8 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index fd21b376ac..4a62f443f1 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -1435,7 +1435,18 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
{
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);
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
index e1643f095d..cb531d4fca 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
@@ -58,7 +58,11 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
* 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 implements AMQConnectionDelegate, Connec
return ProtocolVersion.v0_10;
}
+ public String getUUID()
+ {
+ return (String)_qpidConnection.getServerProperties().get(UUID_NAME);
+ }
+
private void retriveConnectionSettings(ConnectionSettings conSettings, BrokerDetails brokerDetail)
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java b/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
index 8a75082202..5b94b342eb 100644
--- a/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
+++ b/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
@@ -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 XAResource
* @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));
+
}
/**
diff --git a/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java b/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
new file mode 100644
index 0000000000..d7ee203fdf
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/jms/xa/XAResourceTest.java
@@ -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());
+ }
+ }
+
+}
diff --git a/java/test-profiles/JavaExcludes b/java/test-profiles/JavaExcludes
index 57d7681e9c..4be228c7da 100644
--- a/java/test-profiles/JavaExcludes
+++ b/java/test-profiles/JavaExcludes
@@ -87,3 +87,4 @@ org.apache.qpid.server.persistent.NoLocalAfterRecoveryTest#*
org.apache.qpid.server.configuration.ServerConfigurationFileTest#*
org.apache.qpid.test.unit.client.connection.ConnectionTest#testClientIDVerification
+org.apache.qpid.jms.xa.XAResourceTest#*