# IGNITE-56 Rename "clear" tests.

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

Branch: refs/heads/ignite-96-tests
Commit: 95d2c9566ddba340bbfa47676add124e31ca57b7
Parents: 137b729
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Tue Feb 10 14:49:59 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Tue Feb 10 14:49:59 2015 +0300

----------------------------------------------------------------------
 .../cache/GridCacheClearAllSelfTest.java        | 301 ++++-------------
 .../cache/GridCacheClearLocalySelfTest.java     | 336 +++++++++++++++++++
 .../cache/GridCacheGlobalClearAllSelfTest.java  | 168 ----------
 .../junits/common/GridCommonAbstractTest.java   |   4 +-
 .../ignite/testsuites/IgniteCacheTestSuite.java |   1 -
 5 files changed, 405 insertions(+), 405 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/95d2c956/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
index 139d6da0..0bd90cb 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
@@ -24,88 +24,55 @@ import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.junits.common.*;
-import org.apache.ignite.transactions.*;
-
-import java.lang.reflect.*;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
 import static org.apache.ignite.cache.CacheDistributionMode.*;
 import static org.apache.ignite.cache.CacheMode.*;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
-import static org.apache.ignite.internal.processors.cache.GridCacheAdapter.*;
 
 /**
- * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} operations in 
multinode environment with nodes having caches with different names.
+ * Test {@link IgniteCache#clear()} operation in multinode environment with 
nodes
+ * having caches with different names.
  */
 public class GridCacheClearAllSelfTest extends GridCommonAbstractTest {
-    /** Local cache. */
-    private static final String CACHE_LOCAL = "cache_local";
+    /** Grid nodes count. */
+    private static final int GRID_CNT = 3;
 
-    /** Partitioned cache. */
-    private static final String CACHE_PARTITIONED = "cache_partitioned";
+    /** Amount of keys stored in the default cache. */
+    private static final int KEY_CNT = 20;
 
-    /** Co-located cache. */
-    private static final String CACHE_COLOCATED = "cache_colocated";
+    /** Amount of keys stored in cache other than default. */
+    private static final int KEY_CNT_OTHER = 10;
 
-    /** Replicated cache. */
-    private static final String CACHE_REPLICATED = "cache_replicated";
+    /** Default cache name. */
+    private static final String CACHE_NAME = "cache_name";
 
-    /** Grid nodes count. */
-    private static final int GRID_CNT = 3;
+    /** Cache name which differs from the default one. */
+    private static final String CACHE_NAME_OTHER = "cache_name_other";
 
     /** VM IP finder for TCP discovery SPI. */
     private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
 
-    /** Local caches. */
-    private GridCache<Integer, Integer>[] cachesLoc;
-
-    /** Partitioned caches. */
-    private GridCache<Integer, Integer>[] cachesPartitioned;
+    /** Cache name which will be passed to grid configuration. */
+    private CacheMode cacheMode = PARTITIONED;
 
-    /** Colocated caches. */
-    private GridCache<Integer, Integer>[] cachesColocated;
-
-    /** Replicated caches. */
-    private GridCache<Integer, Integer>[] cachesReplicated;
+    /** Cache mode which will be passed to grid configuration. */
+    private String cacheName = CACHE_NAME;
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        CacheConfiguration ccfgLoc = new CacheConfiguration();
-
-        ccfgLoc.setName(CACHE_LOCAL);
-        ccfgLoc.setCacheMode(LOCAL);
-        ccfgLoc.setWriteSynchronizationMode(FULL_SYNC);
-        ccfgLoc.setAtomicityMode(TRANSACTIONAL);
-
-        CacheConfiguration ccfgPartitioned = new CacheConfiguration();
-
-        ccfgPartitioned.setName(CACHE_PARTITIONED);
-        ccfgPartitioned.setCacheMode(PARTITIONED);
-        ccfgPartitioned.setBackups(1);
-        ccfgPartitioned.setWriteSynchronizationMode(FULL_SYNC);
-        
ccfgPartitioned.setDistributionMode(gridName.equals(getTestGridName(0)) ? 
NEAR_PARTITIONED :
-            gridName.equals(getTestGridName(1)) ? NEAR_ONLY : CLIENT_ONLY);
-        ccfgPartitioned.setAtomicityMode(TRANSACTIONAL);
-
-        CacheConfiguration ccfgColocated = new CacheConfiguration();
+        CacheConfiguration ccfg = defaultCacheConfiguration();
 
-        ccfgColocated.setName(CACHE_COLOCATED);
-        ccfgColocated.setCacheMode(PARTITIONED);
-        ccfgColocated.setBackups(1);
-        ccfgColocated.setWriteSynchronizationMode(FULL_SYNC);
-        ccfgColocated.setDistributionMode(PARTITIONED_ONLY);
-        ccfgColocated.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setName(cacheName);
+        ccfg.setCacheMode(cacheMode);
+        ccfg.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setDistributionMode(NEAR_PARTITIONED);
 
-        CacheConfiguration ccfgReplicated = new CacheConfiguration();
+        if (cacheMode == PARTITIONED)
+            ccfg.setBackups(1);
 
-        ccfgReplicated.setName(CACHE_REPLICATED);
-        ccfgReplicated.setCacheMode(REPLICATED);
-        ccfgReplicated.setWriteSynchronizationMode(FULL_SYNC);
-        ccfgReplicated.setAtomicityMode(TRANSACTIONAL);
-
-        cfg.setCacheConfiguration(ccfgLoc, ccfgPartitioned, ccfgColocated, 
ccfgReplicated);
+        cfg.setCacheConfiguration(ccfg);
 
         TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
 
@@ -119,217 +86,83 @@ public class GridCacheClearAllSelfTest extends 
GridCommonAbstractTest {
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
         stopAllGrids();
-
-        cachesLoc = null;
-        cachesPartitioned = null;
-        cachesColocated = null;
-        cachesReplicated = null;
-    }
-
-    /**
-     * Startup routine.
-     *
-     * @throws Exception If failed.
-     */
-    private void startUp() throws Exception {
-        cachesLoc = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
-        cachesPartitioned = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
-        cachesColocated = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
-        cachesReplicated = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
-
-        for (int i = 0; i < GRID_CNT; i++) {
-            Ignite ignite = startGrid(i);
-
-            cachesLoc[i] = ignite.cache(CACHE_LOCAL);
-            cachesPartitioned[i] = ignite.cache(CACHE_PARTITIONED);
-            cachesColocated[i] = ignite.cache(CACHE_COLOCATED);
-            cachesReplicated[i] = ignite.cache(CACHE_REPLICATED);
-        }
     }
 
     /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on LOCAL 
cache with no split.
+     * Start GRID_CNT nodes. All nodes except the last one will have one cache 
with particular name, while the last
+     * one will have one cache of the same type, but with different name.
      *
-     * @throws Exception If failed.
+     * @throws Exception In case of exception.
      */
-    public void testLocalNoSplit() throws Exception {
-        test(Mode.TEST_LOCAL, CLEAR_ALL_SPLIT_THRESHOLD / 2);
-    }
+    private void startNodes() throws Exception {
+        cacheName = CACHE_NAME;
 
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on LOCAL 
cache with split.
-     *
-     * @throws Exception If failed.
-     */
-    public void testLocalSplit() throws Exception {
-        test(Mode.TEST_LOCAL, CLEAR_ALL_SPLIT_THRESHOLD + 1);
-    }
+        for (int i = 0; i < GRID_CNT - 1; i++)
+            startGrid(i);
 
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
PARTITIONED cache with no split.
-     *
-     * @throws Exception If failed.
-     */
-    public void testPartitionedNoSplit() throws Exception {
-        test(Mode.TEST_PARTITIONED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
-    }
+        cacheName = CACHE_NAME_OTHER;
 
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
PARTITIONED cache with split.
-     *
-     * @throws Exception If failed.
-     */
-    public void testPartitionedSplit() throws Exception {
-        test(Mode.TEST_PARTITIONED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+        startGrid(GRID_CNT - 1);
     }
 
     /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
co-located cache with no split.
+     * Test for partitioned cache.
      *
-     * @throws Exception If failed.
-     */
-    public void testColocatedNoSplit() throws Exception {
-        test(Mode.TEST_COLOCATED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
-    }
-
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
co-located cache with split.
-     *
-     * @throws Exception If failed.
+     * @throws Exception In case of exception.
      */
-    public void testColocatedSplit() throws Exception {
-        test(Mode.TEST_COLOCATED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
-    }
+    public void testGlobalClearAllPartitioned() throws Exception {
+        cacheMode = PARTITIONED;
 
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
REPLICATED cache with no split.
-     *
-     * @throws Exception If failed.
-     */
-    public void testReplicatedNoSplit() throws Exception {
-        test(Mode.TEST_REPLICATED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
-    }
+        startNodes();
 
-    /**
-     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
REPLICATED cache with split.
-     *
-     * @throws Exception If failed.
-     */
-    public void testReplicatedSplit() throws Exception {
-        test(Mode.TEST_REPLICATED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+        performTest();
     }
 
     /**
-     * Internal method for all tests.
+     * Test for replicated cache.
      *
-     * @param mode Test mode
-     * @param keysCnt Keys count.
      * @throws Exception In case of exception.
      */
-    private void test(Mode mode, int keysCnt) throws Exception {
-        startUp();
-
-        switch (mode) {
-            case TEST_LOCAL: {
-                // Check on only one node.
-                GridCache<Integer, Integer> cache = cachesLoc[0];
-
-                fillCache(cache, keysCnt);
-
-                cache.clear();
-
-                assert cache.isEmpty();
-
-                break;
-            }
-            case TEST_PARTITIONED: {
-                // Take in count special case for near-only cache as well.
-                fillCache(cachesPartitioned[0], keysCnt);
-
-                // Ensure correct no-op clean of CLIENT_ONLY cache.
-                warmCache(cachesPartitioned[2], keysCnt);
-                assert cachesPartitioned[2].isEmpty();
-                cachesPartitioned[2].clearLocally();
-                assert cachesPartitioned[2].isEmpty();
+    public void testGlobalClearAllReplicated() throws Exception {
+        cacheMode = REPLICATED;
 
-                stopGrid(2); // Shutdown Grid in order to remove reader in 
NEAR_PARTITIONED cache.
+        startNodes();
 
-                // Ensure correct clearLocally of NEA_ONLY cache.
-                warmCache(cachesPartitioned[1], keysCnt);
-                assert !cachesPartitioned[1].isEmpty();
-                cachesPartitioned[1].clearLocally();
-                assert cachesPartitioned[1].isEmpty();
-                fillCache(cachesPartitioned[1], keysCnt);
-
-                stopGrid(1); // Shutdown Grid in order to remove reader in 
NEAR_PARTITIONED cache.
-
-                // Ensure correct clearLocally of NEAR_PARTITIONED cache.
-                assert !cachesPartitioned[0].isEmpty();
-                cachesPartitioned[0].clearLocally();
-                assert cachesPartitioned[0].isEmpty();
-
-                break;
-            }
-            default: {
-                assert mode == Mode.TEST_COLOCATED || mode == 
Mode.TEST_REPLICATED;
-
-                GridCache<Integer, Integer>[] caches = mode == 
Mode.TEST_COLOCATED ? cachesColocated : cachesReplicated;
-
-                fillCache(caches[0], keysCnt);
-
-                for (GridCache<Integer, Integer> cache : caches) {
-                    assert !cache.isEmpty();
-
-                    cache.clearLocally();
-
-                    assert cache.isEmpty();
-                }
-            }
-        }
+        performTest();
     }
 
     /**
-     * Fill cache with values.
+     * Ensure that clear() clears correct cache and is only executed on nodes 
with the cache excluding
+     * master-node where it is executed locally.
      *
-     * @param cache Cache.
-     * @param keysCnt Amount of keys to put.
      * @throws Exception If failed.
      */
-    private void fillCache(GridCache<Integer, Integer> cache, int keysCnt) 
throws Exception {
-        try (IgniteTx tx = cache.txStart()) {
-            for (int i = 0; i < keysCnt; i++)
-                cache.put(i, i);
+    public void performTest() throws Exception {
+        // Put values into normal replicated cache.
+        for (int i = 0; i < KEY_CNT; i++)
+            grid(0).jcache(CACHE_NAME).put(i, "val" + i);
 
-            tx.commit();
-        }
-    }
+        // Put values into a cache with another name.
+        for (int i = 0; i < KEY_CNT_OTHER; i++)
+            grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).put(i, "val" + i);
 
-    /**
-     * Warm cache up.
-     *
-     * @param cache Cache.
-     * @param keysCnt Amount of keys to get.
-     * @throws Exception If failed.
-     */
-    private void warmCache(GridCache<Integer, Integer> cache, int keysCnt) 
throws Exception {
-        for (int i = 0; i < keysCnt; i++)
-            cache.get(i);
-    }
+        // Check cache sizes.
+        for (int i = 0; i < GRID_CNT - 1; i++) {
+            IgniteCache<Object, Object> cache = grid(i).jcache(CACHE_NAME);
 
-    /**
-     * Test mode.
-     */
-    private enum Mode {
-        /** Local cache. */
-        TEST_LOCAL,
+            assertEquals("Key set [i=" + i + ']', KEY_CNT, cache.localSize());
+        }
+
+        assert grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).localSize() == 
KEY_CNT_OTHER;
 
-        /** Partitioned cache. */
-        TEST_PARTITIONED,
+        // Perform clear.
+        grid(0).jcache(CACHE_NAME).clear();
 
-        /** Co-located cache. */
-        TEST_COLOCATED,
+        // Expect caches with the given name to be clear on all nodes.
+        for (int i = 0; i < GRID_CNT - 1; i++)
+            assert grid(i).jcache(CACHE_NAME).isEmpty();
 
-        /** Replicated cache. */
-        TEST_REPLICATED
+        // ... but cache with another name should remain untouched.
+        assert grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).localSize() == 
KEY_CNT_OTHER;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/95d2c956/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocalySelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocalySelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocalySelfTest.java
new file mode 100644
index 0000000..a33304f
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocalySelfTest.java
@@ -0,0 +1,336 @@
+/*
+ * 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.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.transactions.*;
+
+import java.lang.reflect.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheDistributionMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+import static org.apache.ignite.internal.processors.cache.GridCacheAdapter.*;
+
+/**
+ * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} operations in 
multinode environment with nodes having caches with different names.
+ */
+public class GridCacheClearLocalySelfTest extends GridCommonAbstractTest {
+    /** Local cache. */
+    private static final String CACHE_LOCAL = "cache_local";
+
+    /** Partitioned cache. */
+    private static final String CACHE_PARTITIONED = "cache_partitioned";
+
+    /** Co-located cache. */
+    private static final String CACHE_COLOCATED = "cache_colocated";
+
+    /** Replicated cache. */
+    private static final String CACHE_REPLICATED = "cache_replicated";
+
+    /** Grid nodes count. */
+    private static final int GRID_CNT = 3;
+
+    /** VM IP finder for TCP discovery SPI. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** Local caches. */
+    private GridCache<Integer, Integer>[] cachesLoc;
+
+    /** Partitioned caches. */
+    private GridCache<Integer, Integer>[] cachesPartitioned;
+
+    /** Colocated caches. */
+    private GridCache<Integer, Integer>[] cachesColocated;
+
+    /** Replicated caches. */
+    private GridCache<Integer, Integer>[] cachesReplicated;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfgLoc = new CacheConfiguration();
+
+        ccfgLoc.setName(CACHE_LOCAL);
+        ccfgLoc.setCacheMode(LOCAL);
+        ccfgLoc.setWriteSynchronizationMode(FULL_SYNC);
+        ccfgLoc.setAtomicityMode(TRANSACTIONAL);
+
+        CacheConfiguration ccfgPartitioned = new CacheConfiguration();
+
+        ccfgPartitioned.setName(CACHE_PARTITIONED);
+        ccfgPartitioned.setCacheMode(PARTITIONED);
+        ccfgPartitioned.setBackups(1);
+        ccfgPartitioned.setWriteSynchronizationMode(FULL_SYNC);
+        
ccfgPartitioned.setDistributionMode(gridName.equals(getTestGridName(0)) ? 
NEAR_PARTITIONED :
+            gridName.equals(getTestGridName(1)) ? NEAR_ONLY : CLIENT_ONLY);
+        ccfgPartitioned.setAtomicityMode(TRANSACTIONAL);
+
+        CacheConfiguration ccfgColocated = new CacheConfiguration();
+
+        ccfgColocated.setName(CACHE_COLOCATED);
+        ccfgColocated.setCacheMode(PARTITIONED);
+        ccfgColocated.setBackups(1);
+        ccfgColocated.setWriteSynchronizationMode(FULL_SYNC);
+        ccfgColocated.setDistributionMode(PARTITIONED_ONLY);
+        ccfgColocated.setAtomicityMode(TRANSACTIONAL);
+
+        CacheConfiguration ccfgReplicated = new CacheConfiguration();
+
+        ccfgReplicated.setName(CACHE_REPLICATED);
+        ccfgReplicated.setCacheMode(REPLICATED);
+        ccfgReplicated.setWriteSynchronizationMode(FULL_SYNC);
+        ccfgReplicated.setAtomicityMode(TRANSACTIONAL);
+
+        cfg.setCacheConfiguration(ccfgLoc, ccfgPartitioned, ccfgColocated, 
ccfgReplicated);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        cachesLoc = null;
+        cachesPartitioned = null;
+        cachesColocated = null;
+        cachesReplicated = null;
+    }
+
+    /**
+     * Startup routine.
+     *
+     * @throws Exception If failed.
+     */
+    private void startUp() throws Exception {
+        cachesLoc = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
+        cachesPartitioned = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
+        cachesColocated = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
+        cachesReplicated = (GridCache<Integer, 
Integer>[])Array.newInstance(GridCache.class, GRID_CNT);
+
+        for (int i = 0; i < GRID_CNT; i++) {
+            Ignite ignite = startGrid(i);
+
+            cachesLoc[i] = ((IgniteKernal)ignite).cache(CACHE_LOCAL);
+            cachesPartitioned[i] = 
((IgniteKernal)ignite).cache(CACHE_PARTITIONED);
+            cachesColocated[i] = ((IgniteKernal)ignite).cache(CACHE_COLOCATED);
+            cachesReplicated[i] = 
((IgniteKernal)ignite).cache(CACHE_REPLICATED);
+        }
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on LOCAL 
cache with no split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testLocalNoSplit() throws Exception {
+        test(Mode.TEST_LOCAL, CLEAR_ALL_SPLIT_THRESHOLD / 2);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on LOCAL 
cache with split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testLocalSplit() throws Exception {
+        test(Mode.TEST_LOCAL, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
PARTITIONED cache with no split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testPartitionedNoSplit() throws Exception {
+        test(Mode.TEST_PARTITIONED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
PARTITIONED cache with split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testPartitionedSplit() throws Exception {
+        test(Mode.TEST_PARTITIONED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
co-located cache with no split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testColocatedNoSplit() throws Exception {
+        test(Mode.TEST_COLOCATED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
co-located cache with split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testColocatedSplit() throws Exception {
+        test(Mode.TEST_COLOCATED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
REPLICATED cache with no split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testReplicatedNoSplit() throws Exception {
+        test(Mode.TEST_REPLICATED, CLEAR_ALL_SPLIT_THRESHOLD / 2);
+    }
+
+    /**
+     * Test {@link org.apache.ignite.cache.GridCache#clearLocally()} on 
REPLICATED cache with split.
+     *
+     * @throws Exception If failed.
+     */
+    public void testReplicatedSplit() throws Exception {
+        test(Mode.TEST_REPLICATED, CLEAR_ALL_SPLIT_THRESHOLD + 1);
+    }
+
+    /**
+     * Internal method for all tests.
+     *
+     * @param mode Test mode
+     * @param keysCnt Keys count.
+     * @throws Exception In case of exception.
+     */
+    private void test(Mode mode, int keysCnt) throws Exception {
+        startUp();
+
+        switch (mode) {
+            case TEST_LOCAL: {
+                // Check on only one node.
+                GridCache<Integer, Integer> cache = cachesLoc[0];
+
+                fillCache(cache, keysCnt);
+
+                cache.clearLocally();
+
+                assert cache.isEmpty();
+
+                break;
+            }
+            case TEST_PARTITIONED: {
+                // Take in count special case for near-only cache as well.
+                fillCache(cachesPartitioned[0], keysCnt);
+
+                // Ensure correct no-op clean of CLIENT_ONLY cache.
+                warmCache(cachesPartitioned[2], keysCnt);
+                assert cachesPartitioned[2].isEmpty();
+                cachesPartitioned[2].clearLocally();
+                assert cachesPartitioned[2].isEmpty();
+
+                stopGrid(2); // Shutdown Grid in order to remove reader in 
NEAR_PARTITIONED cache.
+
+                // Ensure correct clearLocally of NEA_ONLY cache.
+                warmCache(cachesPartitioned[1], keysCnt);
+                assert !cachesPartitioned[1].isEmpty();
+                cachesPartitioned[1].clearLocally();
+                assert cachesPartitioned[1].isEmpty();
+                fillCache(cachesPartitioned[1], keysCnt);
+
+                stopGrid(1); // Shutdown Grid in order to remove reader in 
NEAR_PARTITIONED cache.
+
+                // Ensure correct clearLocally of NEAR_PARTITIONED cache.
+                assert !cachesPartitioned[0].isEmpty();
+                cachesPartitioned[0].clearLocally();
+                assert cachesPartitioned[0].isEmpty();
+
+                break;
+            }
+            default: {
+                assert mode == Mode.TEST_COLOCATED || mode == 
Mode.TEST_REPLICATED;
+
+                GridCache<Integer, Integer>[] caches = mode == 
Mode.TEST_COLOCATED ? cachesColocated : cachesReplicated;
+
+                fillCache(caches[0], keysCnt);
+
+                for (GridCache<Integer, Integer> cache : caches) {
+                    assert !cache.isEmpty();
+
+                    cache.clearLocally();
+
+                    assert cache.isEmpty();
+                }
+            }
+        }
+    }
+
+    /**
+     * Fill cache with values.
+     *
+     * @param cache Cache.
+     * @param keysCnt Amount of keys to put.
+     * @throws Exception If failed.
+     */
+    private void fillCache(GridCache<Integer, Integer> cache, int keysCnt) 
throws Exception {
+        try (IgniteTx tx = cache.txStart()) {
+            for (int i = 0; i < keysCnt; i++)
+                cache.put(i, i);
+
+            tx.commit();
+        }
+    }
+
+    /**
+     * Warm cache up.
+     *
+     * @param cache Cache.
+     * @param keysCnt Amount of keys to get.
+     * @throws Exception If failed.
+     */
+    private void warmCache(GridCache<Integer, Integer> cache, int keysCnt) 
throws Exception {
+        for (int i = 0; i < keysCnt; i++)
+            cache.get(i);
+    }
+
+    /**
+     * Test mode.
+     */
+    private enum Mode {
+        /** Local cache. */
+        TEST_LOCAL,
+
+        /** Partitioned cache. */
+        TEST_PARTITIONED,
+
+        /** Co-located cache. */
+        TEST_COLOCATED,
+
+        /** Replicated cache. */
+        TEST_REPLICATED
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/95d2c956/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheGlobalClearAllSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheGlobalClearAllSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheGlobalClearAllSelfTest.java
deleted file mode 100644
index 565400f..0000000
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheGlobalClearAllSelfTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.*;
-import static org.apache.ignite.cache.CacheDistributionMode.*;
-import static org.apache.ignite.cache.CacheMode.*;
-
-/**
- * Test {@link IgniteCache#clear()} operation in multinode environment with 
nodes
- * having caches with different names.
- */
-public class GridCacheGlobalClearAllSelfTest extends GridCommonAbstractTest {
-    /** Grid nodes count. */
-    private static final int GRID_CNT = 3;
-
-    /** Amount of keys stored in the default cache. */
-    private static final int KEY_CNT = 20;
-
-    /** Amount of keys stored in cache other than default. */
-    private static final int KEY_CNT_OTHER = 10;
-
-    /** Default cache name. */
-    private static final String CACHE_NAME = "cache_name";
-
-    /** Cache name which differs from the default one. */
-    private static final String CACHE_NAME_OTHER = "cache_name_other";
-
-    /** VM IP finder for TCP discovery SPI. */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
-
-    /** Cache name which will be passed to grid configuration. */
-    private CacheMode cacheMode = PARTITIONED;
-
-    /** Cache mode which will be passed to grid configuration. */
-    private String cacheName = CACHE_NAME;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        CacheConfiguration ccfg = defaultCacheConfiguration();
-
-        ccfg.setName(cacheName);
-        ccfg.setCacheMode(cacheMode);
-        ccfg.setAtomicityMode(TRANSACTIONAL);
-        ccfg.setDistributionMode(NEAR_PARTITIONED);
-
-        if (cacheMode == PARTITIONED)
-            ccfg.setBackups(1);
-
-        cfg.setCacheConfiguration(ccfg);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * Start GRID_CNT nodes. All nodes except the last one will have one cache 
with particular name, while the last
-     * one will have one cache of the same type, but with different name.
-     *
-     * @throws Exception In case of exception.
-     */
-    private void startNodes() throws Exception {
-        cacheName = CACHE_NAME;
-
-        for (int i = 0; i < GRID_CNT - 1; i++)
-            startGrid(i);
-
-        cacheName = CACHE_NAME_OTHER;
-
-        startGrid(GRID_CNT - 1);
-    }
-
-    /**
-     * Test for partitioned cache.
-     *
-     * @throws Exception In case of exception.
-     */
-    public void testGlobalClearAllPartitioned() throws Exception {
-        cacheMode = PARTITIONED;
-
-        startNodes();
-
-        performTest();
-    }
-
-    /**
-     * Test for replicated cache.
-     *
-     * @throws Exception In case of exception.
-     */
-    public void testGlobalClearAllReplicated() throws Exception {
-        cacheMode = REPLICATED;
-
-        startNodes();
-
-        performTest();
-    }
-
-    /**
-     * Ensure that clear() clears correct cache and is only executed on nodes 
with the cache excluding
-     * master-node where it is executed locally.
-     *
-     * @throws Exception If failed.
-     */
-    public void performTest() throws Exception {
-        // Put values into normal replicated cache.
-        for (int i = 0; i < KEY_CNT; i++)
-            grid(0).jcache(CACHE_NAME).put(i, "val" + i);
-
-        // Put values into a cache with another name.
-        for (int i = 0; i < KEY_CNT_OTHER; i++)
-            grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).put(i, "val" + i);
-
-        // Check cache sizes.
-        for (int i = 0; i < GRID_CNT - 1; i++) {
-            IgniteCache<Object, Object> cache = grid(i).jcache(CACHE_NAME);
-
-            assertEquals("Key set [i=" + i + ']', KEY_CNT, cache.localSize());
-        }
-
-        assert grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).localSize() == 
KEY_CNT_OTHER;
-
-        // Perform clear.
-        grid(0).jcache(CACHE_NAME).clear();
-
-        // Expect caches with the given name to be clear on all nodes.
-        for (int i = 0; i < GRID_CNT - 1; i++)
-            assert grid(i).jcache(CACHE_NAME).isEmpty();
-
-        // ... but cache with another name should remain untouched.
-        assert grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).localSize() == 
KEY_CNT_OTHER;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/95d2c956/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index eb700d4..33b82b4 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -121,8 +121,8 @@ public abstract class GridCommonAbstractTest extends 
GridAbstractTest {
     /**
      * @param cache Cache.
      */
-    protected <K, V> GridCacheAdapter<K, V> internalCache(IgniteCache<K, V> 
cache) {
-        return 
((IgniteKernal)cache.unwrap(Ignite.class)).internalCache(cache.getName());
+    protected <K, V> GridCache<K, V> internalCache(IgniteCache<K, V> cache) {
+        return 
((IgniteKernal)cache.unwrap(Ignite.class)).cache(cache.getName());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/95d2c956/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 4cd6417..28539e7 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -95,7 +95,6 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(GridDataLoaderImplSelfTest.class);
         suite.addTestSuite(GridCacheEntryMemorySizeSelfTest.class);
         suite.addTestSuite(GridCacheClearAllSelfTest.class);
-        suite.addTestSuite(GridCacheGlobalClearAllSelfTest.class);
         suite.addTestSuite(GridCacheObjectToStringSelfTest.class);
         suite.addTestSuite(GridCacheLoadOnlyStoreAdapterSelfTest.class);
         suite.addTestSuite(GridCacheGetStoreErrorSelfTest.class);

Reply via email to