You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ar...@apache.org on 2018/05/31 18:45:43 UTC
[6/8] hadoop git commit: HDFS-13631.
TestDFSAdmin#testCheckNumOfBlocksInReportCommand should use a separate
MiniDFSCluster path. Contributed by Anbang Hu.
HDFS-13631. TestDFSAdmin#testCheckNumOfBlocksInReportCommand should use a separate MiniDFSCluster path. Contributed by Anbang Hu.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/1f324e96
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/1f324e96
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/1f324e96
Branch: refs/heads/HDDS-48
Commit: 1f324e966136f69c3254f01b43b56cf077abba7f
Parents: 1361030
Author: Inigo Goiri <in...@apache.org>
Authored: Thu May 31 10:12:38 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Thu May 31 10:12:38 2018 -0700
----------------------------------------------------------------------
.../apache/hadoop/hdfs/tools/TestDFSAdmin.java | 59 ++++++++++----------
1 file changed, 29 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/1f324e96/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
index aab3aee..647327c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
@@ -110,11 +110,15 @@ public class TestDFSAdmin {
private static final PrintStream OLD_OUT = System.out;
private static final PrintStream OLD_ERR = System.err;
private String tempResource = null;
+ private static final int NUM_DATANODES = 2;
@Before
public void setUp() throws Exception {
conf = new Configuration();
conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 3);
+ conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 512);
+ conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR,
+ GenericTestUtils.getRandomizedTempPath());
restartCluster();
admin = new DFSAdmin(conf);
@@ -157,7 +161,8 @@ public class TestDFSAdmin {
if (cluster != null) {
cluster.shutdown();
}
- cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
+ cluster = new MiniDFSCluster.Builder(conf)
+ .numDataNodes(NUM_DATANODES).build();
cluster.waitActive();
datanode = cluster.getDataNodes().get(0);
namenode = cluster.getNameNode();
@@ -904,40 +909,34 @@ public class TestDFSAdmin {
@Test(timeout = 300000L)
public void testCheckNumOfBlocksInReportCommand() throws Exception {
- Configuration config = new Configuration();
- config.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 512);
- config.set(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, "3s");
-
- int numOfDatanodes = 1;
- MiniDFSCluster miniDFSCluster = new MiniDFSCluster.Builder(config)
- .numDataNodes(numOfDatanodes).build();
- try {
- miniDFSCluster.waitActive();
- DistributedFileSystem dfs = miniDFSCluster.getFileSystem();
- Path path= new Path("/tmp.txt");
-
- DatanodeInfo[] dn = dfs.getDataNodeStats();
- assertEquals(dn.length, numOfDatanodes);
- //Block count should be 0, as no files are created
- assertEquals(dn[0].getNumBlocks(), 0);
-
-
- //Create a file with 2 blocks
- DFSTestUtil.createFile(dfs, path, 1024, (short) 1, 0);
- int expectedBlockCount = 2;
+ DistributedFileSystem dfs = cluster.getFileSystem();
+ Path path = new Path("/tmp.txt");
+
+ DatanodeInfo[] dn = dfs.getDataNodeStats();
+ assertEquals(dn.length, NUM_DATANODES);
+ // Block count should be 0, as no files are created
+ int actualBlockCount = 0;
+ for (DatanodeInfo d : dn) {
+ actualBlockCount += d.getNumBlocks();
+ }
+ assertEquals(0, actualBlockCount);
- //Wait for One Heartbeat
- Thread.sleep(3 * 1000);
+ // Create a file with 2 blocks
+ DFSTestUtil.createFile(dfs, path, 1024, (short) 1, 0);
+ int expectedBlockCount = 2;
- dn = dfs.getDataNodeStats();
- assertEquals(dn.length, numOfDatanodes);
+ // Wait for One Heartbeat
+ Thread.sleep(3 * 1000);
- //Block count should be 2, as file is created with block count 2
- assertEquals(dn[0].getNumBlocks(), expectedBlockCount);
+ dn = dfs.getDataNodeStats();
+ assertEquals(dn.length, NUM_DATANODES);
- } finally {
- cluster.shutdown();
+ // Block count should be 2, as file is created with block count 2
+ actualBlockCount = 0;
+ for (DatanodeInfo d : dn) {
+ actualBlockCount += d.getNumBlocks();
}
+ assertEquals(expectedBlockCount, actualBlockCount);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org