aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1694829 - in /aries/trunk/transaction/transaction-blueprint: pom.xml src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java src/test/java/org/apache/aries/transaction/InterceptorTest.java
Date Sat, 08 Aug 2015 18:13:27 GMT
Author: cschneider
Date: Sat Aug  8 18:13:26 2015
New Revision: 1694829

URL: http://svn.apache.org/r1694829
Log:
[ARIES-1369] Make sure rollback works even if coordination failed

Modified:
    aries/trunk/transaction/transaction-blueprint/pom.xml
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java

Modified: aries/trunk/transaction/transaction-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/pom.xml?rev=1694829&r1=1694828&r2=1694829&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/pom.xml (original)
+++ aries/trunk/transaction/transaction-blueprint/pom.xml Sat Aug  8 18:13:26 2015
@@ -50,7 +50,7 @@
             org.apache.aries.transaction,
             org.apache.aries.transaction.parsing
         </aries.osgi.private.pkg>
-        <lastReleaseVersion>1.0.1</lastReleaseVersion>
+        <lastReleaseVersion>1.1.0</lastReleaseVersion>
     </properties>
 
     <dependencies>

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java?rev=1694829&r1=1694828&r2=1694829&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
Sat Aug  8 18:13:26 2015
@@ -28,6 +28,7 @@ import org.apache.aries.transaction.anno
 import org.apache.aries.transaction.exception.TransactionRollbackException;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.coordinator.Coordination;
+import org.osgi.service.coordinator.CoordinationException;
 import org.osgi.service.coordinator.Coordinator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,7 +68,11 @@ public class TxInterceptorImpl implement
             return;
         }
         final TransactionToken token = (TransactionToken)preCallToken;
-        token.getCoordination().end();
+        try {
+            token.getCoordination().end();
+        } catch (CoordinationException e){
+            LOGGER.debug(e.getMessage(), e);
+        }
         try {
             Transaction tran = token.getActiveTransaction();
             if (tran != null && isRollBackException(ex)) {

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java?rev=1694829&r1=1694828&r2=1694829&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
Sat Aug  8 18:13:26 2015
@@ -18,6 +18,9 @@
  */
 package org.apache.aries.transaction;
 
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
 import java.io.IOException;
 
 import javax.transaction.Transaction;
@@ -27,18 +30,36 @@ import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
 import org.junit.Test;
 import org.osgi.service.coordinator.Coordination;
+import org.osgi.service.coordinator.CoordinationException;
 
 public class InterceptorTest {
 
     @Test
     public void testRollbackOnException() throws Throwable {
-        postCallWithTransaction(new IllegalStateException(), true);
-        postCallWithTransaction(new Error(), true);
-        postCallWithTransaction(new Exception(), false);
-        postCallWithTransaction(new IOException(), false);
+        runPostCall(false);
+        runPostCall(true);
+    }
+
+    private void runPostCall(boolean failCoordination) throws Throwable {
+        postCallWithTransaction(new IllegalStateException(), true, failCoordination);
+        postCallWithTransaction(new Error(), true, failCoordination);
+        postCallWithTransaction(new Exception(), false, failCoordination);
+        postCallWithTransaction(new IOException(), false, failCoordination);
     }
     
-    private void postCallWithTransaction(Throwable th, boolean expectRollback) throws Throwable
{
+    private CoordinationException coordinationException(Throwable th) {
+        Coordination coordination = EasyMock.createMock(Coordination.class);
+        expect(coordination.getId()).andReturn(1l);
+        expect(coordination.getName()).andReturn("Test");
+        replay(coordination);
+        CoordinationException cex = new CoordinationException("Simulating exception", 
+                                                              coordination , 
+                                                              CoordinationException.FAILED,
+                                                              th);
+        return cex;
+    }
+    
+    private void postCallWithTransaction(Throwable th, boolean expectRollback, boolean failCoordination)
throws Throwable {
         IMocksControl c = EasyMock.createControl();
         TxInterceptorImpl sut = new TxInterceptorImpl();
         sut.setTransactionManager(c.createMock(TransactionManager.class));
@@ -50,7 +71,11 @@ public class InterceptorTest {
         }
         Coordination coordination = c.createMock(Coordination.class);
         coordination.end();
-        EasyMock.expectLastCall();
+        if (failCoordination) {
+            EasyMock.expectLastCall().andThrow(coordinationException(th));
+        } else {
+            EasyMock.expectLastCall();
+        }
         
         c.replay();
         TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);



Mime
View raw message