diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java index b9a2d1586d..572b40d0f3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java @@ -30,6 +30,7 @@ import java.net.URI; import java.util.Collection; +import com.google.common.base.Supplier; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileUtil; @@ -56,6 +57,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeoutException; public class TestFSNamesystem { @@ -271,9 +273,16 @@ public void run() { } latch.await(); - Thread.sleep(10); // Lets all threads get BLOCKED - Assert.assertEquals("Expected number of blocked thread not found", - threadCount, rwLock.getQueueLength()); + try { + GenericTestUtils.waitFor(new Supplier() { + @Override + public Boolean get() { + return (threadCount == rwLock.getQueueLength()); + } + }, 10, 1000); + } catch (TimeoutException e) { + fail("Expected number of blocked thread not found"); + } } /**