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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3628aedb38 HDDS-3849. Add tests for show rule status of scm safemode 
(#6027)
3628aedb38 is described below

commit 3628aedb38a247e4938a69caa16ac8946c672d35
Author: Sadanand Shenoy <[email protected]>
AuthorDate: Fri Jan 19 00:32:39 2024 +0530

    HDDS-3849. Add tests for show rule status of scm safemode (#6027)
---
 .../hdds/scm/safemode/TestSCMSafeModeManager.java  | 30 +++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSCMSafeModeManager.java
 
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSCMSafeModeManager.java
index 79adf009f0..4f08462342 100644
--- 
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSCMSafeModeManager.java
+++ 
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSCMSafeModeManager.java
@@ -25,10 +25,13 @@ import java.time.ZoneOffset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdds.HddsConfigKeys;
 import org.apache.hadoop.hdds.client.RatisReplicationConfig;
@@ -135,6 +138,7 @@ public class TestSCMSafeModeManager {
         serviceManager, scmContext);
 
     assertTrue(scmSafeModeManager.getInSafeMode());
+    validateRuleStatus("DatanodeSafeModeRule", "registered datanodes 0");
     queue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT,
         HddsTestUtils.createNodeRegistrationContainerReport(containers));
 
@@ -176,7 +180,8 @@ public class TestSCMSafeModeManager {
         .getNumContainerWithOneReplicaReportedThreshold().value());
 
     assertTrue(scmSafeModeManager.getInSafeMode());
-
+    validateRuleStatus("ContainerSafeModeRule",
+        "% of containers with at least one reported");
     testContainerThreshold(containers.subList(0, 25), 0.25);
     assertEquals(25, scmSafeModeManager.getSafeModeMetrics()
         .getCurrentContainersWithOneReplicaReportedCount().value());
@@ -316,6 +321,13 @@ public class TestSCMSafeModeManager {
         scmContext);
 
     assertTrue(scmSafeModeManager.getInSafeMode());
+    if (healthyPipelinePercent > 0) {
+      validateRuleStatus("HealthyPipelineSafeModeRule",
+          "healthy Ratis/THREE pipelines");
+    }
+    validateRuleStatus("OneReplicaPipelineSafeModeRule",
+        "reported Ratis/THREE pipelines with at least one datanode");
+
     testContainerThreshold(containers, 1.0);
 
     List<Pipeline> pipelines = pipelineManager.getPipelines();
@@ -374,6 +386,22 @@ public class TestSCMSafeModeManager {
         100, 1000 * 5);
   }
 
+  /**
+   * @param safeModeRule verify that this rule is not satisfied
+   * @param stringToMatch string to match in the rule status.
+   */
+  private void validateRuleStatus(String safeModeRule, String stringToMatch) {
+    Set<Map.Entry<String, Pair<Boolean, String>>> ruleStatuses =
+        scmSafeModeManager.getRuleStatus().entrySet();
+    for (Map.Entry<String, Pair<Boolean, String>> entry : ruleStatuses) {
+      if (entry.getKey().equals(safeModeRule)) {
+        Pair<Boolean, String> value = entry.getValue();
+        assertEquals(false, value.getLeft());
+        assertTrue(value.getRight().contains(stringToMatch));
+      }
+    }
+  }
+
   private void checkHealthy(int expectedCount) throws Exception {
     GenericTestUtils.waitFor(() -> scmSafeModeManager
             .getHealthyPipelineSafeModeRule()


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to