HDFS-13631. TestDFSAdmin#testCheckNumOfBlocksInReportCommand should use a separate MiniDFSCluster path. Contributed by Anbang Hu.
This commit is contained in:
parent
1361030e59
commit
1f324e9661
|
@ -110,11 +110,15 @@ public class TestDFSAdmin {
|
||||||
private static final PrintStream OLD_OUT = System.out;
|
private static final PrintStream OLD_OUT = System.out;
|
||||||
private static final PrintStream OLD_ERR = System.err;
|
private static final PrintStream OLD_ERR = System.err;
|
||||||
private String tempResource = null;
|
private String tempResource = null;
|
||||||
|
private static final int NUM_DATANODES = 2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
conf = new Configuration();
|
conf = new Configuration();
|
||||||
conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 3);
|
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();
|
restartCluster();
|
||||||
|
|
||||||
admin = new DFSAdmin(conf);
|
admin = new DFSAdmin(conf);
|
||||||
|
@ -157,7 +161,8 @@ public class TestDFSAdmin {
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
cluster = new MiniDFSCluster.Builder(conf)
|
||||||
|
.numDataNodes(NUM_DATANODES).build();
|
||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
datanode = cluster.getDataNodes().get(0);
|
datanode = cluster.getDataNodes().get(0);
|
||||||
namenode = cluster.getNameNode();
|
namenode = cluster.getNameNode();
|
||||||
|
@ -904,40 +909,34 @@ public class TestDFSAdmin {
|
||||||
|
|
||||||
@Test(timeout = 300000L)
|
@Test(timeout = 300000L)
|
||||||
public void testCheckNumOfBlocksInReportCommand() throws Exception {
|
public void testCheckNumOfBlocksInReportCommand() throws Exception {
|
||||||
Configuration config = new Configuration();
|
DistributedFileSystem dfs = cluster.getFileSystem();
|
||||||
config.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 512);
|
Path path = new Path("/tmp.txt");
|
||||||
config.set(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, "3s");
|
|
||||||
|
|
||||||
int numOfDatanodes = 1;
|
DatanodeInfo[] dn = dfs.getDataNodeStats();
|
||||||
MiniDFSCluster miniDFSCluster = new MiniDFSCluster.Builder(config)
|
assertEquals(dn.length, NUM_DATANODES);
|
||||||
.numDataNodes(numOfDatanodes).build();
|
// Block count should be 0, as no files are created
|
||||||
try {
|
int actualBlockCount = 0;
|
||||||
miniDFSCluster.waitActive();
|
for (DatanodeInfo d : dn) {
|
||||||
DistributedFileSystem dfs = miniDFSCluster.getFileSystem();
|
actualBlockCount += d.getNumBlocks();
|
||||||
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;
|
|
||||||
|
|
||||||
//Wait for One Heartbeat
|
|
||||||
Thread.sleep(3 * 1000);
|
|
||||||
|
|
||||||
dn = dfs.getDataNodeStats();
|
|
||||||
assertEquals(dn.length, numOfDatanodes);
|
|
||||||
|
|
||||||
//Block count should be 2, as file is created with block count 2
|
|
||||||
assertEquals(dn[0].getNumBlocks(), expectedBlockCount);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cluster.shutdown();
|
|
||||||
}
|
}
|
||||||
|
assertEquals(0, actualBlockCount);
|
||||||
|
|
||||||
|
// Create a file with 2 blocks
|
||||||
|
DFSTestUtil.createFile(dfs, path, 1024, (short) 1, 0);
|
||||||
|
int expectedBlockCount = 2;
|
||||||
|
|
||||||
|
// Wait for One Heartbeat
|
||||||
|
Thread.sleep(3 * 1000);
|
||||||
|
|
||||||
|
dn = dfs.getDataNodeStats();
|
||||||
|
assertEquals(dn.length, NUM_DATANODES);
|
||||||
|
|
||||||
|
// 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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue