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 b702da0b06d..2139df94b9b 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.List; @@ -505,12 +511,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 listFiles = new ArrayList<>(); + Files.walkFileTree(participatedNodeDirs.toPath(), + new SimpleFileVisitor() { + @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")) { @@ -519,10 +541,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