geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r942259 - in /geronimo/components/txmanager/trunk/geronimo-transaction/src: main/java/org/apache/geronimo/transaction/manager/ test/java/org/apache/geronimo/transaction/manager/ test/resources/META-INF/
Date Fri, 07 May 2010 22:42:09 GMT
Author: djencks
Date: Fri May  7 22:42:08 2010
New Revision: 942259

URL: http://svn.apache.org/viewvc?rev=942259&view=rev
Log:
GERONIMO-5289 add some heuristic tests, and fix everCommit test

Added:
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
  (with props)
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
  (contents, props changed)
      - copied, changed from r942257, geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
Removed:
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
Modified:
    geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/CommitTask.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResource.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResourceManager.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/ProtocolTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/XidImporterTest.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/resources/META-INF/NOTICE.txt

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/CommitTask.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/CommitTask.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/CommitTask.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/CommitTask.java
Fri May  7 22:42:08 2010
@@ -68,6 +68,7 @@ public class CommitTask implements Runna
             try {
                 try {
                     manager.getCommitter().commit(manager.getBranchId(), false);
+                    evercommit = true;
                     i.remove();
                 } catch (XAException e) {
                     log.error("Unexpected exception committing " + manager.getCommitter()
+ "; continuing to commit other RMs", e);

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
Fri May  7 22:42:08 2010
@@ -757,7 +757,7 @@ public class TransactionImpl implements 
         XAException cause = commitTask.getCause();
         boolean evercommit = commitTask.isEvercommit();
         if (cause != null) {
-            if (cause.errorCode == XAException.XA_HEURRB&& !evercommit) {
+            if (cause.errorCode == XAException.XA_HEURRB && !evercommit) {
                 throw (HeuristicRollbackException) new HeuristicRollbackException("Error
during two phase commit").initCause(cause);
             } else if (cause.errorCode == XAException.XA_HEURRB && evercommit) {
                 throw (HeuristicMixedException) new HeuristicMixedException("Error during
two phase commit").initCause(cause);

Added: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java?rev=942259&view=auto
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
(added)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
Fri May  7 22:42:08 2010
@@ -0,0 +1,130 @@
+/*
+ * 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.geronimo.transaction.manager;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.xa.XAException;
+import junit.framework.TestCase;
+
+/**
+ * Test all combinations of heuristic error codes except XA_HEURHAZ
+ * @version $Rev$ $Date$
+ */
+public class HeuristicTest extends TestCase {
+
+    TransactionLog transactionLog = new MockLog();
+
+    TransactionManagerImpl tm;
+
+    protected void setUp() throws Exception {
+        tm = new TransactionManagerImpl(10,
+                new XidFactoryImpl("WHAT DO WE CALL IT?".getBytes()), transactionLog);
+    }
+
+    protected void tearDown() throws Exception {
+        tm = null;
+    }
+
+    public void test_C_C() throws Exception {
+        expectSuccess(0,0);
+    }
+    public void test_C_HC() throws Exception {
+        expectSuccess(0,XAException.XA_HEURCOM);
+    }
+    public void test_C_HM() throws Exception {
+        expectHeuristicMixedException(0, XAException.XA_HEURMIX);
+    }
+    public void test_C_HR() throws Exception {
+        expectHeuristicMixedException(0, XAException.XA_HEURRB);
+    }
+
+    public void test_HC_C() throws Exception {
+        expectSuccess(XAException.XA_HEURCOM,0);
+    }
+    public void test_HC_HC() throws Exception {
+        expectSuccess(XAException.XA_HEURCOM, XAException.XA_HEURCOM);
+    }
+    public void test_HC_HM() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURCOM, XAException.XA_HEURMIX);
+    }
+    public void test_HC_HR() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURCOM, XAException.XA_HEURRB);
+    }
+
+    public void test_HM_C() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURMIX, 0);
+    }
+    public void test_HM_HC() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURMIX, XAException.XA_HEURCOM);
+    }
+    public void test_HM_HM() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURMIX, XAException.XA_HEURMIX);
+    }
+    public void test_HM_HR() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURMIX, XAException.XA_HEURRB);
+    }
+
+
+    public void test_HR_C() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURRB, 0);
+    }
+    public void test_HR_HC() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURRB, XAException.XA_HEURCOM);
+    }
+    public void test_HR_HM() throws Exception {
+        expectHeuristicMixedException(XAException.XA_HEURRB, XAException.XA_HEURMIX);
+    }
+    public void test_HR_HR() throws Exception {
+        expectHeuristicRollbackException(XAException.XA_HEURRB, XAException.XA_HEURRB);
+    }
+
+
+    public void expectSuccess(int first, int second) throws Exception {
+        tm.begin();
+        tm.getTransaction().enlistResource(new MockResource("1", first));
+        tm.getTransaction().enlistResource(new MockResource("2", second));
+        tm.commit();
+    }
+    public void expectHeuristicMixedException(int first, int second) throws Exception {
+        tm.begin();
+        tm.getTransaction().enlistResource(new MockResource("1", first));
+        tm.getTransaction().enlistResource(new MockResource("2", second));
+        try {
+            tm.commit();
+            fail();
+        } catch (HeuristicMixedException e) {
+            //expected
+        }
+    }
+    public void expectHeuristicRollbackException(int first, int second) throws Exception
{
+        tm.begin();
+        tm.getTransaction().enlistResource(new MockResource("1", first));
+        tm.getTransaction().enlistResource(new MockResource("2", second));
+        try {
+            tm.commit();
+            fail();
+        } catch (HeuristicRollbackException e) {
+            //expected
+        }
+    }
+
+}

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/HeuristicTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResource.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResource.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResource.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResource.java
Fri May  7 22:42:08 2010
@@ -36,15 +36,22 @@ public class MockResource implements Nam
     private boolean prepared;
     private boolean committed;
     private boolean rolledback;
