cluster = new MiniDFSCluster(conf, 0, false, null);
cluster.waitActive();
LOG.info("Restarted cluster with just the NameNode");
NameNode namenode = cluster.getNameNode();
assertTrue("No datanode is started. Should be in SafeMode",
namenode.isInSafeMode());
// manually set safemode.
namenode.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.");
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {}
assertTrue("should still be in SafeMode", namenode.isInSafeMode());
namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
assertFalse("should not be in SafeMode", namenode.isInSafeMode());
} finally {
if(fs != null) fs.close();
if(cluster!= null) cluster.shutdown();
}
}