You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by xy...@apache.org on 2023/05/22 23:19:55 UTC

[helix] branch master updated: Fixing the TestClusterStatusMonitorLifecyle integration test (#2489)

This is an automated email from the ASF dual-hosted git repository.

xyuanlu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 4760ba77c Fixing the TestClusterStatusMonitorLifecyle integration test (#2489)
4760ba77c is described below

commit 4760ba77c3a8c6e254c40780eba81fe6230682a0
Author: Naman Parakh <pa...@gmail.com>
AuthorDate: Mon May 22 16:19:49 2023 -0700

    Fixing the TestClusterStatusMonitorLifecyle integration test (#2489)
    
    Fixing the TestClusterStatusMonitorLifecyle integration test.
    ---------
    
    Co-authored-by: Naman Parakh <np...@linkedin.biz>
---
 .../apache/helix/manager/zk/ZKHelixManager.java    |  3 +-
 .../DistClusterControllerStateModel.java           |  2 +
 .../TestClusterStatusMonitorLifecycle.java         | 74 ++++++----------------
 3 files changed, 25 insertions(+), 54 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
index 65303b389..7a62d1923 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
@@ -793,13 +793,14 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
 
   @Override
   public void connect() throws Exception {
-    LOG.info("ClusterManager.connect()");
     if (isConnected()) {
       LOG.warn("Cluster manager: " + _instanceName + " for cluster: " + _clusterName
           + " already connected. skip connect");
       return;
     }
 
+    LOG.info("Connecting cluster manager: " + _instanceName + " of instance type: " + _instanceType
+        + " for cluster: " + _clusterName);
     switch (_instanceType) {
     case CONTROLLER:
     case CONTROLLER_PARTICIPANT:
diff --git a/helix-core/src/main/java/org/apache/helix/participant/DistClusterControllerStateModel.java b/helix-core/src/main/java/org/apache/helix/participant/DistClusterControllerStateModel.java
index 430f47f60..42f0e4b41 100644
--- a/helix-core/src/main/java/org/apache/helix/participant/DistClusterControllerStateModel.java
+++ b/helix-core/src/main/java/org/apache/helix/participant/DistClusterControllerStateModel.java
@@ -114,6 +114,8 @@ public class DistClusterControllerStateModel extends AbstractHelixLeaderStandbyS
   public void reset() {
     synchronized (_controllerOpt) {
       if (_controllerOpt.isPresent()) {
+        logger.info("Disconnecting controller: " + _controllerOpt.get().getInstanceName() + " for "
+            + _controllerOpt.get().getClusterName());
         _controllerOpt.get().disconnect();
         _controllerOpt = Optional.empty();
       }
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java b/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
index 8ef0bebd0..61b2f58bb 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
@@ -37,20 +37,12 @@ import org.apache.helix.model.IdealState;
 import org.apache.helix.tools.ClusterSetup;
 import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier;
 import org.apache.helix.tools.ClusterVerifiers.ZkHelixClusterVerifier;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import static org.apache.logging.log4j.Level.ERROR;
-import static org.apache.logging.log4j.Level.INFO;
-
 public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
-  public static final String HELIX_LOGGER_NAME = "org.apache.helix";
   MockParticipantManager[] _participants;
   ClusterDistributedController[] _controllers;
   String _controllerClusterName;
@@ -63,8 +55,6 @@ public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
 
   @BeforeClass
   public void beforeClass() throws Exception {
-    // enabling info level for helix logs to help with debugging
-    updateLog4jLevel(INFO, HELIX_LOGGER_NAME);
     String className = TestHelper.getTestClassName();
     _clusterNamePrefix = className;
 
@@ -101,7 +91,7 @@ public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
         "LeaderStandby", true); // do rebalance
 
     // start distributed cluster controllers
-    _controllers = new ClusterDistributedController[n + n];
+    _controllers = new ClusterDistributedController[n];
     for (int i = 0; i < n; i++) {
       _controllers[i] =
           new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i);
@@ -129,24 +119,6 @@ public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
         new BestPossibleExternalViewVerifier.Builder(_firstClusterName).setZkClient(_gZkClient)
             .setWaitTillVerify(TestHelper.DEFAULT_REBALANCE_PROCESSING_WAIT_TIME)
             .build();
-    Assert.assertTrue(firstClusterVerifier.verifyByPolling(), "first cluster NOT in ideal state");
-
-    // add more controllers to controller cluster
-    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
-    for (int i = 0; i < n; i++) {
-      String controller = "controller_" + (n + i);
-      setupTool.addInstanceToCluster(_controllerClusterName, controller);
-    }
-    setupTool.rebalanceStorageCluster(_controllerClusterName, _clusterNamePrefix + "0", 6);
-    for (int i = n; i < 2 * n; i++) {
-      _controllers[i] =
-          new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i);
-      _controllers[i].syncStart();
-    }
-
-    // verify controller cluster
-    Assert.assertTrue(controllerClusterVerifier.verifyByPolling(),
-        "Controller cluster NOT in ideal state");
 
     // verify first cluster
     Assert.assertTrue(firstClusterVerifier.verifyByPolling(), "first cluster NOT in ideal state");
@@ -164,17 +136,12 @@ public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
   @AfterClass
   public void afterClass() throws Exception {
     System.out.println("Cleaning up...");
-    for (int i = 0; i < 2 * n; i++) {
-      if (_controllers[i] != null) {
-        _controllers[i].syncStop();
-      }
-    }
+    cleanupControllers();
     for (MockParticipantManager participant : _participants) {
       if (participant != null) {
         participant.syncStop();
       }
     }
-    cleanupControllers();
     deleteCluster(_controllerClusterName);
 
     for (String cluster : _clusters) {
@@ -182,28 +149,29 @@ public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
     }
 
     System.out.println("END " + _clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
-    // restoring error level for helix logs
-    updateLog4jLevel(ERROR, HELIX_LOGGER_NAME);
-  }
-
-  private void cleanupControllers() {
-    for (ClusterDistributedController controller : _controllers) {
-      controller.syncStop();
-    }
   }
 
   /**
-   * Updates the log level for the specified logger.
-   * @param level Log level to update.
-   * @param loggerName Name of the logger for which the level will be updated.
+   * Disconnects all the controllers one by one.
+   * NOTE: Invoking this method multiple times won't disconnect the controllers multiple times.
    */
-  private void updateLog4jLevel(org.apache.logging.log4j.Level level, String loggerName) {
-    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
-    Configuration config = ctx.getConfiguration();
-    LoggerConfig loggerConfig =
-        config.getLoggerConfig(String.valueOf(LogManager.getLogger(loggerName)));
-    loggerConfig.setLevel(level);
-    ctx.updateLoggers();
+  private void cleanupControllers() {
+    for (int i = 0; i < n; i++) {
+      ClusterDistributedController controller = _controllers[i];
+      if (controller != null) {
+        ZkHelixClusterVerifier controllerClusterVerifier =
+            new BestPossibleExternalViewVerifier.Builder(controller.getClusterName()).setZkClient(
+                    _gZkClient).setWaitTillVerify(TestHelper.DEFAULT_REBALANCE_PROCESSING_WAIT_TIME)
+                .build();
+        Assert.assertTrue(controllerClusterVerifier.verifyByPolling(),
+            "Controller cluster NOT in ideal state");
+        System.out.println(String.format("Disconnecting controller %s from cluster %s at %s",
+            controller.getInstanceName(), controller.getClusterName(),
+            new Date(System.currentTimeMillis())));
+        controller.syncStop();
+        _controllers[i] = null;
+      }
+    }
   }
 
   @Test