Skip to content

Commit

Permalink
HDDS-6776. Cleanup TestSCMSafeModeManager (apache#7272)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryteng9527 authored Oct 5, 2024
1 parent 4bee3e9 commit 1f1e618
Showing 1 changed file with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.HddsConfigKeys;
Expand Down Expand Up @@ -63,7 +64,10 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -108,13 +112,10 @@ public void destroyDbStore() throws Exception {
}
}

@Test
public void testSafeModeState() throws Exception {
// Test 1: test for 0 containers
testSafeMode(0);

// Test 2: test for 20 containers
testSafeMode(20);
@ParameterizedTest
@ValueSource(ints = {0, 20})
public void testSafeModeState(int numContainers) throws Exception {
testSafeMode(numContainers);
}

@Test
Expand Down Expand Up @@ -215,36 +216,6 @@ private OzoneConfiguration createConf(double healthyPercent,
return conf;
}

@Test
public void testSafeModeExitRuleWithPipelineAvailabilityCheck1()
throws Exception {
testSafeModeExitRuleWithPipelineAvailabilityCheck(100, 30, 8, 0.90, 1);
}

@Test
public void testSafeModeExitRuleWithPipelineAvailabilityCheck2()
throws Exception {
testSafeModeExitRuleWithPipelineAvailabilityCheck(100, 90, 22, 0.10, 0.9);
}

@Test
public void testSafeModeExitRuleWithPipelineAvailabilityCheck3()
throws Exception {
testSafeModeExitRuleWithPipelineAvailabilityCheck(100, 30, 8, 0, 0.9);
}

@Test
public void testSafeModeExitRuleWithPipelineAvailabilityCheck4()
throws Exception {
testSafeModeExitRuleWithPipelineAvailabilityCheck(100, 90, 22, 0, 0);
}

@Test
public void testSafeModeExitRuleWithPipelineAvailabilityCheck5()
throws Exception {
testSafeModeExitRuleWithPipelineAvailabilityCheck(100, 90, 22, 0, 0.5);
}

@ParameterizedTest
@CsvSource(value = {"100,0.9,false", "0.9,200,false", "0.9,0.1,true"})
public void testHealthyPipelinePercentWithIncorrectValue(double healthyPercent,
Expand All @@ -269,6 +240,18 @@ public void testHealthyPipelinePercentWithIncorrectValue(double healthyPercent,
assertThat(exception).hasMessageEndingWith("value should be >= 0.0 and <= 1.0");
}

private static Stream<Arguments> testCaseForSafeModeExitRuleWithPipelineAvailabilityCheck() {
return Stream.of(
Arguments.of(100, 30, 8, 0.90, 1),
Arguments.of(100, 90, 22, 0.10, 0.9),
Arguments.of(100, 30, 8, 0, 0.9),
Arguments.of(100, 90, 22, 0, 0),
Arguments.of(100, 90, 22, 0, 0.5)
);
}

@ParameterizedTest
@MethodSource("testCaseForSafeModeExitRuleWithPipelineAvailabilityCheck")
public void testSafeModeExitRuleWithPipelineAvailabilityCheck(
int containerCount, int nodeCount, int pipelineCount,
double healthyPipelinePercent, double oneReplicaPercent)
Expand Down Expand Up @@ -455,12 +438,11 @@ public void testDisableSafeMode() {
assertFalse(scmSafeModeManager.getInSafeMode());
}

@Test
public void testSafeModeDataNodeExitRule() throws Exception {
@ParameterizedTest
@ValueSource(ints = {0, 3, 5})
public void testSafeModeDataNodeExitRule(int numberOfDns) throws Exception {
containers = new ArrayList<>();
testSafeModeDataNodes(0);
testSafeModeDataNodes(3);
testSafeModeDataNodes(5);
testSafeModeDataNodes(numberOfDns);
}

/**
Expand Down

0 comments on commit 1f1e618

Please sign in to comment.