ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject [1/3] ignite git commit: IGNITE-4324 Check node list is non-empty before selecting one for query execution
Date Thu, 08 Jun 2017 13:06:40 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-4324 [created] 715c40c41


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


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

Branch: refs/heads/ignite-4324
Commit: 91dbe85f394c00cce8efde08588670fd7cdcd8ea
Parents: 40851c7
Author: William Do <williamd0@outlook.com>
Authored: Fri May 12 22:18:20 2017 +0100
Committer: William Do <williamd0@outlook.com>
Committed: Sat May 27 14:37:10 2017 +0100

----------------------------------------------------------------------
 .../cache/query/GridCacheQueryAdapter.java      |   8 +-
 .../cache/CacheIteratorScanQueryTest.java       | 102 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   2 +
 3 files changed, 109 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/91dbe85f/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..ba82a68 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,11 @@ 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> dataNodes = nodes(cctx, null, null);
+                return dataNodes.isEmpty() ? dataNodes : Collections.singletonList(F.rand(dataNodes));
 
             case PARTITIONED:
                 return nodes(cctx, prj, part);

http://git-wip-us.apache.org/repos/asf/ignite/blob/91dbe85f/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..dc4ca47
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIteratorScanQueryTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.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")
+            .setCacheMode(REPLICATED).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());
+
+        IgniteCache<Object, Object> cache = client.cache("test-cache");
+
+        assertNotNull(cache);
+        assertNotNull(cache.iterator());
+    }
+
+    /**
+     * 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/91dbe85f/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 14fb6ce..4cabde3 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;
@@ -276,6 +277,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