ignite-737 ClusterGroup.forDataNodes() returns empty cluster group for daemon 
node


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

Branch: refs/heads/ignite-sprint-4
Commit: 7c6fb23e9628655fdc307ce50ed658e06fe45c25
Parents: 3fdc824
Author: agura <ag...@gridgain.com>
Authored: Tue Apr 14 18:21:07 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Wed Apr 15 16:07:15 2015 +0300

----------------------------------------------------------------------
 .../internal/cluster/ClusterGroupAdapter.java   |  19 ++-
 ...ProjectionForCachesOnDaemonNodeSelfTest.java | 147 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +
 3 files changed, 166 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c6fb23e/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
index e52bed4..be91d19 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
@@ -530,22 +530,37 @@ public class ClusterGroupAdapter implements 
ClusterGroupEx, Externalizable {
 
     /** {@inheritDoc} */
     @Override public final ClusterGroup forCacheNodes(@Nullable String 
cacheName) {
+        if (ctx.isDaemon())
+            throw new IllegalStateException("Not applicable for the daemon 
node.");
+
         return forPredicate(new CachesFilter(cacheName, true, true, true));
     }
 
     /** {@inheritDoc} */
     @Override public final ClusterGroup forDataNodes(@Nullable String 
cacheName) {
+        if (ctx.isDaemon())
+            throw new IllegalStateException("Not applicable for the daemon 
node.");
+
         return forPredicate(new CachesFilter(cacheName, true, false, false));
     }
 
     /** {@inheritDoc} */
     @Override public final ClusterGroup forClientNodes(@Nullable String 
cacheName) {
+        if (ctx.isDaemon())
+            throw new IllegalStateException("Not applicable for the daemon 
node.");
+
         return forPredicate(new CachesFilter(cacheName, false, true, true));
     }
 
     /** {@inheritDoc} */
-    @Override public ClusterGroup forCacheNodes(@Nullable String cacheName, 
boolean affNodes, boolean nearNodes,
-        boolean clientNodes) {
+    @Override public ClusterGroup forCacheNodes(@Nullable String cacheName,
+        boolean affNodes,
+        boolean nearNodes,
+        boolean clientNodes)
+    {
+        if (ctx.isDaemon())
+            throw new IllegalStateException("Not applicable for the daemon 
node.");
+
         return forPredicate(new CachesFilter(cacheName, affNodes, nearNodes, 
clientNodes));
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c6fb23e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridProjectionForCachesOnDaemonNodeSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridProjectionForCachesOnDaemonNodeSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridProjectionForCachesOnDaemonNodeSelfTest.java
new file mode 100644
index 0000000..b9acd99
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridProjectionForCachesOnDaemonNodeSelfTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.spi.discovery.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Tests of cache related cluster projections for daemon node.
+ */
+public class GridProjectionForCachesOnDaemonNodeSelfTest extends 
GridCommonAbstractTest {
+    /** Ip finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** Daemon node. */
+    private static boolean daemonNode;
+
+    /** Daemon. */
+    private static Ignite ignite;
+
+    /** Daemon. */
+    private static Ignite daemon;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setDiscoverySpi(discoverySpi());
+
+        cfg.setDaemon(daemonNode);
+
+        return cfg;
+    }
+
+    /**
+     * @return Discovery SPI;
+     */
+    private DiscoverySpi discoverySpi() {
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
+
+        spi.setIpFinder(IP_FINDER);
+
+        return spi;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        ignite = startGrid(0);
+
+        daemonNode = true;
+
+        daemon = startGrid(1);
+
+        assert ((IgniteKernal)daemon).localNode().isDaemon();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    protected void beforeTest() throws Exception {
+        ignite.getOrCreateCache((String)null);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.cache(null).close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForDataNodes() throws Exception {
+        ClusterGroup grp = ignite.cluster().forDataNodes(null);
+
+        assertFalse(grp.nodes().isEmpty());
+
+        try {
+            daemon.cluster().forDataNodes(null);
+        }
+        catch (IllegalStateException e) {
+            return;
+        }
+
+        fail();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForClientNodes() throws Exception {
+        ClusterGroup grp = ignite.cluster().forClientNodes(null);
+
+        assertTrue(grp.nodes().isEmpty());
+
+        try {
+            daemon.cluster().forClientNodes(null);
+        }
+        catch (IllegalStateException e) {
+            return;
+        }
+
+        fail();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForCacheNodes() throws Exception {
+        ClusterGroup grp = ignite.cluster().forCacheNodes(null);
+
+        assertFalse(grp.nodes().isEmpty());
+
+        try {
+            daemon.cluster().forCacheNodes(null);
+        }
+        catch (IllegalStateException e) {
+            return;
+        }
+
+        fail();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c6fb23e/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 5d53129..2b33d7e 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -21,6 +21,7 @@ import junit.framework.*;
 import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.closure.*;
 import org.apache.ignite.internal.processors.continuous.*;
 import org.apache.ignite.internal.product.*;
@@ -61,6 +62,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(GridClosureProcessorSelfTest.class);
         suite.addTestSuite(GridStartStopSelfTest.class);
         suite.addTestSuite(GridProjectionForCachesSelfTest.class);
+        suite.addTestSuite(GridProjectionForCachesOnDaemonNodeSelfTest.class);
         suite.addTestSuite(GridSpiLocalHostInjectionTest.class);
         suite.addTestSuite(GridLifecycleBeanSelfTest.class);
         suite.addTestSuite(GridStopWithCancelSelfTest.class);

Reply via email to