Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A792717921 for ; Wed, 24 Jun 2015 13:19:17 +0000 (UTC) Received: (qmail 47923 invoked by uid 500); 24 Jun 2015 13:19:17 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 47893 invoked by uid 500); 24 Jun 2015 13:19:17 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 47884 invoked by uid 99); 24 Jun 2015 13:19:17 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2015 13:19:17 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 23CA3C0F3C for ; Wed, 24 Jun 2015 13:19:17 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id ehnC6cwZWf8o for ; Wed, 24 Jun 2015 13:19:11 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 0BBCA249C8 for ; Wed, 24 Jun 2015 13:19:09 +0000 (UTC) Received: (qmail 47746 invoked by uid 99); 24 Jun 2015 13:19:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2015 13:19:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C4D07E0544; Wed, 24 Jun 2015 13:19:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Wed, 24 Jun 2015 13:19:09 -0000 Message-Id: <1017c16e2e37427fb32e9430d04579b8@git.apache.org> In-Reply-To: <3bf2ce828021460ea36b63d44f80fb37@git.apache.org> References: <3bf2ce828021460ea36b63d44f80fb37@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-ignite git commit: # ignite-917: review (ignite-1033 fixed). # ignite-917: review (ignite-1033 fixed). Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/532a98f1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/532a98f1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/532a98f1 Branch: refs/heads/ignite-917 Commit: 532a98f13933ce34168b64854a735f4f9ee4b8bd Parents: 2ad4fe1 Author: ashutak Authored: Wed Jun 24 16:19:27 2015 +0300 Committer: ashutak Committed: Wed Jun 24 16:19:27 2015 +0300 ---------------------------------------------------------------------- .../ClientAbstractConnectivitySelfTest.java | 4 +- .../org/apache/ignite/cluster/ClusterNode.java | 2 + .../internal/cluster/ClusterGroupAdapter.java | 30 +++-- .../cluster/IgniteClusterAsyncImpl.java | 2 +- .../ignite/internal/util/IgniteUtils.java | 6 +- .../internal/ClusterForHostsSelfTest.java | 113 +++++++++++++++++++ .../ignite/internal/GridProjectionSelfTest.java | 19 ---- .../internal/util/IgniteUtilsSelfTest.java | 22 ++++ .../ignite/testsuites/IgniteBasicTestSuite.java | 1 + 9 files changed, 157 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java index 5aec7e5..a2e7c38 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractConnectivitySelfTest.java @@ -20,9 +20,9 @@ package org.apache.ignite.internal.client.integration; import org.apache.ignite.*; import org.apache.ignite.internal.client.*; import org.apache.ignite.internal.util.*; -import org.apache.ignite.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lang.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.common.*; import org.jetbrains.annotations.*; @@ -146,7 +146,7 @@ public abstract class ClientAbstractConnectivitySelfTest extends GridCommonAbstr startRestNode("grid1", LOOPBACK_IP, defaultRestPort()); checkConnectivityByIp(LOOPBACK_IP, F.t((Collection)Collections.singleton(LOOPBACK_IP), - (Collection)Collections.singleton(""))); + (Collection)Collections.emptySet())); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java index 85fd08a..bb792d5 100644 --- a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java +++ b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterNode.java @@ -188,6 +188,8 @@ public interface ClusterNode { *

