From d0c786db4de99a72802e844a3a2a717a64845cda Mon Sep 17 00:00:00 2001 From: Ahmed Hussein <50450311+amahussein@users.noreply.github.com> Date: Tue, 27 Oct 2020 20:56:40 -0500 Subject: [PATCH] HDFS-15460. TestFileCreation#testServerDefaultsWithMinimalCaching fails intermittently. (#2406) --- .../apache/hadoop/hdfs/TestFileCreation.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCreation.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCreation.java index 93687b680a..a7cf68b101 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCreation.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCreation.java @@ -239,9 +239,8 @@ public void testServerDefaultsWithCaching() * Test that server defaults are updated on the client after cache expiration. */ @Test - public void testServerDefaultsWithMinimalCaching() - throws IOException, InterruptedException { - // Create cluster with an explicit block size param + public void testServerDefaultsWithMinimalCaching() throws Exception { + // Create cluster with an explicit block size param. Configuration clusterConf = new HdfsConfiguration(); long originalBlockSize = DFS_BLOCK_SIZE_DEFAULT * 2; clusterConf.setLong(DFS_BLOCK_SIZE_KEY, originalBlockSize); @@ -273,10 +272,17 @@ public void testServerDefaultsWithMinimalCaching() defaults.getDefaultStoragePolicyId()); doReturn(newDefaults).when(spyNamesystem).getServerDefaults(); - Thread.sleep(1); - defaults = dfsClient.getServerDefaults(); - // Value is updated correctly - assertEquals(updatedDefaultBlockSize, defaults.getBlockSize()); + // Verify that the value is updated correctly. Wait for 3 seconds. + GenericTestUtils.waitFor(()->{ + try { + FsServerDefaults currDef = dfsClient.getServerDefaults(); + return (currDef.getBlockSize() == updatedDefaultBlockSize); + } catch (IOException e) { + // do nothing; + return false; + } + }, 1, 3000); + } finally { cluster.shutdown(); }