// create two files with one block each.
DFSTestUtil.createFile(fs, file1, 1000, (short) 1, 0);
DFSTestUtil.createFile(fs, file2, 2000, (short) 1, 0);
checkGetBlockLocationsWorks(fs, file1);
NameNode namenode = cluster.getNameNode();
namenode.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
Assert.assertTrue("should still be in SafeMode", namenode.isInSafeMode());
// getBlock locations should still work since block locations exists
checkGetBlockLocationsWorks(fs, file1);
namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
assertFalse("should not be in SafeMode", namenode.isInSafeMode());
Assert.assertFalse("should not be in SafeMode", namenode.isInSafeMode());
// Now 2nd part of the tests where there aren't block locations
cluster.shutdownDataNodes();
cluster.shutdownNameNode();
// now bring up just the NameNode.
cluster.restartNameNode();
cluster.waitActive();
LOG.info("Restarted cluster with just the NameNode");
namenode = cluster.getNameNode();
Assert.assertTrue("No datanode is started. Should be in SafeMode",
namenode.isInSafeMode());
FileStatus stat = fs.getFileStatus(file1);
try {
fs.getFileBlockLocations(stat, 0, 1000);
Assert.assertTrue("Should have got safemode exception", false);
} catch (SafeModeException e) {
// as expected
} catch (RemoteException re) {
if (!re.getClassName().equals(SafeModeException.class.getName()))
Assert.assertTrue("Should have got safemode exception", false);
}
namenode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
Assert.assertFalse("Should not be in safemode", namenode.isInSafeMode());
checkGetBlockLocationsWorks(fs, file1);
} finally {
if (fs != null)
fs.close();