IGNITE-10290 Fix Map.Entry interface for key cache may lead to incorrect hash code...
authorDmitriyGovorukhin <dmitriy.govorukhin@gmail.com>
Sat, 5 Jan 2019 16:32:17 +0000 (19:32 +0300)
committerDmitriy Govorukhin <dmitriy.govorukhin@gmail.com>
Sat, 5 Jan 2019 16:32:17 +0000 (19:32 +0300)
Signed-off-by: Dmitriy Govorukhin <dmitriy.govorukhin@gmail.com>
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java [new file with mode: 0644]
modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java

index 0629754..55fae44 100644 (file)
@@ -482,9 +482,11 @@ public class GridPartitionedGetFuture<K, V> extends CacheDistributedGetFutureAda
                 GridCacheVersion ver = null;
 
                 if (readNoEntry) {
+                    KeyCacheObject key0 = (KeyCacheObject)cctx.cacheObjects().prepareForCache(key, cctx);
+
                     CacheDataRow row = cctx.mvccEnabled() ?
-                        cctx.offheap().mvccRead(cctx, key, mvccSnapshot()) :
-                        cctx.offheap().read(cctx, key);
+                        cctx.offheap().mvccRead(cctx, key0, mvccSnapshot()) :
+                        cctx.offheap().read(cctx, key0);
 
                     if (row != null) {
                         long expireTime = row.expireTime();
index 0d69485..8878414 100644 (file)
@@ -440,9 +440,11 @@ public class GridPartitionedSingleGetFuture extends GridCacheFutureAdapter<Objec
                 boolean skipEntry = readNoEntry;
 
                 if (readNoEntry) {
+                    KeyCacheObject key0 = (KeyCacheObject)cctx.cacheObjects().prepareForCache(key, cctx);
+
                     CacheDataRow row = mvccSnapshot != null ?
-                        cctx.offheap().mvccRead(cctx, key, mvccSnapshot) :
-                        cctx.offheap().read(cctx, key);
+                        cctx.offheap().mvccRead(cctx, key0, mvccSnapshot) :
+                        cctx.offheap().read(cctx, key0);
 
                     if (row != null) {
                         long expireTime = row.expireTime();
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheLocalGetSerializationTest.java
new file mode 100644 (file)
index 0000000..bfcc413
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ *
+ */
+@RunWith(JUnit4.class)
+public class CacheLocalGetSerializationTest extends GridCommonAbstractTest {
+    /**
+     * Check correct Map.Entry serialization key on local get/put operation.
+     * https://issues.apache.org/jira/browse/IGNITE-10290
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test() throws Exception {
+        Ignite ig = startGrid();
+
+        IgniteCache<Map.Entry<Integer, Integer>, Long> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
+
+        // Try use Map.Entry as key in destributed map.
+        Map.Entry<Integer, Integer> key = new Map.Entry<Integer, Integer>() {
+            @Override public Integer getKey() {
+                return 123;
+            }
+
+            @Override public Integer getValue() {
+                return 123;
+            }
+
+            @Override public Integer setValue(Integer value) {
+                throw new UnsupportedOperationException();
+            }
+        };
+
+        cache.put(key, Long.MAX_VALUE);
+
+        Long val = cache.get(key);
+
+        Assert.assertNotNull(val);
+        Assert.assertEquals(Long.MAX_VALUE, (long)val);
+    }
+}
index 276dbc5..369a0b5 100644 (file)
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesMultipleConne
 import org.apache.ignite.internal.managers.IgniteDiagnosticMessagesTest;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorMemoryLeakTest;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorRendezvousSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheLocalGetSerializationTest;
 import org.apache.ignite.internal.processors.cache.CacheRebalanceConfigValidationTest;
 import org.apache.ignite.internal.processors.cache.GridLocalIgniteSerializationTest;
 import org.apache.ignite.internal.processors.cache.GridProjectionForCachesOnDaemonNodeSelfTest;
@@ -219,6 +220,8 @@ public class IgniteBasicTestSuite {
 
         suite.addTest(new JUnit4TestAdapter(ListeningTestLoggerTest.class));
 
+        suite.addTest(new JUnit4TestAdapter(CacheLocalGetSerializationTest.class));
+
         return suite;
     }
 }