ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [15/33] ignite git commit: IGNITE-4931 Fixed cluster deactivation tests - Fixes #2648.
Date Wed, 20 Sep 2017 12:48:13 GMT
IGNITE-4931 Fixed cluster deactivation tests - Fixes #2648.

Signed-off-by: Alexey Goncharuk <alexey.goncharuk@gmail.com>


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

Branch: refs/heads/ignite-3478
Commit: 879fffa65738af0a89adc1b24d08cae8408b0794
Parents: 5046206
Author: voipp <alkuznetsov.sb@gmail.com>
Authored: Tue Sep 19 11:52:50 2017 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Tue Sep 19 11:52:50 2017 +0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/ignite/Ignite.java |   1 +
 .../cluster/GridClusterStateProcessor.java      |   2 +-
 .../cache/ClusterStateAbstractTest.java         | 129 +++++--------------
 3 files changed, 35 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/879fffa6/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 7ea0aa4..866c313 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -666,6 +666,7 @@ public interface Ignite extends AutoCloseable {
      * Changes Ignite grid state to active or inactive.
      *
      * @param active If {@code True} start activation process. If {@code False} start deactivation
process.
+     * @throws IgniteException If there is an already started transaction or lock in the
same thread.
      */
     public void active(boolean active);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/879fffa6/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
index 64ee472..ff42ff6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
@@ -418,7 +418,7 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
 
         if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null)
!= null) {
             return new GridFinishedFuture<>(new IgniteCheckedException("Failed to "
+ prettyStr(activate) +
-                " cluster (must invoke the method outside of an active transaction)."));
+                " cluster (must invoke the method outside of an active transaction or lock)."));
         }
 
         DiscoveryDataClusterState curState = globalState;

http://git-wip-us.apache.org/repos/asf/ignite/blob/879fffa6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterStateAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterStateAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterStateAbstractTest.java
index ce7829a..d5f9c90 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterStateAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterStateAbstractTest.java
@@ -19,8 +19,7 @@
 package org.apache.ignite.internal.processors.cache;
 
 import java.util.Collection;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import org.apache.ignite.Ignite;
@@ -29,14 +28,11 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.managers.communication.GridIoMessage;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage;
 import org.apache.ignite.internal.util.GridConcurrentHashSet;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.plugin.extensions.communication.Message;
 import org.apache.ignite.spi.IgniteSpiException;
@@ -44,9 +40,8 @@ import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
-
-import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
 
 /**
  *
@@ -275,125 +270,67 @@ public abstract class ClusterStateAbstractTest extends GridCommonAbstractTest
{
     }
 
     /**
-     * Tests that state doesn't change until all acquired locks are released.
+     * Tests that deactivation is prohibited if explicit lock is held in current thread.
      *
      * @throws Exception If fails.
      */
     public void testDeactivationWithPendingLock() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-4931");
-
         startGrids(GRID_CNT);
 
-        final CountDownLatch finishedLatch = new CountDownLatch(1);
-
         Lock lock = grid(0).cache(CACHE_NAME).lock(1);
 
-        IgniteInternalFuture<?> fut;
-
         lock.lock();
 
-        try {
-            fut = multithreadedAsync(new Runnable() {
-                @Override public void run() {
-                    grid(1).active(false);
-
-                    finishedLatch.countDown();
-                }
-            }, 1);
-
-            U.sleep(2000);
-
-            assert !fut.isDone();
-
-            boolean hasActive = false;
-
-            for (int g = 0; g < GRID_CNT; g++) {
-                IgniteEx grid = grid(g);
-
-                if (grid.active()) {
-                    hasActive = true;
-
-                    break;
-                }
+        GridTestUtils.assertThrowsAnyCause(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                grid(0).active(false);
 
+                return null;
             }
+        }, IgniteException.class,
+            "Failed to deactivate cluster (must invoke the method outside of an active transaction
or lock).");
 
-            assertTrue(hasActive);
-        }
-        finally {
-            lock.unlock();
-        }
-
-        fut.get(getTestTimeout(), TimeUnit.MILLISECONDS);
-
-        checkInactive(GRID_CNT);
-
-        finishedLatch.await();
+        lock.unlock();
     }
 
     /**
-     * Tests that state doesn't change until all pending transactions are finished.
+     * Tests that deactivation is prohibited if transaction is active in current thread.
      *
-     * @throws Exception If fails.
+     * @throws Exception If failed.
      */
     public void testDeactivationWithPendingTransaction() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-4931");
-
         startGrids(GRID_CNT);
 
-        final CountDownLatch finishedLatch = new CountDownLatch(1);
+        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
+            for (TransactionIsolation isolation : TransactionIsolation.values())
+                deactivateWithPendingTransaction(concurrency, isolation);
+        }
+    }
 
+    /**
+     * @throws Exception if failed.
+     */
+    private void deactivateWithPendingTransaction(TransactionConcurrency concurrency,
+        TransactionIsolation isolation) throws Exception {
         final Ignite ignite0 = grid(0);
 
         final IgniteCache<Object, Object> cache0 = ignite0.cache(CACHE_NAME);
 
-        IgniteInternalFuture<?> fut;
-
-        try (Transaction tx = ignite0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ))
{
-            cache0.get(1);
-
-            fut = multithreadedAsync(new Runnable() {
-                @Override public void run() {
-                    ignite0.active(false);
-
-                    finishedLatch.countDown();
-                }
-            }, 1);
-
-            U.sleep(2000);
-
-            assert !fut.isDone();
-
-            boolean hasActive = false;
+        try (Transaction tx = ignite0.transactions().txStart(concurrency, isolation)) {
+            cache0.put(1, "1");
 
-            for (int g = 0; g < GRID_CNT; g++) {
-                IgniteEx grid = grid(g);
+            GridTestUtils.assertThrowsAnyCause(log, new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    grid(0).active(false);
 
-                if (grid.active()) {
-                    hasActive = true;
-
-                    break;
+                    return null;
                 }
-
-            }
-
-            assertTrue(hasActive);
-
-            cache0.put(1, 2);
-
-            tx.commit();
+            }, IgniteException.class,
+                "Failed to deactivate cluster (must invoke the method outside of an active
transaction or lock).");
         }
 
-        fut.get(getTestTimeout(), TimeUnit.MILLISECONDS);
-
-        checkInactive(GRID_CNT);
-
-        ignite0.active(true);
-
-        for (int g = 0; g < GRID_CNT; g++)
-            assertEquals(2, grid(g).cache(CACHE_NAME).get(1));
-
-        finishedLatch.await();
+        assertNull(cache0.get(1));
+        assertNull(ignite0.transactions().tx());
     }
 
     /**


Mime
View raw message