From 0ddb8defad6a7fd5eb69847d1789ba51952c0cf0 Mon Sep 17 00:00:00 2001 From: Brahma Reddy Battula Date: Wed, 28 Dec 2016 10:34:33 +0530 Subject: [PATCH] HDFS-11252. TestFileTruncate#testTruncateWithDataNodesRestartImmediately can fail with BindException. Contributed by Yiqun Lin. --- .../server/namenode/TestFileTruncate.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java index d203413556..0ea587ccbb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java @@ -681,13 +681,7 @@ public void testTruncateWithDataNodesRestart() throws Exception { int toTruncateLength = 1; int newLength = startingFileSize - toTruncateLength; cluster.getDataNodes().get(dn).shutdown(); - try { - boolean isReady = fs.truncate(p, newLength); - assertFalse(isReady); - } finally { - cluster.restartDataNode(dn, true, true); - cluster.waitActive(); - } + truncateAndRestartDN(p, dn, newLength); checkBlockRecovery(p); LocatedBlock newBlock = getLocatedBlocks(p).getLastLocatedBlock(); @@ -740,13 +734,7 @@ public void testCopyOnTruncateWithDataNodesRestart() throws Exception { int toTruncateLength = 1; int newLength = startingFileSize - toTruncateLength; cluster.getDataNodes().get(dn).shutdown(); - try { - boolean isReady = fs.truncate(p, newLength); - assertFalse(isReady); - } finally { - cluster.restartDataNode(dn, true, true); - cluster.waitActive(); - } + truncateAndRestartDN(p, dn, newLength); checkBlockRecovery(p); LocatedBlock newBlock = getLocatedBlocks(p).getLastLocatedBlock(); @@ -800,8 +788,8 @@ public void testTruncateWithDataNodesRestartImmediately() throws Exception { boolean isReady = fs.truncate(p, newLength); assertFalse(isReady); - cluster.restartDataNode(dn0, true, true); - cluster.restartDataNode(dn1, true, true); + cluster.restartDataNode(dn0, false, true); + cluster.restartDataNode(dn1, false, true); cluster.waitActive(); checkBlockRecovery(p); @@ -1242,4 +1230,15 @@ static void restartCluster(StartupOption o) .build(); fs = cluster.getFileSystem(); } + + private void truncateAndRestartDN(Path p, int dn, int newLength) + throws IOException { + try { + boolean isReady = fs.truncate(p, newLength); + assertFalse(isReady); + } finally { + cluster.restartDataNode(dn, false, true); + cluster.waitActive(); + } + } }