ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/8] ignite git commit: ignite-4763 doSetRollbackOnly method to be implemented in the SpringTransactionManager
Date Tue, 23 May 2017 12:09:51 GMT
ignite-4763 doSetRollbackOnly method to be implemented in the SpringTransactionManager


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c4bb996d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c4bb996d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c4bb996d

Branch: refs/heads/ignite-5075-pds
Commit: c4bb996d86f80f1009d6efb85f5c659048bb0c48
Parents: 561d2cf
Author: NSAmelchev <nsamelchev@gmail.com>
Authored: Wed Apr 26 16:17:19 2017 +0300
Committer: agura <agura@apache.org>
Committed: Mon May 22 16:10:40 2017 +0300

----------------------------------------------------------------------
 .../spring/SpringTransactionManager.java        | 13 ++++++
 .../GridSpringTransactionManagerSelfTest.java   | 45 ++++++++++++++++++++
 2 files changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c4bb996d/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
b/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
index 2fe8aad..d09656e 100644
--- a/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
+++ b/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
@@ -446,6 +446,19 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
     }
 
     /** {@inheritDoc} */
+    @Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException
{
+        IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+        Transaction tx = txObj.getTransactionHolder().getTransaction();
+
+        assert tx != null;
+
+        if (status.isDebug() && log.isDebugEnabled())
+            log.debug("Setting Ignite transaction rollback-only: " + tx);
+
+        tx.setRollbackOnly();
+    }
+
+    /** {@inheritDoc} */
     @Override protected void doCleanupAfterCompletion(Object transaction) {
         IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4bb996d/modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionManagerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionManagerSelfTest.java
b/modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionManagerSelfTest.java
index 8640c0b..e68ddb4 100644
--- a/modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionManagerSelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/transactions/spring/GridSpringTransactionManagerSelfTest.java
@@ -25,10 +25,14 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.GenericXmlApplicationContext;
 import org.springframework.transaction.IllegalTransactionStateException;
 import org.springframework.transaction.InvalidIsolationLevelException;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
 
 /**
  * Spring transaction test.
@@ -144,4 +148,45 @@ public class GridSpringTransactionManagerSelfTest extends GridCommonAbstractTest
 
         assertEquals(0, c.size());
     }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testDoSetRollbackOnlyInExistingTransaction() throws Exception {
+        final IgniteCache<Integer, String> c = grid().cache(CACHE_NAME);
+
+        SpringTransactionManager mngr = new SpringTransactionManager();
+        mngr.setIgniteInstanceName(grid().name());
+        mngr.afterPropertiesSet();
+
+        TransactionTemplate txTmpl = new TransactionTemplate(mngr);
+
+        try {
+            txTmpl.execute(new TransactionCallback<Object>() {
+                @Override public Object doInTransaction(TransactionStatus status) {
+                    c.put(1, "1");
+
+                    Transaction tx = grid().transactions().tx();
+
+                    assertFalse(tx.isRollbackOnly());
+
+                    try {
+                        service.putWithError(c, 1_000);
+                    }
+                    catch (Exception ignored) {
+                        // No-op.
+                    }
+
+                    assertTrue(tx.isRollbackOnly());
+
+                    return null;
+                }
+            });
+        }
+        catch (Exception ignored) {
+            // No-op.
+        }
+
+        assertEquals(0, c.size());
+    }
 }


Mime
View raw message