*
* @throws IOException
*/
public void testManualSafeMode() throws IOException {
MiniDFSCluster cluster = null;
DistributedFileSystem fs = null;
try {
Configuration conf = new Configuration();
// disable safemode extension to make the test run faster.
conf.set("dfs.safemode.extension", "1");
cluster = new MiniDFSCluster(conf, 1, true, null);
cluster.waitActive();
fs = (DistributedFileSystem)cluster.getFileSystem();
Path file1 = new Path("/tmp/testManualSafeMode/file1");
Path file2 = new Path("/tmp/testManualSafeMode/file2");
LOG.info("Created file1 and file2.");
// create two files with one block each.
DFSTestUtil.createFile(fs, file1, 1000, (short)1, 0);
DFSTestUtil.createFile(fs, file2, 2000, (short)1, 0);
fs.close();
cluster.shutdown();
// now bring up just the NameNode.
cluster = new MiniDFSCluster(conf, 0, false, null);
cluster.waitActive();
fs = (DistributedFileSystem)cluster.getFileSystem();
LOG.info("Restarted cluster with just the NameNode");
assertTrue("No datanode is started. Should be in SafeMode",
fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
// manually set safemode.
fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
// now bring up the datanode and wait for it to be active.
cluster.startDataNodes(conf, 1, true, null, null);
cluster.waitActive();
LOG.info("Datanode is started.");
// wait longer than dfs.safemode.extension
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {}
assertTrue("should still be in SafeMode",
fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
assertFalse("should not be in SafeMode",
fs.setSafeMode(SafeModeAction.SAFEMODE_GET));
} finally {
if(fs != null) fs.close();
if(cluster!= null) cluster.shutdown();
}
}