ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject [43/50] [abbrv] ignite git commit: IGNITE-4868 Raw Object keys and values indexing fix
Date Mon, 03 Apr 2017 08:31:43 GMT
IGNITE-4868 Raw Object keys and values indexing fix


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

Branch: refs/heads/master
Commit: b689624e2984ec3cf42ca5b01966937e236abcdc
Parents: 1ddce55
Author: Alexander Paschenko <alexander.a.paschenko@gmail.com>
Authored: Wed Mar 29 18:15:20 2017 +0300
Committer: Alexander Paschenko <alexander.a.paschenko@gmail.com>
Committed: Wed Mar 29 18:15:20 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    |   8 +-
 .../IgniteCacheObjectKeyIndexingSelfTest.java   | 124 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite2.java         |   4 +-
 3 files changed, 131 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b689624e/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 10bf75a..0bde688 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -17,12 +17,11 @@
 
 package org.apache.ignite.internal.processors.query;
 
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.concurrent.TimeUnit;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -40,6 +39,7 @@ import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
 import javax.cache.Cache;
 import javax.cache.CacheException;
 import org.apache.ignite.IgniteCheckedException;
@@ -457,7 +457,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @return {@code True} if will be deserialized.
      */
     private boolean mustDeserializeBinary(Class cls) {
-        if (cls != null && ctx.config().getMarshaller() instanceof BinaryMarshaller)
{
+        if (cls != null && cls != Object.class && ctx.config().getMarshaller()
instanceof BinaryMarshaller) {
             CacheObjectBinaryProcessorImpl proc0 = (CacheObjectBinaryProcessorImpl)ctx.cacheObjects();
 
             return proc0.binaryContext().mustDeserialize(cls);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b689624e/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheObjectKeyIndexingSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheObjectKeyIndexingSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheObjectKeyIndexingSelfTest.java
new file mode 100644
index 0000000..9e3a0bc
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheObjectKeyIndexingSelfTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test index behavior when key is of plain Object type per indexing settings.
+ */
+public class IgniteCacheObjectKeyIndexingSelfTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        Ignition.stopAll(true);
+    }
+
+    /** */
+    protected static CacheConfiguration<Object, TestObject> cacheCfg() {
+        return new CacheConfiguration<Object, TestObject>()
+            .setIndexedTypes(Object.class, TestObject.class);
+    }
+
+    /** */
+    public void testObjectKeyHandling() throws Exception {
+        Ignite ignite = grid();
+
+        IgniteCache<Object, TestObject> cache = ignite.getOrCreateCache(cacheCfg());
+
+        UUID uid = UUID.randomUUID();
+
+        cache.put(uid, new TestObject("A"));
+
+        assertItemsNumber(1);
+
+        cache.put(1, new TestObject("B"));
+
+        assertItemsNumber(2);
+
+        cache.put(uid, new TestObject("C"));
+
+        // Key should have been replaced
+        assertItemsNumber(2);
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("select _key, name
from TestObject order by name")).getAll();
+
+        assertEquals(res,
+            Arrays.asList(
+                Arrays.asList(1, "B"),
+                Arrays.asList(uid, "C")
+            )
+        );
+
+        cache.remove(1);
+
+        assertItemsNumber(1);
+
+        res = cache.query(new SqlFieldsQuery("select _key, name from TestObject")).getAll();
+
+        assertEquals(res,
+            Collections.singletonList(
+                Arrays.asList(uid, "C")
+            )
+        );
+        
+        cache.remove(uid);
+
+        // Removal has worked for both keys although the table was the same and keys were
of different type
+        assertItemsNumber(0);
+    }
+
+    /** */
+    @SuppressWarnings("ConstantConditions")
+    private void assertItemsNumber(long num) {
+        assertEquals(num, grid().cachex().size());
+
+        assertEquals(num, grid().cache(null).query(new SqlFieldsQuery("select count(*) from
TestObject")).getAll()
+            .get(0).get(0));
+    }
+    
+    /** */
+    private static class TestObject {
+        /** */
+        @QuerySqlField
+        public final String name;
+
+        /** */
+        private TestObject(String name) {
+            this.name = name;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b689624e/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
index 8ac219f..923a79c 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java
@@ -36,14 +36,15 @@ import org.apache.ignite.internal.processors.cache.CacheSqlQueryValueCopySelfTes
 import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexingDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheNoClassQuerySelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheObjectKeyIndexingSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingQueryErrorTest;
 import org.apache.ignite.internal.processors.cache.SqlFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheAtomicFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheAtomicNearEnabledFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheDistributedQueryCancelSelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCachePartitionedFieldsQueryP2PEnabledSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCachePartitionedFieldsQuerySelfTest;
-import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQueryP2PEnabledSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQuerySelfTest;
@@ -120,6 +121,7 @@ public class IgniteCacheQuerySelfTestSuite2 extends TestSuite {
         suite.addTestSuite(CacheQueryNewClientSelfTest.class);
         suite.addTestSuite(CacheOffheapBatchIndexingSingleTypeTest.class);
         suite.addTestSuite(CacheSqlQueryValueCopySelfTest.class);
+        suite.addTestSuite(IgniteCacheObjectKeyIndexingSelfTest.class);
 
         return suite;
     }


Mime
View raw message