Repository: ignite
Updated Branches:
  refs/heads/master 67922b326 -> 193603625


IGNITE-7409: Exception before assert in tx.resume - Fixes #3374.

Signed-off-by: Nikolay Izhikov <nizhi...@apache.org>


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

Branch: refs/heads/master
Commit: 193603625d5b7434c5a5d0c2813aafec3387c871
Parents: 67922b3
Author: voipp <alkuznetsov...@gmail.com>
Authored: Mon Feb 19 12:18:04 2018 +0300
Committer: Nikolay Izhikov <nizhi...@apache.org>
Committed: Mon Feb 19 12:24:01 2018 +0300

----------------------------------------------------------------------
 .../cache/transactions/IgniteTxManager.java     |  7 +++--
 .../IgniteOptimisticTxSuspendResumeTest.java    | 33 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/19360362/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
index e735342..dde70bc 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
@@ -2315,15 +2315,16 @@ public class IgniteTxManager extends 
GridCacheSharedManagerAdapter {
      */
     public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
         assert tx != null && !tx.system() : tx;
-        assert !threadMap.containsValue(tx) : tx;
-        assert !transactionMap(tx).containsValue(tx) : tx;
-        assert !haveSystemTxForThread(Thread.currentThread().getId());
 
         if (!tx.state(ACTIVE)) {
             throw new IgniteCheckedException("Trying to resume transaction 
with incorrect state "
                 + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
         }
 
+        assert !threadMap.containsValue(tx) : tx;
+        assert !transactionMap(tx).containsValue(tx) : tx;
+        assert !haveSystemTxForThread(Thread.currentThread().getId());
+
         long threadId = Thread.currentThread().getId();
 
         if (threadMap.putIfAbsent(threadId, tx) != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/19360362/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
index 34bd0a0..a55f21d 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteOptimisticTxSuspendResumeTest.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.CI2;
 import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -630,6 +631,38 @@ public class IgniteOptimisticTxSuspendResumeTest extends 
GridCommonAbstractTest
     }
 
     /**
+     * Test for correct exception handling when misuse transaction API - 
resume active tx.
+     *
+     * @throws Exception If failed.
+     */
+    public void testResumeActiveTx() throws Exception {
+        executeTestForAllCaches(new CI2Exc<Ignite, IgniteCache<Integer, 
Integer>>() {
+            @Override public void applyx(Ignite ignite, final 
IgniteCache<Integer, Integer> cache) throws Exception {
+                for (TransactionIsolation isolation : 
TransactionIsolation.values()) {
+                    final Transaction tx = 
ignite.transactions().txStart(OPTIMISTIC, isolation);
+
+                    cache.put(1, 1);
+
+                    try {
+                        tx.resume();
+
+                        fail("Exception must be thrown");
+                    }
+                    catch (Throwable e) {
+                        assertTrue(X.hasCause(e, IgniteException.class));
+
+                        assertFalse(X.hasCause(e, AssertionError.class));
+                    }
+
+                    tx.close();
+
+                    assertFalse(cache.containsKey(1));
+                }
+            }
+        });
+    }
+
+    /**
      * @return Cache configurations to test.
      */
     private List<CacheConfiguration<Integer, Integer>> cacheConfigurations() {

Reply via email to