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/19 16:35:42 UTC

incubator-ignite git commit: # ignite-917: test

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-917-review 60650b0ff -> 9b144efc1


# ignite-917: test


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

Branch: refs/heads/ignite-917-review
Commit: 9b144efc1367c4cec794d8bad0d450be315bdfb4
Parents: 60650b0
Author: ashutak <as...@gridgain.com>
Authored: Fri Jun 19 17:35:47 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Jun 19 17:35:47 2015 +0300

----------------------------------------------------------------------
 .../internal/cluster/ClusterGroupAdapter.java   |   5 +-
 .../internal/ClusterForHostsSelfTest.java       | 112 +++++++++++++++++++
 .../ignite/internal/GridProjectionSelfTest.java |  32 ------
 3 files changed, 115 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b144efc/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 f2145d0..b940017 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
@@ -578,6 +578,8 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
 
     /** {@inheritDoc} */
     @Override public final ClusterGroup forHost(String host, String... hosts) {
+        A.notNull(host, "host");
+
         return forPredicate(new HostsFilter(host, hosts));
     }
 
@@ -779,8 +781,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
          * @param names Host names
          */
         private HostsFilter(String name, String... names) {
-            if (name != null)
-                validHostNames.add(name);
+            validHostNames.add(name);
 
             if (names != null && (names.length > 0))
                 Collections.addAll(validHostNames, names);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b144efc/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
new file mode 100644
index 0000000..1f4dd59
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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
+ */
+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/9b144efc/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
index 28782c3..9fbad80 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
@@ -248,36 +248,4 @@ public class GridProjectionSelfTest extends GridProjectionAbstractTest {
 
         return even ? cnt - 1 : cnt - 2;
     }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testForHost() throws Exception {
-//        Collection<ClusterNode> allNodes = ignite.cluster().nodes();
-//        ClusterNode localNode = ignite.cluster().localNode();
-//        List<String> inputHostNames = new ArrayList<>();
-//
-//        for (ClusterNode currentNode : allNodes)
-//            inputHostNames.addAll(currentNode.hostNames());
-//
-////        String[] inputHostNamesArray = inputHostNames.toArray(new String[] {});
-//        ClusterGroup resultGroup = ignite.cluster().forHost(inputHostNames.get(0), inputHostNames);
-//        ClusterGroup nullTestGroup = ignite.cluster().forHost(null, null);
-//
-//        assert ((resultGroup.node(localNode.id())) != null);
-//        assert ((nullTestGroup.node(localNode.id())) == null);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testForHost2() throws Exception {
-//        ClusterGroup myHost = ignite.cluster().forHost("my_host");
-//
-//        Collection<ClusterNode> nodes = myHost.nodes();
-//
-//        for (ClusterNode node : nodes) {
-//            if (node.hostNames())
-//        }
-    }
 }