-    private Set preparedXids = new HashSet();
-    private Set knownXids = new HashSet();
-    private Set finishedXids = new HashSet();//end was called with TMSUCCESS or TMFAIL
+    private Set<Xid> preparedXids = new HashSet<Xid>();
+    private Set<Xid> knownXids = new HashSet<Xid>();
+    private Set<Xid> finishedXids = new HashSet<Xid>();//end was called with
TMSUCCESS or TMFAIL
+    private int errorStatus;
 
     public MockResource(MockResourceManager manager, String xaResourceName) {
         this.manager = manager;
         this.xaResourceName = xaResourceName;
     }
 
+    public MockResource(String xaResourceName, int errorStatus) {
+        this.manager = new MockResourceManager();
+        this.xaResourceName = xaResourceName;
+        this.errorStatus = errorStatus;
+    }
+
     public int getTransactionTimeout() throws XAException {
         return timeout;
     }
@@ -110,6 +117,9 @@ public class MockResource implements Nam
         if (!finishedXids.contains(xid)) {
             throw new XAException(XAException.XAER_PROTO);
         }
+        if (errorStatus != 0) {
+            throw new XAException(errorStatus);
+        }
         preparedXids.remove(xid);
         committed = true;
     }
@@ -131,11 +141,11 @@ public class MockResource implements Nam
     }
 
     public void forget(Xid xid) throws XAException {
-        throw new UnsupportedOperationException();
+//        throw new UnsupportedOperationException();
     }
 
     public Xid[] recover(int flag) throws XAException {
-        return (Xid[]) preparedXids.toArray(new Xid[preparedXids.size()]);
+        return preparedXids.toArray(new Xid[preparedXids.size()]);
     }
 
     public boolean isPrepared() {

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResourceManager.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResourceManager.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResourceManager.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/MockResourceManager.java
Fri May  7 22:42:08 2010
@@ -22,7 +22,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import javax.transaction.SystemException;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -33,20 +32,17 @@ import javax.transaction.xa.Xid;
  * @version $Rev$ $Date$
  */
 public class MockResourceManager {
-    private boolean willCommit;
-    private Map xids = new HashMap();
+    private Map<Xid, Set<XAResource>> xids = new HashMap<Xid, Set<XAResource>>();
 
-    public MockResourceManager(boolean willCommit) {
-        this.willCommit = willCommit;
+    public MockResourceManager() {
     }
 
     public MockResource getResource(String xaResourceName) {
-        MockResource mockResource =  new MockResource(this, xaResourceName);
-        return mockResource;
+        return new MockResource(this, xaResourceName);
     }
 
     public void join(Xid xid, XAResource xaRes) throws XAException {
-        Set resSet = (Set) xids.get(xid);
+        Set<XAResource> resSet = xids.get(xid);
         if (resSet == null) {
             throw new XAException(XAException.XAER_NOTA);
         }
@@ -57,7 +53,7 @@ public class MockResourceManager {
         if (xids.containsKey(xid)) {
             throw new XAException(XAException.XAER_DUPID);
         }
-        Set resSet = new HashSet();
+        Set<XAResource> resSet = new HashSet<XAResource>();
         resSet.add(xaRes);
         xids.put(xid, resSet);
     }

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/ProtocolTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/ProtocolTest.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/ProtocolTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/ProtocolTest.java
Fri May  7 22:42:08 2010
@@ -32,8 +32,8 @@ public class ProtocolTest extends TestCa
 
     protected void setUp() throws Exception {
         tm = new TransactionManagerImpl();
-        mrm1 = new MockResourceManager(true);
-        mrm2 = new MockResourceManager(true);
+        mrm1 = new MockResourceManager();
+        mrm2 = new MockResourceManager();
         mr11 = new MockResource(mrm1, "mr11");
         mr12 = new MockResource(mrm1, "mr12");
         mr21 = new MockResource(mrm2, "mr21");

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerImplTest.java
Fri May  7 22:42:08 2010
@@ -33,10 +33,10 @@ import junit.framework.TestCase;
  */
 public class TransactionManagerImplTest extends TestCase {
 
-    MockResourceManager rm1 = new MockResourceManager(true);
+    MockResourceManager rm1 = new MockResourceManager();
     MockResource r1_1 = rm1.getResource("rm1_1");
     MockResource r1_2 = rm1.getResource("rm1_2");
-    MockResourceManager rm2 = new MockResourceManager(true);
+    MockResourceManager rm2 = new MockResourceManager();
     MockResource r2_1 = rm2.getResource("rm2_1");
     MockResource r2_2 = rm2.getResource("rm2_2");
 

Copied: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
(from r942257, geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java)
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java?p2=geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java&p1=geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java&r1=942257&r2=942259&rev=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TestTransactionManager.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
Fri May  7 22:42:08 2010
@@ -29,7 +29,7 @@ import junit.framework.TestCase;
  *
  * @version $Rev$ $Date$
  */
-public class TestTransactionManager extends TestCase {
+public class TransactionManagerTest extends TestCase {
     TransactionManager tm;
     MockResourceManager rm1, rm2, rm3;
 
@@ -113,8 +113,8 @@ public class TestTransactionManager exte
 
     protected void setUp() throws Exception {
         tm = new TransactionManagerImpl();
-        rm1 = new MockResourceManager(true);
-        rm2 = new MockResourceManager(true);
-        rm3 = new MockResourceManager(false);
+        rm1 = new MockResourceManager();
+        rm2 = new MockResourceManager();
+        rm3 = new MockResourceManager();
     }
 }

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/XidImporterTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/XidImporterTest.java?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/XidImporterTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/XidImporterTest.java
Fri May  7 22:42:08 2010
@@ -33,10 +33,10 @@ import junit.framework.TestCase;
  * */
 public class XidImporterTest extends TestCase{
 
-    MockResourceManager rm1 = new MockResourceManager(true);
+    MockResourceManager rm1 = new MockResourceManager();
     MockResource r1_1 = new MockResource(rm1, "rm1");
     MockResource r1_2 = new MockResource(rm1, "rm1");
-    MockResourceManager rm2 = new MockResourceManager(true);
+    MockResourceManager rm2 = new MockResourceManager();
     MockResource r2_1 = new MockResource(rm2, "rm2");
     MockResource r2_2 = new MockResource(rm2, "rm2");
 

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/resources/META-INF/NOTICE.txt?rev=942259&r1=942258&r2=942259&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/resources/META-INF/NOTICE.txt
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/resources/META-INF/NOTICE.txt
Fri May  7 22:42:08 2010
@@ -1,5 +1,5 @@
 Apache Geronimo 
-Copyright 2003-2009 The Apache Software Foundation
+Copyright 2003-2010 The Apache Software Foundation
 
 This product includes software developed by
 The Apache Software Foundation (http://www.apache.org/).



Mime
View raw message