HDFS-10990. TestPendingInvalidateBlock should wait for IBRs. Contributed by Yiqun Lin.

This commit is contained in:
Andrew Wang 2016-10-13 11:41:37 -07:00
parent 008122b3c9
commit fdce515091

View File

@ -86,6 +86,8 @@ public void tearDown() throws Exception {
public void testPendingDeletion() throws Exception {
final Path foo = new Path("/foo");
DFSTestUtil.createFile(dfs, foo, BLOCKSIZE, REPLICATION, 0);
DFSTestUtil.waitForReplication(dfs, foo, REPLICATION, 10000);
// restart NN
cluster.restartNameNode(true);
InvalidateBlocks invalidateBlocks =
@ -98,6 +100,7 @@ public void testPendingDeletion() throws Exception {
"invalidateBlocks", mockIb);
dfs.delete(foo, true);
waitForNumPendingDeletionBlocks(REPLICATION);
Assert.assertEquals(0, cluster.getNamesystem().getBlocksTotal());
Assert.assertEquals(REPLICATION, cluster.getNamesystem()
.getPendingDeletionBlocks());
@ -105,7 +108,7 @@ public void testPendingDeletion() throws Exception {
dfs.getPendingDeletionBlocksCount());
Mockito.doReturn(0L).when(mockIb).getInvalidationDelay();
waitForBlocksToDelete();
waitForNumPendingDeletionBlocks(0);
Assert.assertEquals(0, cluster.getNamesystem().getBlocksTotal());
Assert.assertEquals(0, cluster.getNamesystem().getPendingDeletionBlocks());
Assert.assertEquals(0, dfs.getPendingDeletionBlocksCount());
@ -182,7 +185,7 @@ public void testPendingDeleteUnknownBlocks() throws Exception {
Assert.assertEquals(4, cluster.getNamesystem().getPendingDeletionBlocks());
cluster.restartNameNode(true);
waitForBlocksToDelete();
waitForNumPendingDeletionBlocks(0);
Assert.assertEquals(3, cluster.getNamesystem().getBlocksTotal());
Assert.assertEquals(0, cluster.getNamesystem().getPendingDeletionBlocks());
}
@ -199,7 +202,8 @@ private long waitForReplication() throws Exception {
return cluster.getNamesystem().getUnderReplicatedBlocks();
}
private void waitForBlocksToDelete() throws Exception {
private void waitForNumPendingDeletionBlocks(int numBlocks)
throws Exception {
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
@ -207,7 +211,8 @@ public Boolean get() {
try {
cluster.triggerBlockReports();
if (cluster.getNamesystem().getPendingDeletionBlocks() == 0) {
if (cluster.getNamesystem().getPendingDeletionBlocks()
== numBlocks) {
return true;
}
} catch (Exception e) {