ChenSammi commented on code in PR #8056:
URL: https://github.com/apache/ozone/pull/8056#discussion_r1995215802
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerService.java:
##########
@@ -170,6 +180,86 @@ private DiskBalancerServiceTestImpl getDiskBalancerService(
threadCount);
}
+ static List<Integer> createVolumeSet() {
+ List<Integer> params = new ArrayList<>();
+ for (int i = 0; i < 4; i++) {
+ params.add(i);
+ }
+ return params;
+ }
+
+ @ParameterizedTest
+ @MethodSource("createVolumeSet")
+ public void testCalculateBytesToMove(Integer i) throws IOException {
+ try {
+ conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY,
+ generateVolumeLocation(testRoot.getAbsolutePath(), i));
+ volumeSet = new MutableVolumeSet(datanodeUuid, scmId, conf, null,
+ StorageVolume.VolumeType.DATA_VOLUME, null);
+ createDbInstancesForTestIfNeeded(volumeSet, scmId, scmId, conf);
+
+ double num1 = 0.02;
+ List<StorageVolume> volumes = new ArrayList<>();
+
+ for (StorageVolume volume : volumeSet.getVolumesList()) {
+ volume.incrementUsedSpace((long)
(volume.getCurrentUsage().getCapacity() * num1));
+ volumes.add(volume);
+ num1 = 0.8;
+ }
+
+ ContainerSet containerSet = new ContainerSet(1000);
+ ContainerMetrics metrics = ContainerMetrics.create(conf);
+ KeyValueHandler keyValueHandler =
+ new KeyValueHandler(conf, datanodeUuid, containerSet, volumeSet,
+ metrics, c -> {
+ });
+ DiskBalancerServiceTestImpl svc =
+ getDiskBalancerService(containerSet, conf, keyValueHandler, null, 1);
+ svc.setShouldRun(true);
+ svc.setThreshold(10);
+ svc.setQueueSize(2);
+
+ long expectedBytesToMove = calculateExpectedBytesToMove(volumes,
svc.getDiskBalancerInfo().getThreshold());
+
+ assertEquals(expectedBytesToMove, svc.getBytesToMove(),
+ "The calculated bytes to move should match the expected reduction to
meet the threshold.");
+ } catch (DiskChecker.DiskOutOfSpaceException e) {
+ assertEquals(0, i, "No storage locations configured");
+ }
+ }
+
+ private long calculateExpectedBytesToMove(List<StorageVolume> volumes,
double threshold) {
Review Comment:
Here the calculation logic is almost the same as in DiskBalancerService,
like self compare to self. If there is anything wrong, it cannot be found by
this unit test.
--
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]