ChenSammi commented on code in PR #8150:
URL: https://github.com/apache/ozone/pull/8150#discussion_r2024514219
##########
hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestDiskBalancerSubCommand.java:
##########
@@ -192,6 +198,51 @@ public void testDiskBalancerStopSubcommand() throws
IOException {
stopCmd.setAllHosts(false);
}
+ public static Stream<Arguments> values() {
+ return Stream.of(
+ Arguments.arguments(0L, 0L, 0L, 0L, 0L), // bytesMovedMB = 0,
bytesToMoveMB = 0, estimatedTimeLeft = 0
+ Arguments.arguments(512L, 512L, 1L, 1L, 1L), // bytesMoved and
bytesToMove < 1MB should be rounded up to 1MB
+ Arguments.arguments(5242880L, 10485760L, 5L, 10L, 1L), // bytesMoved =
5MB, bytesToMove = 10MB, estTimeLeft = 1
+ Arguments.arguments(13774139392L, 3229900800L, 13137L, 3081L, 6L),
+ Arguments.arguments(7482638336L, 939524096L, 7136L, 896L, 6L)
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("values")
+ public void testDiskBalancerStatusCalculations(long bytesMoved, long
bytesToMove, long bytesMovedMB,
+ long bytesToMoveMB, long estTimeLeft) throws IOException {
+ ScmClient scmClient = mock(ScmClient.class);
+
+ HddsProtos.DatanodeDiskBalancerInfoProto proto =
+ HddsProtos.DatanodeDiskBalancerInfoProto.newBuilder()
+ .setNode(generateDatanodeDetails())
+ .setCurrentVolumeDensitySum(random.nextDouble())
+ .setRunningStatus(HddsProtos.DiskBalancerRunningStatus.
+ valueOf(random.nextInt(2) + 1))
+ .setBytesMoved(bytesMoved)
+ .setBytesToMove(bytesToMove)
+ .setDiskBalancerConf(
+ HddsProtos.DiskBalancerConfigurationProto.newBuilder()
+ .setDiskBandwidthInMB(10)
+ .setThreshold(10.0)
+ .setParallelThread(5)
+ .build())
+ .build();
+
+ List<HddsProtos.DatanodeDiskBalancerInfoProto> resultList =
Collections.singletonList(proto);
+ Mockito.when(scmClient.getDiskBalancerStatus(Mockito.any(),
Mockito.any())).thenReturn(resultList);
+
+ DiskBalancerStatusSubcommand statusCmd1 = new
DiskBalancerStatusSubcommand();
+ statusCmd1.execute(scmClient);
+
+ String output = outContent.toString(DEFAULT_ENCODING).trim();
+
+ // Check if expected values appear in output
+ assertTrue(output.contains(String.valueOf(bytesMovedMB)));
Review Comment:
Please separate the output to sub strings, and directly compare the matched
column with this expected value. The current contains check is not accurate.
For example, the last 6L is wrong. But the assert just passed.
Arguments.arguments(7482638336L, 939524096L, 7136L, 896L, 6L)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]