ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [25/29] ignite git commit: IGNITE-4891 - Fix. Key is deserialized during transactional get() even if withKeepBinary is set
Date Thu, 13 Apr 2017 15:56:55 GMT
IGNITE-4891 - Fix. Key is deserialized during transactional get() even if withKeepBinary is
set


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

Branch: refs/heads/ignite-4929
Commit: 407843251eb8326b5dddccbc0f7a46434ae8f7af
Parents: 252f004
Author: dkarachentsev <dkarachentsev@gridgain.com>
Authored: Mon Apr 10 16:48:01 2017 +0300
Committer: dkarachentsev <dkarachentsev@gridgain.com>
Committed: Thu Apr 13 09:26:49 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java |   5 +-
 .../cache/CacheKeepBinaryTransactionTest.java   | 121 +++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite5.java       |   2 +
 3 files changed, 126 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/40784325/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 81606d4..8be87d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -1895,8 +1895,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements
AutoClosea
                         for (Iterator<KeyCacheObject> it = missed.keySet().iterator();
it.hasNext(); ) {
                             KeyCacheObject cacheKey = it.next();
 
-                            K keyVal =
-                                (K)(keepCacheObjects ? cacheKey : cacheKey.value(cacheCtx.cacheObjectContext(),
false));
+                            K keyVal = (K)(keepCacheObjects ? cacheKey
+                                : cacheCtx.cacheObjectContext()
+                                .unwrapBinaryIfNeeded(cacheKey, !deserializeBinary, false));
 
                             if (retMap.containsKey(keyVal))
                                 it.remove();

http://git-wip-us.apache.org/repos/asf/ignite/blob/40784325/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheKeepBinaryTransactionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheKeepBinaryTransactionTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheKeepBinaryTransactionTest.java
new file mode 100644
index 0000000..9965737
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheKeepBinaryTransactionTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.IgniteBinary;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+
+/**
+ * Test that no deserialization happens with binary objects and keepBinary set flag.
+ */
+public class CacheKeepBinaryTransactionTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TransactionConfiguration txCfg = new TransactionConfiguration();
+        txCfg.setDefaultTxConcurrency(TransactionConcurrency.OPTIMISTIC);
+        txCfg.setDefaultTxIsolation(TransactionIsolation.REPEATABLE_READ);
+
+        cfg.setTransactionConfiguration(txCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration("tx-cache");
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBinaryGet() throws Exception {
+        IgniteEx ignite = grid(0);
+        IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary();
+
+        try (Transaction tx = ignite.transactions().txStart()) {
+            BinaryObject key = ignite.binary().builder("test1")
+                .setField("id", 1).build();
+
+            assertNull(cache.get(key));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBinaryContains() throws Exception {
+        IgniteEx ignite = grid(0);
+        IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary();
+
+        try (Transaction tx = ignite.transactions().txStart()) {
+            BinaryObject key = ignite.binary().builder("test2")
+                .setField("id", 1).build();
+
+            assertFalse(cache.containsKey(key));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBinaryPutGetContains() throws Exception {
+        IgniteEx ignite = grid(0);
+        IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary();
+
+        try (Transaction tx = ignite.transactions().txStart()) {
+            IgniteBinary binary = ignite.binary();
+
+            BinaryObject key = binary.builder("test-key").setField("id", 1).build();
+            BinaryObject val = binary.builder("test-val").setField("id", 22).build();
+
+            cache.put(key, val);
+
+            assertTrue(cache.containsKey(key));
+            assertEquals(val, cache.get(key));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/40784325/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
index 6fc6846..0716c20 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.CacheKeepBinaryTransactionTest;
 import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest;
 import org.apache.ignite.internal.processors.cache.CacheRebalancingSelfTest;
 import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest;
@@ -53,6 +54,7 @@ public class IgniteCacheTestSuite5 extends TestSuite {
         suite.addTestSuite(IgniteCacheWriteBehindNoUpdateSelfTest.class);
         suite.addTestSuite(IgniteCachePutStackOverflowSelfTest.class);
         suite.addTestSuite(GridCacheSwapSpaceSpiConsistencySelfTest.class);
+        suite.addTestSuite(CacheKeepBinaryTransactionTest.class);
 
         suite.addTestSuite(CacheLateAffinityAssignmentTest.class);
         suite.addTestSuite(CacheLateAffinityAssignmentFairAffinityTest.class);


Mime
View raw message