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 78E4518D25 for ; Thu, 16 Jul 2015 13:23:15 +0000 (UTC) Received: (qmail 24017 invoked by uid 500); 16 Jul 2015 13:23:09 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 23984 invoked by uid 500); 16 Jul 2015 13:23:09 -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 23933 invoked by uid 99); 16 Jul 2015 13:23:09 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jul 2015 13:23:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 92D4B1A70DC for ; Thu, 16 Jul 2015 13:23:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, 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 (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id DLkdN46IPeug for ; Thu, 16 Jul 2015 13:23:00 +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 34E8A2142E for ; Thu, 16 Jul 2015 13:22:58 +0000 (UTC) Received: (qmail 23031 invoked by uid 99); 16 Jul 2015 13:22:58 -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; Thu, 16 Jul 2015 13:22:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B87C5E4957; Thu, 16 Jul 2015 13:22:57 +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: Thu, 16 Jul 2015 13:23:00 -0000 Message-Id: <91cf7908e9aa4d758242c96dac3f83a5@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/4] incubator-ignite git commit: ignite-752: added tests ignite-752: added tests Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5fc818c0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5fc818c0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5fc818c0 Branch: refs/heads/ignite-752 Commit: 5fc818c05190f50dd6bfc753f54e74f422426c66 Parents: 0949c93 Author: Denis Magda Authored: Thu Jul 16 16:22:45 2015 +0300 Committer: Denis Magda Committed: Thu Jul 16 16:22:45 2015 +0300 ---------------------------------------------------------------------- .../configuration/IgniteConfiguration.java | 8 +- .../IgniteSpiOperationTimeoutController.java | 2 +- .../spi/discovery/tcp/TcpDiscoverySpi.java | 18 +- ...TcpDiscoverySpiFailureThresholdSelfTest.java | 215 +++++++++++++++++++ .../IgniteSpiDiscoverySelfTestSuite.java | 1 + 5 files changed, 232 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fc818c0/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index b3d2bfc..49b53c9 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -190,7 +190,7 @@ public class IgniteConfiguration { public static final boolean DFLT_CACHE_SANITY_CHECK_ENABLED = true; /** Default failure detection threshold used by DiscoverySpi and CommunicationSpi in millis. */ - public static final int DFLT_FAILURE_DETECTION_THRESHOLD = 10_000; + public static final long DFLT_FAILURE_DETECTION_THRESHOLD = 10_000; /** Optional grid name. */ private String gridName; @@ -370,7 +370,7 @@ public class IgniteConfiguration { private int timeSrvPortRange = DFLT_TIME_SERVER_PORT_RANGE; /** Failure detection threshold used by DiscoverySpi and CommunicationSpi. */ - private int failureDetectionThreshold = DFLT_FAILURE_DETECTION_THRESHOLD; + private long failureDetectionThreshold = DFLT_FAILURE_DETECTION_THRESHOLD; /** Property names to include into node attributes. */ private String[] includeProps; @@ -1639,7 +1639,7 @@ public class IgniteConfiguration { * TODO: IGNITE-752 * @return */ - public int getFailureDetectionThreshold() { + public long getFailureDetectionThreshold() { return failureDetectionThreshold; } @@ -1647,7 +1647,7 @@ public class IgniteConfiguration { * TODO: IGNITE-752 * @param failureDetectionThreshold */ - public void setFailureDetectionThreshold(int failureDetectionThreshold) { + public void setFailureDetectionThreshold(long failureDetectionThreshold) { this.failureDetectionThreshold = failureDetectionThreshold; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fc818c0/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiOperationTimeoutController.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiOperationTimeoutController.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiOperationTimeoutController.java index ba95871..84ffd0f 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiOperationTimeoutController.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiOperationTimeoutController.java @@ -48,7 +48,7 @@ public class IgniteSpiOperationTimeoutController { failureDetectionThreshold = adapter.failureDetectionThreshold(); assert !failureDetectionThresholdEnabled || failureDetectionThreshold > 0 : " [failureDetectionThreshold=" + - failureDetectionThreshold + ", thresholdEnabled=" + failureDetectionThresholdEnabled + ']'; + failureDetectionThreshold + ", thresholdEnabled=" + failureDetectionThresholdEnabled; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fc818c0/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java index 5be7ab9..eb131b5 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java @@ -1562,27 +1562,31 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T @Override public void spiStart(@Nullable String gridName) throws IgniteSpiException { initFailureDetectionThreshold(); - if (!failureDetectionThresholdEnabled()) { - if (!forceSrvMode && (Boolean.TRUE.equals(ignite.configuration().isClientMode()))) { + if (!forceSrvMode && (Boolean.TRUE.equals(ignite.configuration().isClientMode()))) { + if (!failureDetectionThresholdEnabled()) { if (ackTimeout == 0) ackTimeout = DFLT_ACK_TIMEOUT_CLIENT; if (sockTimeout == 0) sockTimeout = DFLT_SOCK_TIMEOUT_CLIENT; + } - impl = new ClientImpl(this); + impl = new ClientImpl(this); - ctxInitLatch.countDown(); - } else { + ctxInitLatch.countDown(); + } else { + if (!failureDetectionThresholdEnabled()) { if (ackTimeout == 0) ackTimeout = DFLT_ACK_TIMEOUT; if (sockTimeout == 0) sockTimeout = DFLT_SOCK_TIMEOUT; - - impl = new ServerImpl(this); } + impl = new ServerImpl(this); + } + + if (!failureDetectionThresholdEnabled()) { assertParameter(netTimeout > 0, "networkTimeout > 0"); assertParameter(sockTimeout > 0, "sockTimeout > 0"); assertParameter(ackTimeout > 0, "ackTimeout > 0"); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fc818c0/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiFailureThresholdSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiFailureThresholdSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiFailureThresholdSelfTest.java new file mode 100644 index 0000000..db0d9c5 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiFailureThresholdSelfTest.java @@ -0,0 +1,215 @@ +/* + * 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.spi.discovery.tcp; + +import org.apache.ignite.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.*; +import org.apache.ignite.spi.discovery.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.spi.discovery.tcp.messages.*; + +import java.io.*; +import java.net.*; + +/** + * + */ +public class TcpDiscoverySpiFailureThresholdSelfTest extends AbstractDiscoverySelfTest { + /** */ + private static TestTcpDiscoverySpi firstSpi; + + /** */ + private static TestTcpDiscoverySpi secondSpi; + + /** */ + private TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected DiscoverySpi getSpi(int idx) { + TestTcpDiscoverySpi spi = new TestTcpDiscoverySpi(); + + if (idx == 0) + firstSpi = spi; + else + secondSpi = spi; + + spi.setMetricsProvider(createMetricsProvider()); + spi.setIpFinder(ipFinder); + + return spi; + } + + /** + * @throws Exception In case of error. + */ + public void testFailureDetectionThresholdEnabled() throws Exception { + assertTrue(firstSpi.failureDetectionThresholdEnabled()); + assertTrue(secondSpi.failureDetectionThresholdEnabled()); + + assertEquals(IgniteConfiguration.DFLT_FAILURE_DETECTION_THRESHOLD, firstSpi.failureDetectionThreshold()); + assertEquals(IgniteConfiguration.DFLT_FAILURE_DETECTION_THRESHOLD, secondSpi.failureDetectionThreshold()); + } + + /** + * @throws Exception In case of error. + */ + public void testFailureDetectionOnSocketOpen() throws Exception { + try { + ClusterNode node = secondSpi.getLocalNode(); + + firstSpi.openSocketTimeout = true; + + assertFalse(firstSpi.pingNode(node.id())); + assertTrue(firstSpi.validTimeout); + assertTrue(firstSpi.err.getMessage().equals("Timeout: openSocketTimeout")); + + firstSpi.openSocketTimeout = false; + firstSpi.openSocketTimeoutWait = true; + + assertFalse(firstSpi.pingNode(node.id())); + assertTrue(firstSpi.validTimeout); + assertTrue(firstSpi.err.getMessage().equals("Timeout: openSocketTimeoutWait")); + } + finally { + firstSpi.resetState(); + } + } + + + /** + * @throws Exception In case of error. + */ + public void testFailureDetectionOnSocketWrite() throws Exception { + try { + ClusterNode node = secondSpi.getLocalNode(); + + firstSpi.writeToSocketTimeoutWait = true; + + assertFalse(firstSpi.pingNode(node.id())); + assertTrue(firstSpi.validTimeout); + + firstSpi.writeToSocketTimeoutWait = false; + + assertTrue(firstSpi.pingNode(node.id())); + assertTrue(firstSpi.validTimeout); + } + finally { + firstSpi.resetState(); + } + } + + /** + * + */ + private static class TestTcpDiscoverySpi extends TcpDiscoverySpi { + /** */ + private boolean openSocketTimeout; + + /** */ + private boolean openSocketTimeoutWait; + + /** */ + private boolean writeToSocketTimeoutWait; + + /** */ + private boolean validTimeout = true; + + /** */ + private IgniteSpiOperationTimeoutException err; + + + /** {@inheritDoc} */ + @Override protected Socket openSocket(InetSocketAddress sockAddr, + IgniteSpiOperationTimeoutController timeoutCtrl) throws IOException, IgniteSpiOperationTimeoutException { + + if (openSocketTimeout) { + err = new IgniteSpiOperationTimeoutException("Timeout: openSocketTimeout"); + throw err; + } + else if (openSocketTimeoutWait) { + long timeout = timeoutCtrl.nextTimeoutChunk(0); + + try { + Thread.sleep(timeout); + } + catch (InterruptedException e) { + // Ignore + } + + try { + timeoutCtrl.nextTimeoutChunk(0); + } + catch (IgniteSpiOperationTimeoutException e) { + err = new IgniteSpiOperationTimeoutException("Timeout: openSocketTimeoutWait"); + throw err; + } + } + + Socket sock = super.openSocket(sockAddr, timeoutCtrl); + + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + // Ignore + } + + return sock; + } + + /** {@inheritDoc} */ + @Override protected void writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, long timeout) + throws IOException, IgniteCheckedException { + if (!(msg instanceof TcpDiscoveryPingRequest)) { + super.writeToSocket(sock, msg, timeout); + return; + } + + if (timeout >= IgniteConfiguration.DFLT_FAILURE_DETECTION_THRESHOLD) { + validTimeout = false; + + throw new IgniteCheckedException("Invalid timeout: " + timeout); + } + + if (writeToSocketTimeoutWait) { + try { + Thread.sleep(timeout); + } + catch (InterruptedException e) { + // Ignore + } + } + else + super.writeToSocket(sock, msg, timeout); + } + + /** + * + */ + private void resetState() { + openSocketTimeout = false; + openSocketTimeoutWait = false; + writeToSocketTimeoutWait = false; + err = null; + validTimeout = true; + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fc818c0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java index 6f59f14..357fd93 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java @@ -44,6 +44,7 @@ public class IgniteSpiDiscoverySelfTestSuite extends TestSuite { suite.addTest(new TestSuite(TcpDiscoverySelfTest.class)); suite.addTest(new TestSuite(TcpDiscoverySpiSelfTest.class)); + suite.addTest(new TestSuite(TcpDiscoverySpiFailureThresholdSelfTest.class)); suite.addTest(new TestSuite(TcpDiscoverySpiStartStopSelfTest.class)); suite.addTest(new TestSuite(TcpDiscoverySpiConfigSelfTest.class)); suite.addTest(new TestSuite(TcpDiscoveryMarshallerCheckSelfTest.class));