ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-2688: reworked tests using GridStringLogger and removed 'stoppedAbnormally' variable that was used for tests only.
Date Wed, 20 Apr 2016 14:44:36 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2688 386b8f6aa -> b061a27ec


IGNITE-2688: reworked tests using GridStringLogger and removed 'stoppedAbnormally' variable
that was used for tests only.


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

Branch: refs/heads/ignite-2688
Commit: b061a27ec0432744b7283af4c35277e83e19e827
Parents: 386b8f6
Author: Denis Magda <dmagda@gridgain.com>
Authored: Wed Apr 20 17:44:27 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Wed Apr 20 17:44:27 2016 +0300

----------------------------------------------------------------------
 .../ignite/spi/discovery/tcp/ClientImpl.java    |  5 --
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 14 ----
 .../spi/discovery/tcp/TcpDiscoveryImpl.java     |  7 --
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java | 73 +++++++++-----------
 4 files changed, 31 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b061a27e/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
index c5caec2..31d614f 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
@@ -778,11 +778,6 @@ class ClientImpl extends TcpDiscoveryImpl {
         return msgWorker;
     }
 
-    /** {@inheritDoc} */
-    @Override protected Boolean workerThreadStoppedAbnormally() {
-        return false;
-    }
-
     /**
      * FOR TEST PURPOSE ONLY!
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b061a27e/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 8e01f04..529f866 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -1524,11 +1524,6 @@ class ServerImpl extends TcpDiscoveryImpl {
         return msgWorker;
     }
 
-    /** {@inheritDoc} */
-    @Override protected Boolean workerThreadStoppedAbnormally() {
-        return msgWorker.stoppedAbnormally;
-    }
-
     /**
      * <strong>FOR TEST ONLY!!!</strong>
      * <p>
@@ -2137,9 +2132,6 @@ class ServerImpl extends TcpDiscoveryImpl {
         /** Force pending messages send. */
         private boolean forceSndPending;
 
-        /** FOR TESTS ONLY. Used to check whether the worker has been stopped abnormally.
*/
-        private volatile Boolean stoppedAbnormally;
-
         /** Socket. */
         private Socket sock;
 
@@ -2185,16 +2177,12 @@ class ServerImpl extends TcpDiscoveryImpl {
         @Override protected void body() throws InterruptedException {
             try {
                 super.body();
-
-                stoppedAbnormally = false;
             }
             catch (Throwable e) {
                 if (!spi.isNodeStopping0() && spiStateCopy() != DISCONNECTING) {
                         final Ignite ignite = spi.ignite();
 
                     if (ignite != null) {
-                        stoppedAbnormally = true;
-
                         U.error(log, "TcpDiscoverSpi's message worker thread failed abnormally.
" +
                             "Stopping the node in order to prevent cluster wide instability.",
e);
 
@@ -2214,8 +2202,6 @@ class ServerImpl extends TcpDiscoveryImpl {
                         }, "node-stop-thread").start();
                     }
                 }
-                else
-                    stoppedAbnormally = false;
 
                 // Must be processed by IgniteSpiThread as well.
                 throw e;

http://git-wip-us.apache.org/repos/asf/ignite/blob/b061a27e/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
index 6dea491..1aef728 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
@@ -255,13 +255,6 @@ abstract class TcpDiscoveryImpl {
     protected abstract IgniteSpiThread workerThread();
 
     /**
-     * <strong>FOR TEST ONLY!!!</strong>
-     *
-     * @return {@code true} if the worker Thread has been stopped abnormally.
-     */
-    protected abstract Boolean workerThreadStoppedAbnormally();
-
-    /**
      * @throws IgniteSpiException If failed.
      */
     @SuppressWarnings("BusyWait")

http://git-wip-us.apache.org/repos/asf/ignite/blob/b061a27e/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 787e609..e46a2d7 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -43,6 +43,7 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteIllegalStateException;
+import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
@@ -77,6 +78,7 @@ import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedM
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage;
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage;
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage;
+import org.apache.ignite.testframework.GridStringLogger;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.eclipse.jetty.util.ConcurrentHashSet;
@@ -108,6 +110,8 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     /** */
     private static ThreadLocal<TcpDiscoverySpi> nodeSpi = new ThreadLocal<>();
 
+    private GridStringLogger strLogger;
+
     /**
      * @throws Exception If fails.
      */
@@ -188,11 +192,17 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
         }
         else if (gridName.contains("testPingInterruptedOnNodeFailedPingingNode"))
             cfg.setFailureDetectionTimeout(30_000);
-        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureNormalNode"))
+        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureNormalNode")) {
             cfg.setFailureDetectionTimeout(3_000);
-        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureSegmentedNode"))
+        }
+        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureSegmentedNode"))
{
             cfg.setFailureDetectionTimeout(6_000);
 
+            cfg.setGridLogger(strLogger = new GridStringLogger());
+        }
+        else if (gridName.contains("testNodeShutdownOnRingMessageWorkerFailureFailedNode"))
+            cfg.setGridLogger(strLogger = new GridStringLogger());
+
         return cfg;
     }
 
