helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject [2/3] git commit: Adding more testcases for flapping detection
Date Thu, 31 Jan 2013 01:27:29 GMT
Adding more testcases for flapping detection

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

Branch: refs/heads/master
Commit: 20fb700e685cdd916ddccb0a252ef490feeeab03
Parents: e690aff
Author: slu2011 <lushi04@gmail.com>
Authored: Wed Jan 30 17:25:57 2013 -0800
Committer: slu2011 <lushi04@gmail.com>
Committed: Wed Jan 30 17:25:57 2013 -0800

----------------------------------------------------------------------
 .../helix/controller/GenericHelixController.java   |    5 +
 .../test/java/org/apache/helix/ZkTestHelper.java   |   27 ++-
 .../helix/manager/zk/TestZkDisconnectHistory.java  |  109 ---------
 .../manager/zk/TestZkManagerFlappingDetection.java |  182 +++++++++++++++
 4 files changed, 212 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/20fb700e/helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
b/helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
index a439d19..ba22b63 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
@@ -497,6 +497,11 @@ public class GenericHelixController implements
   public void onControllerChange(NotificationContext changeContext)
   {
     logger.info("START: GenericClusterController.onControllerChange()");
+    if (changeContext!= null && changeContext.getType() == Type.FINALIZE)
+    {
+      logger.info("GenericClusterController.onControllerChange() FINALIZE");
+      return;
+    }
     HelixDataAccessor accessor = changeContext.getManager().getHelixDataAccessor();
 
     // double check if this controller is the leader

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/20fb700e/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java b/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
index 23f293b..f9bbc29 100644
--- a/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
+++ b/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
@@ -70,7 +70,29 @@ public class ZkTestHelper
   
   public static void disconnectSession(final ZkClient zkClient) throws Exception
   {
-    
+    IZkStateListener listener = new IZkStateListener()
+    {
+      @Override
+      public void handleStateChanged(KeeperState state) throws Exception
+      {
+//         System.err.println("disconnectSession handleStateChanged. state: " + state);
+      }
+
+      @Override
+      public void handleNewSession() throws Exception
+      {
+        // make sure zkclient is connected again
+        zkClient.waitUntilConnected();
+
+        ZkConnection connection = ((ZkConnection) zkClient.getConnection());
+        ZooKeeper curZookeeper = connection.getZookeeper();
+
+        LOG.info("handleNewSession. sessionId: "
+            + Long.toHexString(curZookeeper.getSessionId()));
+      }
+    };
+
+    zkClient.subscribeStateChanges(listener);
     ZkConnection connection = ((ZkConnection) zkClient.getConnection());
     ZooKeeper curZookeeper = connection.getZookeeper();
     LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
@@ -99,6 +121,7 @@ public class ZkTestHelper
 
     connection = (ZkConnection) zkClient.getConnection();
     curZookeeper = connection.getZookeeper();
+    zkClient.unsubscribeStateChanges(listener);
 
     // System.err.println("zk: " + oldZookeeper);
     LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
@@ -113,7 +136,7 @@ public class ZkTestHelper
       @Override
       public void handleStateChanged(KeeperState state) throws Exception
       {
-         System.err.println("handleStateChanged. state: " + state);
+//         System.err.println("handleStateChanged. state: " + state);
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/20fb700e/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkDisconnectHistory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkDisconnectHistory.java
b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkDisconnectHistory.java
deleted file mode 100644
index 6df52db..0000000
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkDisconnectHistory.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.helix.manager.zk;
-
-import org.apache.helix.InstanceType;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZkTestHelper;
-import org.apache.helix.ZkTestHelper.TestZkHelixManager;
-import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class TestZkDisconnectHistory extends ZkIntegrationTestBase
-{
-  @Test
-  public void testDisconnectHistory() throws Exception
-  {
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    final String clusterName = className + "_" + methodName;
-
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
-                            "localhost", // participant name prefix
-                            "TestDB", // resource name prefix
-                            1, // resources
-                            10, // partitions per resource
-                            5, // number of nodes
-                            3, // replicas
-                            "MasterSlave",
-                            true); // do rebalance
-    
-    
-      String instanceName = "localhost_" + (12918 + 0);
-      TestZkHelixManager manager =
-          new TestZkHelixManager(clusterName,
-                                 instanceName,
-                                 InstanceType.PARTICIPANT,
-                                 ZK_ADDR);
-      manager.connect();
-      ZkClient zkClient = manager.getZkClient();
-      ZkTestHelper.expireSession(zkClient);
-      for(int i = 0;i < 4; i++)
-      {
-        ZkTestHelper.expireSession(zkClient);
-        Thread.sleep(500);
-        if(i < 5)
-        {
-          Assert.assertTrue(manager.isConnected());
-        }
-      }
-      ZkTestHelper.disconnectSession(zkClient);
-      for(int i = 0; i < 20; i++)
-      {
-        Thread.sleep(500);
-        if(!manager.isConnected()) break;
-      }
-      Assert.assertFalse(manager.isConnected());
-  }
-  
-  @Test
-  public void testDisconnectFlappingWindow() throws Exception
-  {
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    final String clusterName = className + "_" + methodName;
-
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
-                            "localhost", // participant name prefix
-                            "TestDB", // resource name prefix
-                            1, // resources
-                            10, // partitions per resource
-                            5, // number of nodes
-                            3, // replicas
-                            "MasterSlave",
-                            true); // do rebalance
-    
-    
-      // flapping time window to 5 sec
-      System.setProperty("helixmanager.flappingTimeWindow", "10000");
-      String instanceName = "localhost_" + (12918 + 1);
-      TestZkHelixManager manager2 =
-          new TestZkHelixManager(clusterName,
-                                 instanceName,
-                                 InstanceType.PARTICIPANT,
-                                 ZK_ADDR);
-      manager2.connect();
-      ZkClient zkClient = manager2.getZkClient();
-      for(int i = 0;i < 3; i++)
-      {
-        ZkTestHelper.expireSession(zkClient);
-        Thread.sleep(500);
-        Assert.assertTrue(manager2.isConnected());
-      }
-      Thread.sleep(10000);
-      // Old entries should be cleaned up
-      for(int i = 0;i < 5; i++)
-      {
-        ZkTestHelper.expireSession(zkClient);
-        Thread.sleep(500);
-        Assert.assertTrue(manager2.isConnected());
-      }
-      ZkTestHelper.disconnectSession(zkClient);
-      for(int i = 0; i < 20; i++)
-      {
-        Thread.sleep(500);
-        if(!manager2.isConnected()) break;
-      }
-      Assert.assertFalse(manager2.isConnected());
-      
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/20fb700e/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
new file mode 100644
index 0000000..54c2414
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
@@ -0,0 +1,182 @@
+package org.apache.helix.manager.zk;
+
+import java.util.UUID;
+
+import org.apache.helix.InstanceType;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkTestHelper;
+import org.apache.helix.ZkTestHelper.TestZkHelixManager;
+import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase
+{
+  @Test
+  public void testDisconnectHistory() throws Exception
+  {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    final String clusterName = className + "_" + methodName;
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+                            "localhost", // participant name prefix
+                            "TestDB", // resource name prefix
+                            1, // resources
+                            10, // partitions per resource
+                            5, // number of nodes
+                            3, // replicas
+                            "MasterSlave",
+                            true); // do rebalance
+    
+    
+      String instanceName = "localhost_" + (12918 + 0);
+      TestZkHelixManager manager =
+          new TestZkHelixManager(clusterName,
+                                 instanceName,
+                                 InstanceType.PARTICIPANT,
+                                 ZK_ADDR);
+      manager.connect();
+      ZkClient zkClient = manager.getZkClient();
+      ZkTestHelper.expireSession(zkClient);
+      for(int i = 0;i < 4; i++)
+      {
+        ZkTestHelper.expireSession(zkClient);
+        Thread.sleep(500);
+        if(i < 5)
+        {
+          Assert.assertTrue(manager.isConnected());
+        }
+      }
+      ZkTestHelper.disconnectSession(zkClient);
+      for(int i = 0; i < 20; i++)
+      {
+        Thread.sleep(500);
+        if(!manager.isConnected()) break;
+      }
+      Assert.assertFalse(manager.isConnected());
+  }
+  
+  @Test
+  public void testDisconnectFlappingWindow() throws Exception
+  {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String instanceName = "localhost_" + (12918 + 1);
+    final String clusterName = className + "_" + methodName + UUID.randomUUID();
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+                            "localhost", // participant name prefix
+                            "TestDB", // resource name prefix
+                            1, // resources
+                            10, // partitions per resource
+                            5, // number of nodes
+                            3, // replicas
+                            "MasterSlave",
+                            true); // do rebalance
+    testDisconnectFlappingWindow2(instanceName, InstanceType.PARTICIPANT);
+    testDisconnectFlappingWindow2("admin", InstanceType.ADMINISTRATOR);
+  }
+  
+  public void testDisconnectFlappingWindow2(String instanceName, InstanceType type) throws
Exception
+  {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    final String clusterName = className + "_" + methodName + UUID.randomUUID();
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+                            "localhost", // participant name prefix
+                            "TestDB", // resource name prefix
+                            1, // resources
+                            10, // partitions per resource
+                            5, // number of nodes
+                            3, // replicas
+                            "MasterSlave",
+                            true); // do rebalance
+    
+    
+      // flapping time window to 5 sec
+      System.setProperty("helixmanager.flappingTimeWindow", "10000");
+      System.setProperty("helixmanager.maxDisconnectThreshold", "7");
+      TestZkHelixManager manager2 =
+          new TestZkHelixManager(clusterName,
+                                 instanceName,
+                                 type,
+                                 ZK_ADDR);
+      manager2.connect();
+      ZkClient zkClient = manager2.getZkClient();
+      for(int i = 0;i < 3; i++)
+      {
+        ZkTestHelper.expireSession(zkClient);
+        Thread.sleep(500);
+        Assert.assertTrue(manager2.isConnected());
+      }
+      Thread.sleep(10000);
+      // Old entries should be cleaned up
+      for(int i = 0;i < 7; i++)
+      {
+        ZkTestHelper.expireSession(zkClient);
+        Thread.sleep(500);
+        Assert.assertTrue(manager2.isConnected());
+      }
+      ZkTestHelper.disconnectSession(zkClient);
+      for(int i = 0; i < 20; i++)
+      {
+        Thread.sleep(500);
+        if(!manager2.isConnected()) break;
+      }
+      Assert.assertFalse(manager2.isConnected());
+  }
+  
+  //@Test
+  public void testDisconnectFlappingWindowController() throws Exception
+  {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    final String clusterName = className + "_" + methodName;
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+                            "localhost", // participant name prefix
+                            "TestDB", // resource name prefix
+                            1, // resources
+                            10, // partitions per resource
+                            5, // number of nodes
+                            3, // replicas
+                            "MasterSlave",
+                            true); // do rebalance
+    
+    
+      // flapping time window to 5 sec
+      System.setProperty("helixmanager.flappingTimeWindow", "5000");
+      System.setProperty("helixmanager.maxDisconnectThreshold", "3");
+      TestZkHelixManager manager2 =
+          new TestZkHelixManager(clusterName,
+                                 null,
+                                 InstanceType.CONTROLLER,
+                                 ZK_ADDR);
+      manager2.connect();
+      Thread.sleep(100);
+      ZkClient zkClient = manager2.getZkClient();
+      for(int i = 0;i < 2; i++)
+      {
+        ZkTestHelper.expireSession(zkClient);
+        Thread.sleep(500);
+        Assert.assertTrue(manager2.isConnected());
+      }
+      Thread.sleep(5000);
+      // Old entries should be cleaned up
+      for(int i = 0;i < 3; i++)
+      {
+        ZkTestHelper.expireSession(zkClient);
+        Thread.sleep(500);
+        Assert.assertTrue(manager2.isConnected());
+      }
+      ZkTestHelper.disconnectSession(zkClient);
+      for(int i = 0; i < 20; i++)
+      {
+        Thread.sleep(500);
+        if(!manager2.isConnected()) break;
+      }
+      Assert.assertFalse(manager2.isConnected());
+  }
+}


Mime
View raw message