HDFS-10603. Fix flaky tests in org.apache.hadoop.hdfs.server.namenode.snapshot.TestOpenFilesWithSnapshot. Contributed by Yiqun Lin.

This commit is contained in:
Akira Ajisaka 2016-07-19 13:49:24 -07:00
parent cda0a280dd
commit fc570b55b9
1 changed files with 9 additions and 12 deletions

View File

@ -69,7 +69,7 @@ public class TestOpenFilesWithSnapshot {
// delete files separately // delete files separately
fs.delete(new Path("/test/test/test2"), true); fs.delete(new Path("/test/test/test2"), true);
fs.delete(new Path("/test/test/test3"), true); fs.delete(new Path("/test/test/test3"), true);
cluster.restartNameNode(); restartNameNode();
} }
@Test @Test
@ -79,7 +79,7 @@ public class TestOpenFilesWithSnapshot {
// delete parent directory // delete parent directory
fs.delete(new Path("/test/test"), true); fs.delete(new Path("/test/test"), true);
cluster.restartNameNode(); restartNameNode();
} }
@Test @Test
@ -87,11 +87,7 @@ public class TestOpenFilesWithSnapshot {
Path path = new Path("/test"); Path path = new Path("/test");
doWriteAndAbort(fs, path); doWriteAndAbort(fs, path);
fs.delete(new Path("/test/test"), true); fs.delete(new Path("/test/test"), true);
NameNode nameNode = cluster.getNameNode(); restartNameNode();
NameNodeAdapter.enterSafeMode(nameNode, false);
NameNodeAdapter.saveNamespace(nameNode);
NameNodeAdapter.leaveSafeMode(nameNode);
cluster.restartNameNode(true);
// read snapshot file after restart // read snapshot file after restart
String test2snapshotPath = Snapshot.getSnapshotPath(path.toString(), String test2snapshotPath = Snapshot.getSnapshotPath(path.toString(),
@ -108,11 +104,7 @@ public class TestOpenFilesWithSnapshot {
doWriteAndAbort(fs, path); doWriteAndAbort(fs, path);
fs.delete(new Path("/test/test/test2"), true); fs.delete(new Path("/test/test/test2"), true);
fs.delete(new Path("/test/test/test3"), true); fs.delete(new Path("/test/test/test3"), true);
NameNode nameNode = cluster.getNameNode(); restartNameNode();
NameNodeAdapter.enterSafeMode(nameNode, false);
NameNodeAdapter.saveNamespace(nameNode);
NameNodeAdapter.leaveSafeMode(nameNode);
cluster.restartNameNode(true);
// read snapshot file after restart // read snapshot file after restart
String test2snapshotPath = Snapshot.getSnapshotPath(path.toString(), String test2snapshotPath = Snapshot.getSnapshotPath(path.toString(),
@ -203,6 +195,11 @@ public class TestOpenFilesWithSnapshot {
fs.rename(new Path("/test/test"), new Path("/test/test-renamed")); fs.rename(new Path("/test/test"), new Path("/test/test-renamed"));
fs.delete(new Path("/test/test-renamed"), true); fs.delete(new Path("/test/test-renamed"), true);
restartNameNode();
}
private void restartNameNode() throws Exception {
cluster.triggerBlockReports();
NameNode nameNode = cluster.getNameNode(); NameNode nameNode = cluster.getNameNode();
NameNodeAdapter.enterSafeMode(nameNode, false); NameNodeAdapter.enterSafeMode(nameNode, false);
NameNodeAdapter.saveNamespace(nameNode); NameNodeAdapter.saveNamespace(nameNode);