[jboss-cvs] JBoss Messaging SVN: r6737 - in branches/Branch_1_4: tests and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 12 05:11:49 EDT 2009
Author: gaohoward
Date: 2009-05-12 05:11:49 -0400 (Tue, 12 May 2009)
New Revision: 6737
Added:
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/ASRecoveryTest.java
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/MockMessagingXAResourceWrapper.java
Modified:
branches/Branch_1_4/src/main/org/jboss/jms/server/recovery/MessagingXAResourceWrapper.java
branches/Branch_1_4/tests/build.xml
Log:
JBMESSAGING-1608
Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/recovery/MessagingXAResourceWrapper.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/recovery/MessagingXAResourceWrapper.java 2009-05-12 01:24:35 UTC (rev 6736)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/recovery/MessagingXAResourceWrapper.java 2009-05-12 09:11:49 UTC (rev 6737)
@@ -23,6 +23,7 @@
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
+import javax.jms.Session;
import javax.jms.XAConnection;
import javax.jms.XAConnectionFactory;
import javax.jms.XASession;
@@ -289,7 +290,44 @@
synchronized (lock)
{
if (delegate != null)
- return delegate;
+ {
+ boolean stillOK = true;
+
+ //verify connection
+ Session s = null;
+ try
+ {
+ s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+ catch (JMSException e)
+ {
+ stillOK = false;
+ try
+ {
+ connection.close();
+ connection = null;
+ }
+ catch (JMSException ex)
+ {
+ //ignore
+ }
+ }
+ finally
+ {
+ if (s != null)
+ {
+ s.close();
+ }
+ }
+ if (stillOK)
+ {
+ return delegate;
+ }
+ else
+ {
+ delegate = null;
+ }
+ }
}
// Create the connection
Modified: branches/Branch_1_4/tests/build.xml
===================================================================
--- branches/Branch_1_4/tests/build.xml 2009-05-12 01:24:35 UTC (rev 6736)
+++ branches/Branch_1_4/tests/build.xml 2009-05-12 09:11:49 UTC (rev 6737)
@@ -351,6 +351,7 @@
<include name="**/messaging/core/**/${test-mask}.class" />
<include name="**/jms/**/${test-mask}.class" />
<include name="**/messaging/util/**/${test-mask}.class" />
+ <exclude name="**/jms/server/recovery/**" />
<exclude name="**/jms/DeliveryOnConnectionFailureTest.class" />
<exclude name="**/jms/MemLeakTest.class" />
<exclude name="**/jms/RemotingConnectionConfigurationTest.class" />
@@ -450,7 +451,7 @@
<include name="**/jms/message/**/${test-mask}.class" />
<include name="**/jms/selector/${test-mask}.class" />
<include name="**/jms/crash/${test-mask}.class" />
-
+ <include name="**/jms/server/recovery/${test-mask}.class" />
<exclude name="**/jms/WireFormatTest.class" />
<exclude name="**/jms/ReferencingTest.class" />
<exclude name="**/jms/PersistenceTest.class" />
Added: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/ASRecoveryTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/ASRecoveryTest.java (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/ASRecoveryTest.java 2009-05-12 09:11:49 UTC (rev 6737)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.messaging.jms.server.recovery;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.jms.ConnectionFactory;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ *
+ * ASRecoverytest
+ *
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ *
+ */
+public class ASRecoveryTest extends MessagingTestCase
+{
+ protected static ConnectionFactory cf0;
+
+ protected static Properties targetProps;
+
+ public ASRecoveryTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ //Start the servers
+
+ ServerManagement.start(0, "all", true);
+
+ setUpAdministeredObjects();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ protected void setUpAdministeredObjects() throws Exception
+ {
+ Hashtable props1 = ServerManagement.getJNDIEnvironment(0);
+ targetProps = new Properties();
+ Enumeration keys = props1.keys();
+ while (keys.hasMoreElements())
+ {
+ Object key = keys.nextElement();
+ targetProps.put(key, props1.get(key));
+ }
+ }
+
+ public void testRemoteXAResourceReconnect() throws Exception
+ {
+ MockMessagingXAResourceWrapper wrapper = new MockMessagingXAResourceWrapper(targetProps);
+
+ XAResource res = wrapper.getDelegate();
+
+ assertNotNull(res);
+
+ res.recover(XAResource.TMENDRSCAN);
+
+ //get again
+ res = wrapper.getDelegate();
+
+ res.recover(XAResource.TMENDRSCAN);
+
+ //kill the server
+ ServerManagement.kill(0);
+
+ try
+ {
+ res = wrapper.getDelegate();
+ fail("should have thrown an exception due to lose of server!");
+ }
+ catch (Exception e)
+ {
+ //fine.
+ }
+
+ //Start the server again.
+
+ ServerManagement.start(0, "all", true);
+
+ setUpAdministeredObjects();
+
+ //get again.
+ res = wrapper.getDelegate();
+
+ assertNotNull(res);
+
+ //should work again.
+ res.recover(XAResource.TMENDRSCAN);
+
+ wrapper.close();
+ }
+
+
+ // Inner classes -------------------------------------------------------------------
+
+}
+
Added: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/MockMessagingXAResourceWrapper.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/MockMessagingXAResourceWrapper.java (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/recovery/MockMessagingXAResourceWrapper.java 2009-05-12 09:11:49 UTC (rev 6737)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.test.messaging.jms.server.recovery;
+
+import java.util.Hashtable;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.XAConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.jms.jndi.JMSProviderAdapter;
+import org.jboss.jms.server.recovery.MessagingXAResourceWrapper;
+import org.jboss.util.naming.Util;
+
+/**
+ * A MockMessagingXAResourceWrapper
+ *
+ * @author howard
+ *
+ * Created May 12, 2009 11:34:08 AM
+ *
+ *
+ */
+public class MockMessagingXAResourceWrapper extends MessagingXAResourceWrapper
+{
+
+ private Hashtable icProp;
+
+ public MockMessagingXAResourceWrapper(Hashtable prop)
+ {
+ super("fakeProvider", null, null);
+ icProp = prop;
+ }
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ protected XAConnectionFactory getConnectionFactory() throws Exception
+ {
+ InitialContext ic = null;
+ try
+ {
+ ic = new InitialContext(icProp);
+
+ XAConnectionFactory xaFact = (XAConnectionFactory)ic.lookup("/XAConnectionFactory");
+
+ return xaFact;
+ }
+ finally
+ {
+ if (ic != null)
+ {
+ ic.close();
+ }
+ }
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list