You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by zh...@apache.org on 2021/12/20 18:28:59 UTC

[helix] branch master updated: Fix a string operation for custom health check and update test (#1924)

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

zhangmeng 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 40b39fe  Fix a string operation for custom health check and update test (#1924)
40b39fe is described below

commit 40b39fea0eb451f99547bc94e0744560b88956ef
Author: xyuanlu <xy...@gmail.com>
AuthorDate: Mon Dec 20 10:28:51 2021 -0800

    Fix a string operation for custom health check and update test (#1924)
---
 .../MaintenanceManagementService.java              |  4 ++--
 .../TestMaintenanceManagementService.java          | 24 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
index 082c54b..c70b9c0 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
@@ -548,9 +548,9 @@ public class MaintenanceManagementService {
         // "CUSTOM_PARTITION_HEALTH_FAILURE:PARTITION_INITIAL_STATE_FAIL:partition_name"
         // we want to keep the first 2 parts as failed test name.
         String[] checks = failedCheck.split(":", 3);
-        failedCheck = checks[0] + checks[1];
+        failedCheck = checks[0] + ":" + checks[1];
       }
-      // Helix own health check name wil be in this pattern "HELIX:INSTANCE_NOT_ALIVE",
+      // Helix own health check name will be in this pattern "HELIX:INSTANCE_NOT_ALIVE",
       // no need to preprocess.
       if (!_nonBlockingHealthChecks.contains(failedCheck)) {
         return false;
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java b/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
index b24ffa1..a911286 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/clusterMaintenanceService/TestMaintenanceManagementService.java
@@ -29,6 +29,7 @@ import java.util.Set;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.ConfigAccessor;
@@ -104,6 +105,7 @@ public class TestMaintenanceManagementService {
     }
   }
 
+
   @Test
   public void testGetInstanceStoppableCheckWhenHelixOwnCheckFail() throws IOException {
     Map<String, Boolean> failedCheck = ImmutableMap.of("FailCheck", false);
@@ -233,8 +235,28 @@ public class TestMaintenanceManagementService {
             false, HelixRestNamespace.DEFAULT_NAMESPACE_NAME);
     stoppableCheck = instanceServiceWithoutReadZK.getInstanceStoppableCheck(TEST_CLUSTER, TEST_INSTANCE, jsonContent);
     Assert.assertFalse(stoppableCheck.isStoppable());
+
+    // Test take instance with same setting.
+    MaintenanceManagementInstanceInfo instanceInfo =
+        instanceServiceWithoutReadZK.takeInstance(TEST_CLUSTER, TEST_INSTANCE, Collections.singletonList("CustomInstanceStoppableCheck"),
+            MaintenanceManagementService.getMapFromJsonPayload(jsonContent), Collections.singletonList("org.apache.helix.rest.server.TestOperationImpl"),
+            Collections.EMPTY_MAP, true);
+    Assert.assertFalse(instanceInfo.isSuccessful());
+    Assert.assertEquals(instanceInfo.getMessages().get(0), "CUSTOM_PARTITION_HEALTH_FAILURE:UNHEALTHY_PARTITION:PARTITION_0");
+
+    // Operation should finish even with check failed.
+    MockMaintenanceManagementService instanceServiceSkipFailure =
+        new MockMaintenanceManagementService(zkHelixDataAccessor, _configAccessor, _customRestClient, true,
+            ImmutableSet.of("CUSTOM_PARTITION_HEALTH_FAILURE:UNHEALTHY_PARTITION"), HelixRestNamespace.DEFAULT_NAMESPACE_NAME);
+    MaintenanceManagementInstanceInfo instanceInfo2 =
+        instanceServiceSkipFailure.takeInstance(TEST_CLUSTER, TEST_INSTANCE, Collections.singletonList("CustomInstanceStoppableCheck"),
+            MaintenanceManagementService.getMapFromJsonPayload(jsonContent), Collections.singletonList("org.apache.helix.rest.server.TestOperationImpl"),
+            Collections.EMPTY_MAP, true);
+    Assert.assertTrue(instanceInfo2.isSuccessful());
+    Assert.assertEquals(instanceInfo2.getOperationResult(), "DummyTakeOperationResult");
   }
-  /*
+
+    /*
    * Tests stoppable check api when all checks query is enabled. After helix own check fails,
    * the subsequent checks should be performed.
    */