@@ -1364,7 +1374,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
 
             nodeSpi.set(spi0);
 
-            final Ignite ignite0 = startGrid(0);
+            final Ignite ignite0 = startGrid("testNodeShutdownOnRingMessageWorkerFailureFailedNode");
 
             nodeSpi.set(new TcpDiscoverySpi());
 
@@ -1379,10 +1389,11 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             ignite1.events().localListen(new IgnitePredicate<Event>() {
                 @Override public boolean apply(Event evt) {
                     if (evt.type() == EventType.EVT_NODE_FAILED &&
-                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id())) {
                         disconnected.set(true);
 
-                    latch.countDown();
+                        latch.countDown();
+                    }
 
                     return false;
                 }
@@ -1394,17 +1405,9 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
 
             assertTrue(disconnected.get());
 
-            GridTestUtils.waitForCondition(new GridAbsPredicate() {
-                @Override public boolean apply() {
-                    Boolean stoppedAbnormally = spi0.stoppedAbnormally();
-
-                    return stoppedAbnormally != null && stoppedAbnormally;
-                }
-            }, 10_000);
+            String result = strLogger.toString();
 
-            Boolean stoppedAbnormally = spi0.stoppedAbnormally();
-
-            assertTrue(stoppedAbnormally != null && stoppedAbnormally);
+            assert result.contains("TcpDiscoverSpi's message worker thread failed abnormally")
: result;
         }
         finally {
             stopAllGrids();
@@ -1424,9 +1427,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             Ignite ignite1 = startGrid("testNoRingMessageWorkerAbnormalFailureNormalNode");
 
 
-            final TestMessageWorkerFailureSpi3 spi2 = new TestMessageWorkerFailureSpi3();
-
-            nodeSpi.set(spi2);
+            nodeSpi.set(new TcpDiscoverySpi());
 
             final Ignite ignite2 = startGrid("testNoRingMessageWorkerAbnormalFailureSegmentedNode");
 
@@ -1455,13 +1456,16 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
 
             ignite2.events().localListen(new IgnitePredicate<Event>() {
                 @Override public boolean apply(Event evt) {
-                    if (evt.type() == EventType.EVT_NODE_SEGMENTED &&
-                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                    if (!failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                        return true;
+
+                    if (evt.type() == EventType.EVT_NODE_SEGMENTED) {
                         segmented.set(true);
 
-                    segLatch.countDown();
+                        segLatch.countDown();
+                    }
 
-                    return false;
+                    return true;
                 }
             }, EventType.EVT_NODE_SEGMENTED);
 
@@ -1480,17 +1484,13 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             assertTrue(segmented.get());
 
 
-            GridTestUtils.waitForCondition(new GridAbsPredicate() {
-                @Override public boolean apply() {
-                    Boolean stoppedAbnormally = spi2.stoppedAbnormally();
+            Thread.sleep(10_000);
 
-                    return stoppedAbnormally != null && !stoppedAbnormally;
-                }
-            }, 10_000);
 
-            Boolean stoppedAbnormally = spi2.stoppedAbnormally();
+            String result = strLogger.toString();
 
-            assertTrue(stoppedAbnormally != null && !stoppedAbnormally);
+            assert result.contains("Local node SEGMENTED") &&
+                !result.contains("TcpDiscoverSpi's message worker thread failed abnormally")
: result;
         }
         finally {
             stopAllGrids();
@@ -2163,7 +2163,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     /**
      *
      */
-    private static class TestMessageWorkerFailureSpi1 extends TestMessageWorkerFailureSpi3
{
+    private static class TestMessageWorkerFailureSpi1 extends TcpDiscoverySpi {
         /** */
         private static int EXCEPTION_MODE = 0;
 
@@ -2225,17 +2225,6 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
         }
     }
 
-    private static class TestMessageWorkerFailureSpi3 extends TcpDiscoverySpi {
-        /**
-         * Checks if the worker thread has been stopped abnormally.
-         *
-         * @return {@code true} if the worker thread has been stopped abnormally.
-         */
-        Boolean stoppedAbnormally() {
-            return impl.workerThreadStoppedAbnormally();
-        }
-    }
-
     /**
      * Starts new grid with given index. Method optimize is not invoked.
      *


Mime
View raw message