ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [4/4] incubator-ignite git commit: ignite-752: added tests
Date Thu, 16 Jul 2015 13:23:00 GMT
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 <dmagda@gridgain.com>
Authored: Thu Jul 16 16:22:45 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
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));


Mime
View raw message