ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject ignite git commit: IGNITE-4324 Check node list is non-empty before selecting one for query execution.
Date Tue, 13 Jun 2017 10:27:59 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 4df693704 -> 5f84bf498


IGNITE-4324 Check node list is non-empty before selecting one for query execution.

Signed-off-by: nikolay_tikhonov <ntikhonov@gridgain.com>


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

Branch: refs/heads/master
Commit: 5f84bf498c45a9437de80806ca50419bc221f10c
Parents: 4df6937
Author: William Do <williamd0@outlook.com>
Authored: Tue Jun 13 13:28:00 2017 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Tue Jun 13 13:28:00 2017 +0300

----------------------------------------------------------------------
 .../cache/query/GridCacheQueryAdapter.java      |   9 +-
 .../cache/CacheIteratorScanQueryTest.java       | 110 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   2 +
 3 files changed, 118 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5f84bf49/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
index 0372868..87eed82 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
@@ -570,9 +570,12 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T>
{
                 if (prj != null || part != null)
                     return nodes(cctx, prj, part);
 
-                return cctx.affinityNode() ?
-                    Collections.singletonList(cctx.localNode()) :
-                    Collections.singletonList(F.rand(nodes(cctx, null, null)));
+                if (cctx.affinityNode())
+                    return Collections.singletonList(cctx.localNode());
+
+                Collection<ClusterNode> affNodes = nodes(cctx, null, null);
+
+                return affNodes.isEmpty() ? affNodes : Collections.singletonList(F.rand(affNodes));
 
             case PARTITIONED:
                 return nodes(cctx, prj, part);

http://git-wip-us.apache.org/repos/asf/ignite/blob/5f84bf49/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIteratorScanQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIteratorScanQueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIteratorScanQueryTest.java
new file mode 100644
index 0000000..0151471
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIteratorScanQueryTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ * Node filter test.
+ */
+public class CacheIteratorScanQueryTest extends GridCommonAbstractTest {
+    /** Client mode. */
+    private boolean client = false;
+
+    /** Cache configurations. */
+    private CacheConfiguration[] ccfgs = null;
+
+    /** */
+    public CacheIteratorScanQueryTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        client = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String name) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(name);
+
+        cfg.setClientMode(client);
+        cfg.setCacheConfiguration(ccfgs);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testScanQuery() throws Exception {
+        Ignite server = startGrid(0);
+
+        client = true;
+        ccfgs = new CacheConfiguration[] {
+            new CacheConfiguration("test-cache-replicated").setCacheMode(REPLICATED)
+                .setNodeFilter(new AlwaysFalseCacheFilter()),
+            new CacheConfiguration("test-cache-partitioned").setCacheMode(PARTITIONED)
+                .setNodeFilter(new AlwaysFalseCacheFilter())
+        };
+
+        Ignite client = startGrid(1);
+
+        assertEquals(2, server.cluster().nodes().size());
+        assertEquals(1, server.cluster().forServers().nodes().size());
+        assertEquals(1, server.cluster().forClients().nodes().size());
+
+        assertEquals(2, client.cluster().nodes().size());
+        assertEquals(1, client.cluster().forServers().nodes().size());
+        assertEquals(1, client.cluster().forClients().nodes().size());
+
+        for (CacheConfiguration cfg : ccfgs) {
+            IgniteCache<Object, Object> cache = client.cache(cfg.getName());
+
+            assertNotNull(cache);
+            assertNotNull(cache.iterator());
+            assertFalse(cache.iterator().hasNext());
+        }
+    }
+
+    /**
+     * Return always false.
+     */
+    public static class AlwaysFalseCacheFilter implements IgnitePredicate<ClusterNode>
{
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode node) {
+            return false;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/5f84bf49/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 0d18517..7b90e8e 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.CacheIteratorScanQueryTest;
 import org.apache.ignite.internal.processors.cache.CacheLocalQueryDetailMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.CacheLocalQueryMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.CacheOffheapBatchIndexingSingleTypeTest;
@@ -282,6 +283,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheLocalQueryCancelOrTimeoutSelfTest.class);
 
         // Other.
+        suite.addTestSuite(CacheIteratorScanQueryTest.class);
         suite.addTestSuite(CacheQueryNewClientSelfTest.class);
         suite.addTestSuite(CacheOffheapBatchIndexingSingleTypeTest.class);
         suite.addTestSuite(CacheSqlQueryValueCopySelfTest.class);


Mime
View raw message