You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/12/08 08:34:51 UTC

[20/30] ignite git commit: IGNITE-7088 Fix implementation of DIRECT comparator for ordering cache start operations. This closes #3136.

IGNITE-7088 Fix implementation of DIRECT comparator for ordering cache start operations. This closes #3136.

Signed-off-by: nikolay_tikhonov <nt...@gridgain.com>


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

Branch: refs/heads/ignite-zk
Commit: bbeb2050877d064cf937c12a4f1536079da40b17
Parents: cab5cc5
Author: Evgenii Zhuravlev <e....@gmail.com>
Authored: Thu Dec 7 15:42:33 2017 +0300
Committer: nikolay_tikhonov <nt...@gridgain.com>
Committed: Thu Dec 7 15:42:33 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/ClusterCachesInfo.java     |  8 ++--
 .../processors/cache/CacheComparatorTest.java   | 48 ++++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite2.java       |  3 ++
 3 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bbeb2050/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index 2b5ebf9..2c32bf2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -1755,16 +1755,14 @@ class ClusterCachesInfo {
      * Use DIRECT comparator for ordering cache start operations.
      * Use REVERSE comparator for ordering cache stop operations.
      */
-    private static class CacheComparators {
+    static class CacheComparators {
         /**
          * DIRECT comparator for cache descriptors (first system caches).
          */
         static Comparator<DynamicCacheDescriptor> DIRECT = new Comparator<DynamicCacheDescriptor>() {
             @Override public int compare(DynamicCacheDescriptor o1, DynamicCacheDescriptor o2) {
-                if (!o1.cacheType().userCache())
-                    return -1;
-                if (!o2.cacheType().userCache())
-                    return 1;
+                if (o1.cacheType().userCache() ^ o2.cacheType().userCache())
+                    return o2.cacheType().userCache() ? -1 : 1;
 
                 return o1.cacheId().compareTo(o2.cacheId());
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbeb2050/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheComparatorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheComparatorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheComparatorTest.java
new file mode 100644
index 0000000..0bd587d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheComparatorTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.query.QuerySchema;
+
+/**
+ * Test for CacheComparators from ClusterCachesInfo
+ */
+public class CacheComparatorTest extends TestCase {
+    /**
+     * Test if comparator not violates its general contract
+     */
+    public void testDirect() {
+        DynamicCacheDescriptor desc1 = new DynamicCacheDescriptor(null,
+            new CacheConfiguration().setName("1111"), CacheType.DATA_STRUCTURES,
+            null, true, null, true,
+            false, null, new QuerySchema());
+
+        DynamicCacheDescriptor desc2 = new DynamicCacheDescriptor(null,
+            new CacheConfiguration().setName("2222"), CacheType.INTERNAL,
+            null, true, null, true,
+            false, null, new QuerySchema());
+
+        assertEquals(-1,
+            ClusterCachesInfo.CacheComparators.DIRECT.compare(desc1, desc2));
+
+        assertEquals(1,
+            ClusterCachesInfo.CacheComparators.DIRECT.compare(desc2, desc1));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbeb2050/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 5ce213e..65cbcc0 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
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunctionBac
 import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunctionExcludeNeighborsSelfTest;
 import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunctionFastPowerOfTwoHashSelfTest;
 import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunctionStandardHashSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheComparatorTest;
 import org.apache.ignite.internal.processors.cache.CacheConcurrentReadThroughTest;
 import org.apache.ignite.internal.processors.cache.CacheConfigurationLeakTest;
 import org.apache.ignite.internal.processors.cache.CacheDhtLocalPartitionAfterRemoveSelfTest;
@@ -294,6 +295,8 @@ public class IgniteCacheTestSuite2 extends TestSuite {
 
         suite.addTest(new TestSuite(CachePartitionStateTest.class));
 
+        suite.addTest(new TestSuite(CacheComparatorTest.class));
+
         return suite;
     }
 }