From 1882a5dd7a693588b258395a5dc36cb2260a6440 Mon Sep 17 00:00:00 2001 From: rich Date: Sun, 16 Nov 2025 16:08:22 +0800 Subject: [PATCH 1/2] Replace Thread.sleep with proper waiting mechanism for Container Balancer --- .../ozone/TestContainerBalancerOperations.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java index a2a534f839d7..5eefc7e025ec 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java @@ -33,6 +33,7 @@ import org.apache.hadoop.hdds.scm.client.ScmClient; import org.apache.hadoop.hdds.scm.container.balancer.ContainerBalancerConfiguration; import org.apache.hadoop.hdds.scm.container.placement.algorithms.SCMContainerPlacementCapacity; +import org.apache.ozone.test.GenericTestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -97,12 +98,17 @@ public void testContainerBalancerCLIOperations() throws Exception { running = containerBalancerClient.getContainerBalancerStatus(); assertTrue(running); - // waiting for balance completed. - // TODO: this is a temporary implementation for now - // modify this after balancer is fully completed - try { - Thread.sleep(20000); - } catch (InterruptedException e) { } + GenericTestUtils.waitFor( + () -> { + try { + return !containerBalancerClient.getContainerBalancerStatus(); + } catch (IOException e) { + return false; + } + }, + 100, + 30000 + ); running = containerBalancerClient.getContainerBalancerStatus(); assertFalse(running); From e069eefdb8f5c472bbf98453019b24ef5bedd81b Mon Sep 17 00:00:00 2001 From: rich7420 Date: Mon, 17 Nov 2025 20:08:33 +0800 Subject: [PATCH 2/2] remove redundant part --- .../apache/hadoop/ozone/TestContainerBalancerOperations.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java index 5eefc7e025ec..b759e7e8cbeb 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestContainerBalancerOperations.java @@ -110,9 +110,6 @@ public void testContainerBalancerCLIOperations() throws Exception { 30000 ); - running = containerBalancerClient.getContainerBalancerStatus(); - assertFalse(running); - // test normally start , and stop it before balance is completed containerBalancerClient.startContainerBalancer(threshold, iterations, maxDatanodesPercentageToInvolvePerIteration,