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/06/26 13:06:31 UTC

[1/2] incubator-ignite git commit: # ignite-1006: review.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1006-review [created] 9cd3aa46a


# ignite-1006: review.


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

Branch: refs/heads/ignite-1006-review
Commit: 5d9bb16f9c0af43944edfca3b95e8350219cf9c5
Parents: a8232be
Author: ashutak <as...@gridgain.com>
Authored: Fri Jun 26 13:51:15 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Jun 26 13:51:15 2015 +0300

----------------------------------------------------------------------
 .../internal/cluster/ClusterGroupAdapter.java   |  12 +-
 .../internal/ClusterForHostsSelfTest.java       | 113 ---------------
 .../internal/ClusterGroupHostsSelfTest.java     | 139 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +-
 4 files changed, 144 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d9bb16f/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 b770d98..4b61116 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
@@ -296,16 +296,12 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
 
     /** {@inheritDoc} */
     @Override public Collection<String> hostNames() {
-        Collection<String> resultHostNames = new HashSet<String> ();
-        Collection<ClusterNode> allNodes = nodes();
+        Set<String> res = new HashSet<>();
 
-        if (!(allNodes.isEmpty()))
-        {
-            for (ClusterNode currentNode : allNodes)
-                Collections.addAll(resultHostNames, currentNode.hostNames().toArray(new String[0]));
-        }
+        for (ClusterNode node : nodes())
+            res.addAll(node.hostNames());
 
-        return resultHostNames;
+        return Collections.unmodifiableSet(res);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d9bb16f/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java
deleted file mode 100644
index 59c3db9..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-/**
- * Test for {@link ClusterGroup#forHost(String, String...)}.
- *
- * @see GridProjectionSelfTest
- */
-@GridCommonTest(group = "Kernal Self")
-public class ClusterForHostsSelfTest extends GridCommonAbstractTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        Collection<String> hostNames = null;
-
-        if ("forHostTest".equals(gridName))
-            hostNames = Arrays.asList("h_1", "h_2", "h_3");
-
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        if (hostNames != null) {
-            TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi();
-
-            cfg.setDiscoverySpi(new CustomHostsTcpDiscoverySpi(hostNames).setIpFinder(disco.getIpFinder()));
-        }
-
-        return cfg;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testForHosts() throws Exception {
-        Ignite ignite = startGrid("forHostTest");
-
-        assertEquals(1, ignite.cluster().forHost("h_1").nodes().size());
-        assertEquals(1, ignite.cluster().forHost("h_1", "h_3").nodes().size());
-        assertEquals(1, ignite.cluster().forHost("unknown_host", "h_2").nodes().size());
-        assertEquals(1, ignite.cluster().forHost("h_1", "h_3", "unknown_host", "h_2").nodes().size());
-
-        assertEquals(0, ignite.cluster().forHost("unknown_host").nodes().size());
-
-        boolean gotNpe = false;
-
-        try {
-            assertEquals(0, ignite.cluster().forHost(null, null, null).nodes().size());
-        }
-        catch (NullPointerException e) {
-            gotNpe = true;
-        }
-
-        assertTrue(gotNpe);
-    }
-
-    /**
-     * Tcp discovery spi that allow to customise hostNames of created local node.
-     */
-    private static class CustomHostsTcpDiscoverySpi extends TcpDiscoverySpi {
-        /** Hosts. */
-        private final Collection<String> hosts;
-
-        /**
-         * @param hosts Host names which will be retuned by {@link ClusterNode#hostNames()} of created local node.
-         */
-        CustomHostsTcpDiscoverySpi(Collection<String> hosts) {
-            this.hosts = hosts;
-        }
-
-        /**
-         * @param srvPort Server port.
-         */
-        @Override protected void initLocalNode(int srvPort, boolean addExtAddrAttr) {
-            super.initLocalNode(srvPort, addExtAddrAttr);
-
-            try {
-                Field hostNamesField = locNode.getClass().getDeclaredField("hostNames");
-
-                hostNamesField.setAccessible(true);
-
-                hostNamesField.set(locNode, hosts);
-            }
-            catch (IllegalAccessException | NoSuchFieldException e) {
-                U.error(log, "Looks like implementation of " + locNode.getClass()
-                    + " class was changed. Need to update test.", e);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d9bb16f/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
new file mode 100644
index 0000000..c1bae97
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+/**
+ * Test for {@link ClusterGroup#forHost(String, String...)}.
+ *
+ * @see ClusterGroupSelfTest
+ */
+@GridCommonTest(group = "Kernal Self")
+public class ClusterGroupHostsSelfTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        Collection<String> hostNames = null;
+
+        if ("forHostTest".equals(gridName))
+            hostNames = Arrays.asList("h_1", "h_2", "h_3");
+
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (hostNames != null) {
+            TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi();
+
+            cfg.setDiscoverySpi(new CustomHostsTcpDiscoverySpi(hostNames).setIpFinder(disco.getIpFinder()));
+        }
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForHosts() throws Exception {
+        Ignite ignite = startGrid("forHostTest");
+
+        assertEquals(1, ignite.cluster().forHost("h_1").nodes().size());
+        assertEquals(1, ignite.cluster().forHost("h_1", "h_3").nodes().size());
+        assertEquals(1, ignite.cluster().forHost("unknown_host", "h_2").nodes().size());
+        assertEquals(1, ignite.cluster().forHost("h_1", "h_3", "unknown_host", "h_2").nodes().size());
+
+        assertEquals(0, ignite.cluster().forHost("unknown_host").nodes().size());
+
+        boolean gotNpe = false;
+
+        try {
+            assertEquals(0, ignite.cluster().forHost(null, null, null).nodes().size());
+        }
+        catch (NullPointerException e) {
+            gotNpe = true;
+        }
+        finally {
+            assertTrue(gotNpe);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHostNames() throws Exception {
+        Ignite ignite = startGrid("forHostTest");
+
+        Collection<String> locNodeHosts = ignite.cluster().localNode().hostNames();
+        Collection<String> clusterHosts = ignite.cluster().hostNames();
+
+        assertTrue(F.eqNotOrdered(locNodeHosts, clusterHosts));
+
+        boolean gotNpe = false;
+
+        try {
+            clusterHosts.add("valueShouldNotToBeAdded");
+        }
+        catch (UnsupportedOperationException e) {
+            gotNpe = true;
+        }
+        finally {
+            assertTrue(gotNpe);
+        }
+    }
+
+    /**
+     * Tcp discovery spi that allow to customise hostNames of created local node.
+     */
+    private static class CustomHostsTcpDiscoverySpi extends TcpDiscoverySpi {
+        /** Hosts. */
+        private final Collection<String> hosts;
+
+        /**
+         * @param hosts Host names which will be retuned by {@link ClusterNode#hostNames()} of created local node.
+         */
+        CustomHostsTcpDiscoverySpi(Collection<String> hosts) {
+            this.hosts = hosts;
+        }
+
+        /**
+         * @param srvPort Server port.
+         */
+        @Override protected void initLocalNode(int srvPort, boolean addExtAddrAttr) {
+            super.initLocalNode(srvPort, addExtAddrAttr);
+
+            try {
+                Field hostNamesField = locNode.getClass().getDeclaredField("hostNames");
+
+                hostNamesField.setAccessible(true);
+
+                hostNamesField.set(locNode, hosts);
+            }
+            catch (IllegalAccessException | NoSuchFieldException e) {
+                U.error(log, "Looks like implementation of " + locNode.getClass()
+                    + " class was changed. Need to update test.", e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d9bb16f/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 6ff83e2..19c1932 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
@@ -65,7 +65,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTest(IgniteStreamSelfTestSuite.suite());
 
         suite.addTest(new TestSuite(GridSelfTest.class));
-        suite.addTest(new TestSuite(ClusterForHostsSelfTest.class));
+        suite.addTest(new TestSuite(ClusterGroupHostsSelfTest.class));
         suite.addTest(new TestSuite(IgniteMessagingWithClientTest.class));
 
         GridTestUtils.addTestIfNeeded(suite, ClusterGroupSelfTest.class, ignoredTests);


[2/2] incubator-ignite git commit: # ignite-1006: review.

Posted by sb...@apache.org.
# ignite-1006: review.


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

Branch: refs/heads/ignite-1006-review
Commit: 9cd3aa46a475d2f864b0bae7b8e03f2b378d9416
Parents: 5d9bb16
Author: ashutak <as...@gridgain.com>
Authored: Fri Jun 26 14:05:59 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Jun 26 14:05:59 2015 +0300

----------------------------------------------------------------------
 .../internal/ClusterGroupHostsSelfTest.java     | 22 +++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9cd3aa46/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
index c1bae97..297a590 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterGroupHostsSelfTest.java
@@ -36,19 +36,21 @@ import java.util.*;
 @GridCommonTest(group = "Kernal Self")
 public class ClusterGroupHostsSelfTest extends GridCommonAbstractTest {
     /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        Collection<String> hostNames = null;
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid();
+    }
 
-        if ("forHostTest".equals(gridName))
-            hostNames = Arrays.asList("h_1", "h_2", "h_3");
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        Collection<String> hostNames = Arrays.asList("h_1", "h_2", "h_3");
 
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        if (hostNames != null) {
-            TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi();
+        TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi();
 
-            cfg.setDiscoverySpi(new CustomHostsTcpDiscoverySpi(hostNames).setIpFinder(disco.getIpFinder()));
-        }
+        cfg.setDiscoverySpi(new CustomHostsTcpDiscoverySpi(hostNames).setIpFinder(disco.getIpFinder()));
 
         return cfg;
     }
@@ -57,7 +59,7 @@ public class ClusterGroupHostsSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testForHosts() throws Exception {
-        Ignite ignite = startGrid("forHostTest");
+        Ignite ignite = grid();
 
         assertEquals(1, ignite.cluster().forHost("h_1").nodes().size());
         assertEquals(1, ignite.cluster().forHost("h_1", "h_3").nodes().size());
@@ -83,7 +85,7 @@ public class ClusterGroupHostsSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testHostNames() throws Exception {
-        Ignite ignite = startGrid("forHostTest");
+        Ignite ignite = grid();
 
         Collection<String> locNodeHosts = ignite.cluster().localNode().hostNames();
         Collection<String> clusterHosts = ignite.cluster().hostNames();