ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [4/6] incubator-ignite git commit: # Refactoring TcpDiscoverySelfTest: replace TcpDiscovery.onBeforeMessageSentAcrossRing() with listeners.
Date Wed, 06 May 2015 13:23:31 GMT
# Refactoring TcpDiscoverySelfTest: replace TcpDiscovery.onBeforeMessageSentAcrossRing() with
listeners.


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

Branch: refs/heads/ignite-836_2
Commit: bd7ae302a11ddfe145ce85dd1fecc4403e5d2dc5
Parents: acb9f1c
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Wed May 6 16:14:06 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed May 6 16:14:20 2015 +0300

----------------------------------------------------------------------
 .../spi/discovery/tcp/TcpDiscoverySpi.java      | 22 ++++---
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java | 65 +++++++-------------
 2 files changed, 38 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd7ae302/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 add83b3..46d90b5 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
@@ -288,6 +288,10 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
     @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
     private ConcurrentLinkedDeque<String> debugLog;
 
+    /** */
+    private final CopyOnWriteArrayList<IgniteInClosure<TcpDiscoveryAbstractMessage>>
sendMsgLsnrs =
+        new CopyOnWriteArrayList<>();
+
     /** {@inheritDoc} */
     @IgniteInstanceResource
     @Override public void injectResources(Ignite ignite) {
@@ -2064,13 +2068,16 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
 
     /**
      * <strong>FOR TEST ONLY!!!</strong>
-     * <p>
-     * This method is intended for test purposes only.
-     *
-     * @param msg Message.
      */
-    void onBeforeMessageSentAcrossRing(Serializable msg) {
-        // No-op.
+    public void addSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage>
msg) {
+        sendMsgLsnrs.add(msg);
+    }
+
+    /**
+     * <strong>FOR TEST ONLY!!!</strong>
+     */
+    public void removeSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage>
msg) {
+        sendMsgLsnrs.remove(msg);
     }
 
     /**
@@ -2679,7 +2686,8 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
 
             assert ring.hasRemoteNodes();
 
-            onBeforeMessageSentAcrossRing(msg);
+            for (IgniteInClosure<TcpDiscoveryAbstractMessage> msgLsnr : sendMsgLsnrs)
+                msgLsnr.apply(msg);
 
             if (redirectToClients(msg)) {
                 for (ClientMessageWorker clientMsgWorker : clientMsgWorkers.values())

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd7ae302/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 7bea1eb..5648c31 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
@@ -70,14 +70,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        TcpDiscoverySpi spi;
-
-        if (gridName.contains("FailBeforeNodeAddedSentSpi"))
-            spi = new FailBeforeNodeAddedSentSpi();
-        else if (gridName.contains("FailBeforeNodeLeftSentSpi"))
-            spi = new FailBeforeNodeLeftSentSpi();
-        else
-            spi = new TcpDiscoverySpi();
+        TcpDiscoverySpi spi = new TcpDiscoverySpi();
 
         discoMap.put(gridName, spi);
 
@@ -600,7 +593,17 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
                 }
             }, EVT_NODE_JOINED, EVT_NODE_FAILED);
 
-            startGrid("FailBeforeNodeAddedSentSpi");
+            final Ignite g = startGrid("FailBeforeNodeAddedSentSpi");
+
+            discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>()
{
+                @Override public void apply(TcpDiscoveryAbstractMessage msg) {
+                    if (msg instanceof TcpDiscoveryNodeAddedMessage) {
+                        discoMap.get(g.name()).simulateNodeFailure();
+
+                        throw new RuntimeException("Avoid message sending: " + msg.getClass());
+                    }
+                }
+            });
 
             startGrid(3);
 
@@ -620,7 +623,17 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             startGrid(1);
             startGrid(2);
 
-            startGrid("FailBeforeNodeLeftSentSpi");
+            final Ignite g = startGrid("FailBeforeNodeLeftSentSpi");
+
+            discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>()
{
+                @Override public void apply(TcpDiscoveryAbstractMessage msg) {
+                    if (msg instanceof TcpDiscoveryNodeLeftMessage) {
+                        discoMap.get(g.name()).simulateNodeFailure();
+
+                        throw new RuntimeException("Avoid message sending: " + msg.getClass());
+                    }
+                }
+            });
 
             Ignite g3 = startGrid(3);
 
@@ -954,36 +967,4 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     private Ignite startGridNoOptimize(String gridName) throws Exception {
         return G.start(getConfiguration(gridName));
     }
-
-    /**
-     *
-     */
-    private static class FailBeforeNodeAddedSentSpi extends TcpDiscoverySpi {
-        /** */
-        private int i;
-
-        /** {@inheritDoc} */
-        @Override void onBeforeMessageSentAcrossRing(Serializable msg) {
-            if (msg instanceof TcpDiscoveryNodeAddedMessage)
-                if (++i == 2) {
-                    simulateNodeFailure();
-
-                    throw new RuntimeException("Avoid message sending: " + msg.getClass());
-                }
-        }
-    }
-
-    /**
-     *
-     */
-    private static class FailBeforeNodeLeftSentSpi extends TcpDiscoverySpi {
-        /** {@inheritDoc} */
-        @Override void onBeforeMessageSentAcrossRing(Serializable msg) {
-            if (msg instanceof TcpDiscoveryNodeLeftMessage) {
-                simulateNodeFailure();
-
-                throw new RuntimeException("Avoid message sending: " + msg.getClass());
-            }
-        }
-    }
 }


Mime
View raw message