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 2015/12/08 09:35:20 UTC
[4/7] ignite git commit: IGNITE-2050 - Fixed duplicate query types in
configuration. - Fixes #291.
IGNITE-2050 - Fixed duplicate query types in configuration. - Fixes #291.
Signed-off-by: Alexey Goncharuk <al...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ebddcb18
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ebddcb18
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ebddcb18
Branch: refs/heads/master
Commit: ebddcb187231c08bcf53a7c567f10064393a8e60
Parents: 9a14d64
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Mon Dec 7 20:11:48 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon Dec 7 20:11:48 2015 +0300
----------------------------------------------------------------------
.../configuration/CacheConfiguration.java | 34 ++++-
...cheDuplicateEntityConfigurationSelfTest.java | 126 +++++++++++++++++++
.../IgniteCacheQuerySelfTestSuite.java | 4 +
3 files changed, 159 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ebddcb18/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 034d20d..af3530a 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -1872,7 +1872,20 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
TypeDescriptor desc = processKeyAndValueClasses(keyCls, valCls);
- qryEntities.add(convert(desc));
+ QueryEntity converted = convert(desc);
+
+ boolean dup = false;
+
+ for (QueryEntity entity : qryEntities) {
+ if (F.eq(entity.getValueType(), converted.getValueType())) {
+ dup = true;
+
+ break;
+ }
+ }
+
+ if (!dup)
+ qryEntities.add(converted);
}
return this;
@@ -1968,10 +1981,21 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
public CacheConfiguration<K, V> setQueryEntities(Collection<QueryEntity> qryEntities) {
if (this.qryEntities == null)
this.qryEntities = new ArrayList<>(qryEntities);
- else if (indexedTypes != null)
- this.qryEntities.addAll(qryEntities);
- else
- throw new CacheException("Query entities can be set only once.");
+
+ for (QueryEntity entity : qryEntities) {
+ boolean found = false;
+
+ for (QueryEntity existing : this.qryEntities) {
+ if (F.eq(entity.getValueType(), existing.getValueType())) {
+ found = true;
+
+ break;
+ }
+ }
+
+ if (!found)
+ this.qryEntities.add(entity);
+ }
return this;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ebddcb18/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDuplicateEntityConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDuplicateEntityConfigurationSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDuplicateEntityConfigurationSelfTest.java
new file mode 100644
index 0000000..8311213
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheDuplicateEntityConfigurationSelfTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.LinkedHashMap;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgniteCacheDuplicateEntityConfigurationSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration c = super.getConfiguration(gridName);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(ipFinder);
+
+ c.setDiscoverySpi(disco);
+
+ return c;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrid(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassDuplicatesQueryEntity() throws Exception {
+ String cacheName = "duplicate";
+
+ CacheConfiguration ccfg = new CacheConfiguration(cacheName);
+
+ ccfg.setIndexedTypes(Integer.class, Person.class);
+
+ QueryEntity entity = new QueryEntity();
+
+ entity.setKeyType(Integer.class.getName());
+ entity.setValueType(Person.class.getName());
+
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("name", String.class.getName());
+
+ entity.setFields(fields);
+
+ ccfg.setQueryEntities(Arrays.asList(entity));
+
+ try {
+ ignite(0).getOrCreateCache(ccfg);
+ }
+ finally {
+ ignite(0).destroyCache(cacheName);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassDuplicatesQueryReverse() throws Exception {
+ String cacheName = "duplicate";
+
+ CacheConfiguration ccfg = new CacheConfiguration(cacheName);
+
+ QueryEntity entity = new QueryEntity();
+
+ entity.setKeyType(Integer.class.getName());
+ entity.setValueType(Person.class.getName());
+
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("name", String.class.getName());
+
+ entity.setFields(fields);
+
+ ccfg.setQueryEntities(Arrays.asList(entity));
+
+ ccfg.setIndexedTypes(Integer.class, Person.class);
+
+ try {
+ ignite(0).getOrCreateCache(ccfg);
+ }
+ finally {
+ ignite(0).destroyCache(cacheName);
+ }
+ }
+
+ private static class Person {
+ @QuerySqlField
+ private String name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ebddcb18/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index 8311414..fc88c75 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheQueryInternalKeysSel
import org.apache.ignite.internal.processors.cache.GridCacheQuerySerializationSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheCollocatedQuerySelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheDuplicateEntityConfigurationSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheNoClassQuerySelfTest;
@@ -111,6 +112,9 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
// Parsing
suite.addTestSuite(GridQueryParsingTest.class);
+ // Config.
+ suite.addTestSuite(IgniteCacheDuplicateEntityConfigurationSelfTest.class);
+
// Queries tests.
suite.addTestSuite(IgniteSqlSplitterSelfTest.class);
suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);