This is an automated email from the ASF dual-hosted git repository.
Gargi-jais11 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 7c6e57e1a1d HDDS-15292. Reduce Thread.sleep usage in DiskBalancer
tests (#10293).
7c6e57e1a1d is described below
commit 7c6e57e1a1de0da7bd2ca097bdbe144cf753821e
Author: slfan1989 <[email protected]>
AuthorDate: Mon May 18 16:05:33 2026 +0800
HDDS-15292. Reduce Thread.sleep usage in DiskBalancer tests (#10293).
---
.../diskbalancer/TestDiskBalancerTask.java | 9 ++++++---
...stDiskBalancerWithConcurrentBackgroundTasks.java | 21 +++++++++++++++++----
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerTask.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerTask.java
index dc2cd03655d..fc3fdb7b140 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerTask.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerTask.java
@@ -47,6 +47,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hdds.HddsConfigKeys;
@@ -579,7 +580,7 @@ public void
testDestVolumeCommittedSpaceReleased(ContainerTestVersionInfo versio
@ContainerTestVersionInfo.ContainerTest
public void testOldReplicaDelayedDeletion(ContainerTestVersionInfo
versionInfo)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
setLayoutAndSchemaForTest(versionInfo);
long delay = 2000L; // 2 second delay
diskBalancerService.setReplicaDeletionDelay(delay);
@@ -598,8 +599,10 @@ public void
testOldReplicaDelayedDeletion(ContainerTestVersionInfo versionInfo)
// create another container to trigger the deletion of old replicas
createContainer(CONTAINER_ID + 1, sourceVolume, State.CLOSED);
task = getTask();
- // Wait for the delay to pass
- Thread.sleep(delay);
+ // Wait until the delayed deletion is eligible, then trigger cleanup.
+ long deletionEligibleAt = System.nanoTime() +
TimeUnit.MILLISECONDS.toNanos(delay);
+ GenericTestUtils.waitFor(
+ () -> System.nanoTime() >= deletionEligibleAt, 50, 12_000);
task.call();
// Verify that the old container is deleted
assertFalse(oldContainerDir.exists());
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerWithConcurrentBackgroundTasks.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerWithConcurrentBackgroundTasks.java
index 2463d0f872f..316f7e5ca86 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerWithConcurrentBackgroundTasks.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/diskbalancer/TestDiskBalancerWithConcurrentBackgroundTasks.java
@@ -285,7 +285,8 @@ void
containerDeleteStaleRefKeepsSwappedReplica(ContainerTestVersionInfo version
}
});
assertThat(deleteThreadPastSchedule.await(10, TimeUnit.SECONDS)).isTrue();
- Thread.sleep(200);
+ GenericTestUtils.waitFor(
+ () -> containerSet.getContainer(CONTAINER_ID) == null, 100, 10_000);
raceInjector.continueBalancer();
@@ -367,7 +368,9 @@ void
blockTaskStaleDataKeepsPendingOnDestination(ContainerTestVersionInfo versio
}
});
assertThat(blockThreadStarted.await(10, TimeUnit.SECONDS)).isTrue();
- Thread.sleep(200);
+ GenericTestUtils.waitFor(
+ () -> readPendingDeleteBlockCountUnchecked(newData) < pendingBefore,
+ 100, 10_000);
raceInjector.continueBalancer();
CompletableFuture.allOf(balancerDone, blockDone).get(60, TimeUnit.SECONDS);
@@ -433,7 +436,8 @@ void markUnhealthyAppliedOnDestVolumeContainer(
}
});
assertThat(unhealthyThreadStarted.await(10, TimeUnit.SECONDS)).isTrue();
- Thread.sleep(200);
+ GenericTestUtils.waitFor(
+ () -> liveReplica.getContainerState() == State.UNHEALTHY, 100, 10_000);
raceInjector.continueBalancer();
CompletableFuture.allOf(balancerDone, unhealthyDone).get(60,
TimeUnit.SECONDS);
@@ -497,7 +501,8 @@ void closeContainerAppliesOnDestVolumeContainer(
}
});
assertThat(closeThreadStarted.await(10, TimeUnit.SECONDS)).isTrue();
- Thread.sleep(200);
+ GenericTestUtils.waitFor(
+ () -> liveReplica.getContainerState() == State.CLOSED, 100, 10_000);
raceInjector.continueBalancer();
CompletableFuture.allOf(balancerDone, closeDone).get(60, TimeUnit.SECONDS);
@@ -535,6 +540,14 @@ private long
readPendingDeleteBlockCount(KeyValueContainerData data) throws IOEx
}
}
+ private long readPendingDeleteBlockCountUnchecked(KeyValueContainerData
data) {
+ try {
+ return readPendingDeleteBlockCount(data);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Persists pending-deletion counters in container metadata so they survive
* disk balancer copy/import and can be verified on the destination replica.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]