Repository: hadoop Updated Branches: refs/heads/branch-2 dcf1f1fdf -> 9d8191604
HDFS-8834. TestReplication is not valid after HDFS-6482. (Contributed by Lei Xu) (cherry picked from commit f4f1b8b267703b8bebab06e17e69a4a4de611592) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/9d819160 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/9d819160 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/9d819160 Branch: refs/heads/branch-2 Commit: 9d8191604010c15a2b9c1eec6e09e04821e3fcee Parents: dcf1f1f Author: Lei Xu <[email protected]> Authored: Tue Jul 28 16:55:51 2015 -0700 Committer: Lei Xu <[email protected]> Committed: Tue Jul 28 23:41:44 2015 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/hdfs/TestReplication.java | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/9d819160/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java index 010a26e..55e9056 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hdfs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; @@ -25,6 +27,10 @@ import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; import java.net.InetSocketAddress; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Iterator; import java.util.Random; @@ -514,12 +520,28 @@ public class TestReplication { if (data_dir.listFiles().length == 0) { nonParticipatedNodeDirs.add(data_dir); } else { + assertNull("participatedNodeDirs has already been set.", + participatedNodeDirs); participatedNodeDirs = data_dir; } } + assertEquals(2, nonParticipatedNodeDirs.size()); String blockFile = null; - File[] listFiles = participatedNodeDirs.listFiles(); + final List<File> listFiles = new ArrayList<>(); + Files.walkFileTree(participatedNodeDirs.toPath(), + new SimpleFileVisitor<java.nio.file.Path>() { + @Override + public FileVisitResult visitFile( + java.nio.file.Path file, BasicFileAttributes attrs) + throws IOException { + listFiles.add(file.toFile()); + return FileVisitResult.CONTINUE; + } + } + ); + assertFalse(listFiles.isEmpty()); + int numReplicaCreated = 0; for (File file : listFiles) { if (file.getName().startsWith(Block.BLOCK_FILE_PREFIX) && !file.getName().endsWith("meta")) { @@ -528,10 +550,12 @@ public class TestReplication { file1.mkdirs(); new File(file1, blockFile).createNewFile(); new File(file1, blockFile + "_1000.meta").createNewFile(); + numReplicaCreated++; } break; } } + assertEquals(2, numReplicaCreated); fs.setReplication(new Path("/test"), (short) 3); cluster.restartDataNodes(); // Lets detect all DNs about dummy copied