* If {@link IgniteConfiguration#getLocalHost()} value is {@code null} then local wildcard address will be used, * and this method returns host names of all addresses of that node. + *

validHostNames = new HashSet<>(); /** - * @param name First host name. - * @param names Host names + * @param name First host name. + * @param names Host names */ - private HostsFilter(String name, String[] names) { - hashInputHostNames = new HashSet(); - - if (name != null) - hashInputHostNames.add(name); + private HostsFilter(String name, String... names) { + validHostNames.add(name); - if (names != null && (names.length > 0)) { - for (String currentInputHostName : names) - hashInputHostNames.add(currentInputHostName); - } + if (names != null && (names.length > 0)) + Collections.addAll(validHostNames, names); } /** {@inheritDoc} */ @Override public boolean apply(ClusterNode n) { - for (String currentHostName : n.hostNames()) { - if (hashInputHostNames.contains(currentHostName)) { - return true; - } + for (String hostName : n.hostNames()) { + if (validHostNames.contains(hostName)) + return true; } return false; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java index ca6cf32..6e68527 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java @@ -233,7 +233,7 @@ public class IgniteClusterAsyncImpl extends AsyncSupportAdapter /** {@inheritDoc} */ @Override public ClusterGroup forHost(String host, String... hosts) { - return cluster.forHost(host, hosts); + return cluster.forHost(host, hosts); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 6623e85..f457d6c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -1658,10 +1658,10 @@ public abstract class IgniteUtils { String ipAddr = addr.getHostAddress(); - hostName = F.isEmpty(hostName) || hostName.equals(ipAddr) || addr.isLoopbackAddress() ? "" : hostName; - addrs.add(ipAddr); - hostNames.add(hostName); + + if (!F.isEmpty(hostName) && !addr.isLoopbackAddress()) + hostNames.add(hostName); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/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..59c3db9 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterForHostsSelfTest.java @@ -0,0 +1,113 @@ +/* + * 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 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 hosts; + + /** + * @param hosts Host names which will be retuned by {@link ClusterNode#hostNames()} of created local node. + */ + CustomHostsTcpDiscoverySpi(Collection 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/532a98f1/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 bd625d9..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,23 +248,4 @@ public class GridProjectionSelfTest extends GridProjectionAbstractTest { return even ? cnt - 1 : cnt - 2; } - - /** - * @throws Exception If failed. - */ - public void testForHost() throws Exception { - Collection allNodes = ignite.cluster().nodes(); - ClusterNode localNode = ignite.cluster().localNode(); - ArrayList inputHostNames = new ArrayList (); - - for (ClusterNode currentNode : allNodes) - Collections.addAll(inputHostNames, currentNode.hostNames().toArray(new String[0])); - - String[] inputHostNamesArray = inputHostNames.toArray(new String[] {}); - ClusterGroup resultGroup = ignite.cluster().forHost(inputHostNamesArray[0], inputHostNamesArray); - ClusterGroup nullTestGroup = ignite.cluster().forHost(null, null); - - assert((resultGroup.node(localNode.id())) != null); - assert((nullTestGroup.node(localNode.id())) == null); - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java index 6e3e0e2..4762001 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java @@ -23,6 +23,7 @@ import org.apache.ignite.compute.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lang.*; import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.http.*; import org.apache.ignite.testframework.junits.*; @@ -698,6 +699,27 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { } /** + * @throws Exception If failed. + */ + public void testResolveLocalAddresses() throws Exception { + InetAddress inetAddress = InetAddress.getByName("0.0.0.0"); + + IgniteBiTuple, Collection> addrs = U.resolveLocalAddresses(inetAddress); + + Collection hostNames = addrs.get2(); + + assertFalse(hostNames.contains(null)); + assertFalse(hostNames.contains("")); + assertFalse(hostNames.contains("127.0.0.1")); + + assertFalse(F.exist(hostNames, new IgnitePredicate() { + @Override public boolean apply(String hostName) { + return hostName.contains("localhost") || hostName.contains("0:0:0:0:0:0:0:1"); + } + })); + } + + /** * Test enum. */ private enum TestEnum { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532a98f1/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 2d14728..8be9f31 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 @@ -66,6 +66,7 @@ public class IgniteBasicTestSuite extends TestSuite { suite.addTest(new TestSuite(GridSelfTest.class)); GridTestUtils.addTestIfNeeded(suite, GridProjectionSelfTest.class, ignoredTests); + suite.addTest(new TestSuite(ClusterForHostsSelfTest.class)); GridTestUtils.addTestIfNeeded(suite, GridMessagingSelfTest.class, ignoredTests); suite.addTest(new TestSuite(IgniteMessagingWithClientTest.class)); GridTestUtils.addTestIfNeeded(suite, GridMessagingNoPeerClassLoadingSelfTest.class, ignoredTests);