|
From: Weston P. <wes...@jb...> - 2006-07-07 02:37:45
|
User: wprice
Date: 06/07/06 22:37:42
Modified: src/main/org/jboss/test/jca/adapter
TestManagedConnection.java
Log:
[JBAS-3336] XAManagedConnections that experience failure issues (XAER_RMFAIL, XAERR_RMERR) during enlistment are no longer returned to the pool but destroyed.
Added support methods to testing framework.
Revision Changes Path
1.18 +47 -3 jbosstest/src/main/org/jboss/test/jca/adapter/TestManagedConnection.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TestManagedConnection.java
===================================================================
RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jca/adapter/TestManagedConnection.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- TestManagedConnection.java 24 Feb 2006 14:26:40 -0000 1.17
+++ TestManagedConnection.java 7 Jul 2006 02:37:42 -0000 1.18
@@ -35,6 +35,7 @@
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData;
+import javax.resource.spi.ResourceAdapterInternalException;
import javax.security.auth.Subject;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
@@ -50,7 +51,7 @@
*
* @author <a href="mailto:d_j...@us...">David Jencks</a>
* @author <a href="mailto:ad...@jb...">Adrian Brock</a>
- * @version <tt>$Revision: 1.17 $</tt>
+ * @version <tt>$Revision: 1.18 $</tt>
*/
public class TestManagedConnection implements ManagedConnection, XAResource, LocalTransaction
{
@@ -77,10 +78,17 @@
private boolean failInPrepare = false;
private boolean failInCommit = false;
- private int xaCode;
+ private static boolean failInStart = false;
+
+ private static int xaCode;
private String localState = LOCAL_NONE;
+ public static void setFailInStart(boolean fis, int xa)
+ {
+ failInStart = fis;
+ xaCode = xa;
+ }
public TestManagedConnection (final TestManagedConnectionFactory mcf, final Subject subject, final TestConnectionRequestInfo cri, final int id)
{
this.mcf = mcf;
@@ -203,6 +211,13 @@
synchronized (this)
{
+ if(failInStart)
+ {
+ XAException xaex = new XAException(xaCode + "for" + this);
+ broadcastConnectionError(xaex);
+ throw new XAException(xaCode + "for" + this);
+ }
+
GlobalXID gid = new GlobalXID(xid);
String flagString = TxUtils.getXAResourceFlagsAsString(flags);
log.info("start with xid=" + gid + " flags=" + flagString + " for " + this);
@@ -467,6 +482,35 @@
}
}
+ protected void broadcastConnectionError(Throwable e)
+ {
+ if(destroyed.get())
+ return;
+
+ Exception ex = null;
+ if (e instanceof Exception)
+ ex = (Exception) e;
+ else
+ ex = new ResourceAdapterInternalException("Unexpected error", e);
+ ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex);
+ Collection copy = null;
+ synchronized(listeners)
+ {
+ copy = new ArrayList(listeners);
+ }
+ for (Iterator i = copy.iterator(); i.hasNext(); )
+ {
+ ConnectionEventListener cel = (ConnectionEventListener)i.next();
+ try
+ {
+ cel.connectionErrorOccurred(ce);
+ }
+ catch (Throwable t)
+ {
+ }
+ }
+ }
+
void connectionError(TestConnection handle, Exception e)
{
if (destroyed.get())
|