You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2016/02/17 02:49:53 UTC

[26/27] ignite git commit: Fixed CacheEvictableEntryImpl.equals()

Fixed CacheEvictableEntryImpl.equals()


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

Branch: refs/heads/ignite-2249
Commit: d2767359a339035df435e6484d48746db6333b83
Parents: 7be1aab
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Tue Feb 16 17:38:44 2016 -0800
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Tue Feb 16 17:38:44 2016 -0800

----------------------------------------------------------------------
 .../GridCacheEvictableEntryEqualsSelfTest.java  | 85 ++++++++++++++++++++
 .../IgniteCacheEvictionSelfTestSuite.java       |  4 +-
 2 files changed, 88 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d2767359/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictableEntryEqualsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictableEntryEqualsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictableEntryEqualsSelfTest.java
new file mode 100644
index 0000000..2b40365
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictableEntryEqualsSelfTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.eviction;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.eviction.EvictableEntry;
+import org.apache.ignite.cache.eviction.EvictionPolicy;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test for EvictableEntry.equals().
+ */
+public class GridCacheEvictableEntryEqualsSelfTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEquals() throws Exception {
+        try (Ignite ignite = startGrid()) {
+            CacheConfiguration<TestKey, String> cfg = new CacheConfiguration<>("test");
+
+            cfg.setEvictionPolicy(new TestEvictionPolicy());
+
+            IgniteCache<TestKey, String> cache = ignite.createCache(cfg);
+
+            for (int i = 0; i < 10; i++)
+                cache.put(new TestKey(0), "val" + i);
+        }
+    }
+
+    private static class TestEvictionPolicy implements EvictionPolicy<TestKey, String>, Serializable {
+        private final Collection<EvictableEntry> entries = new ArrayList<>();
+
+        @Override public synchronized void onEntryAccessed(boolean rmv, EvictableEntry<TestKey, String> e) {
+            for (EvictableEntry e0 : entries)
+                assertTrue(e0.equals(e));
+
+            entries.add(e);
+        }
+    }
+
+    private static class TestKey {
+        private final int key;
+
+        public TestKey(int key) {
+            this.key = key;
+        }
+
+        @Override public boolean equals(Object other) {
+            if (this == other)
+                return true;
+
+            if (other == null || getClass() != other.getClass())
+                return false;
+
+            TestKey testKey = (TestKey)other;
+
+            return key == testKey.key;
+
+        }
+
+        @Override public int hashCode() {
+            return key;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d2767359/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
index 3d8bbba..1ad63ee 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.eviction.GridCacheConcurrentE
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheDistributedEvictionsSelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheEmptyEntriesLocalSelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheEmptyEntriesPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.eviction.GridCacheEvictableEntryEqualsSelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheEvictionFilterSelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheEvictionLockUnlockSelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.GridCacheEvictionTouchSelfTest;
@@ -68,7 +69,8 @@ public class IgniteCacheEvictionSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheEmptyEntriesLocalSelfTest.class));
         suite.addTest(new TestSuite(GridCacheMemoryModeSelfTest.class));
         suite.addTest(new TestSuite(GridCacheSynchronousEvictionsFailoverSelfTest.class));
+        suite.addTest(new TestSuite(GridCacheEvictableEntryEqualsSelfTest.class));
 
         return suite;
     }
-}
\ No newline at end of file
+}