ignite-5226 Cleanup client topology on cache group stop

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

Branch: refs/heads/ignite-2.1.2-exchange
Commit: 44c723c35847cf6eb13dddd1111fa2ead3e8bae7
Parents: 636ddb0
Author: Ivan Rakov <[email protected]>
Authored: Sat Jun 17 09:02:55 2017 +0300
Committer: sboikov <[email protected]>
Committed: Sat Jun 17 09:02:55 2017 +0300

----------------------------------------------------------------------
 .../cache/CacheAffinitySharedManager.java       |   3 +
 ...AffinityCoordinatorDynamicStartStopTest.java | 139 +++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite2.java       |   3 +
 3 files changed, 145 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/44c723c3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
index eada554..231c58e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
@@ -758,6 +758,9 @@ public class CacheAffinitySharedManager<K, V> extends 
GridCacheSharedManagerAdap
         for (ExchangeActions.ActionData action : 
exchActions.cacheStopRequests())
             cctx.cache().blockGateway(action.request().cacheName(), true, 
action.request().restart());
 
+        for (CacheGroupDescriptor grpDesc : exchActions.cacheGroupsToStop())
+            cctx.exchange().clearClientTopology(grpDesc.groupId());
+
         Set<Integer> stoppedGrps = null;
 
         if (crd && lateAffAssign) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/44c723c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/NonAffinityCoordinatorDynamicStartStopTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/NonAffinityCoordinatorDynamicStartStopTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/NonAffinityCoordinatorDynamicStartStopTest.java
new file mode 100644
index 0000000..a4733d5
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/NonAffinityCoordinatorDynamicStartStopTest.java
@@ -0,0 +1,139 @@
+/*
+* 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.ignite.internal.processors.cache;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgnitePredicate;
+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;
+
+/**
+ *
+ */
+public class NonAffinityCoordinatorDynamicStartStopTest extends 
GridCommonAbstractTest {
+    /** Ip finder. */
+    private static final TcpDiscoveryIpFinder ipFinder = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final String TEST_ATTRIBUTE = "test-attribute";
+
+    /** Dummy grid name. */
+    private static final String DUMMY_GRID_NAME = "dummy";
+
+    /** Cache configuration. */
+    private static final CacheConfiguration<Integer, Integer> CCFG = new 
CacheConfiguration<Integer, Integer>("cache")
+        .setAffinity(new RendezvousAffinityFunction(false, 32))
+        .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
+        .setNodeFilter(new TestNodeFilter())
+        .setGroupName("Group");
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi discoverySpi = (TcpDiscoverySpi)cfg.getDiscoverySpi();
+        discoverySpi.setIpFinder(ipFinder);
+
+        MemoryConfiguration dbCfg = new MemoryConfiguration();
+
+        MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+        memPlcCfg.setMaxSize(200 * 1000 * 1000);
+
+        memPlcCfg.setName("dfltMemPlc");
+
+        dbCfg.setMemoryPolicies(memPlcCfg);
+        dbCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+        if (gridName.contains(DUMMY_GRID_NAME))
+            cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE, false));
+        else
+            cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE, true));
+
+        cfg.setConsistentId(gridName);
+
+        if (gridName.contains("client"))
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        stopAllGrids();
+
+        final Ignite crd = startGrid(DUMMY_GRID_NAME);
+
+        crd.active(true);
+
+        startGrid("client");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStartStop() throws Exception {
+        startGrids(2);
+
+        awaitPartitionMapExchange();
+
+        Ignite ig = ignite(0);
+
+        IgniteCache<Integer, Integer> cache = ig.getOrCreateCache(CCFG);
+
+        for (int i = 0; i < 1000; i++)
+            cache.put(i, i);
+
+        cache.destroy();
+
+        grid("dummy").createCache(CCFG);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean checkTopology() {
+        // We start a dummy node in the beginning of the each test,
+        // so default startGrids(n) will fail on wait for .
+        return false;
+    }
+
+    /**
+     *
+     */
+    private static class TestNodeFilter implements 
IgnitePredicate<ClusterNode> {
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode clusterNode) {
+            return Boolean.TRUE.equals(clusterNode.attribute(TEST_ATTRIBUTE));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/44c723c3/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
index b9a81c8..83b8df5 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -48,6 +48,7 @@ import 
org.apache.ignite.internal.processors.cache.IgniteNearClientCacheCloseTes
 import 
org.apache.ignite.internal.processors.cache.IgniteOnePhaseCommitInvokeTest;
 import 
org.apache.ignite.internal.processors.cache.IgniteOnePhaseCommitNearReadersTest;
 import 
org.apache.ignite.internal.processors.cache.MemoryPolicyConfigValidationTest;
+import 
org.apache.ignite.internal.processors.cache.NonAffinityCoordinatorDynamicStartStopTest;
 import 
org.apache.ignite.internal.processors.cache.persistence.MemoryPolicyInitializationTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.CacheLoadingConcurrentGridStartSelfTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.CacheLoadingConcurrentGridStartSelfTestAllowOverwrite;
@@ -277,6 +278,8 @@ public class IgniteCacheTestSuite2 extends TestSuite {
         suite.addTest(new TestSuite(IgniteNearClientCacheCloseTest.class));
         suite.addTest(new TestSuite(IgniteClientCacheStartFailoverTest.class));
 
+        suite.addTest(new 
TestSuite(NonAffinityCoordinatorDynamicStartStopTest.class));
+
         return suite;
     }
 }

Reply via email to