Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = null;
SecondaryNameNode secondary = null;
try {
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
StorageDirectory savedSd = null;
// Start a secondary NN, then make sure that all of its storage
// dirs got locked.
secondary = startSecondaryNameNode(conf);
NNStorage storage = secondary.getFSImage().getStorage();
for (StorageDirectory sd : storage.dirIterable(null)) {
assertLockFails(sd);
savedSd = sd;
}
LOG.info("===> Shutting down first 2NN");
secondary.shutdown();
secondary = null;
LOG.info("===> Locking a dir, starting second 2NN");
// Lock one of its dirs, make sure it fails to start
LOG.info("Trying to lock" + savedSd);
savedSd.lock();
try {
secondary = startSecondaryNameNode(conf);
assertFalse("Should fail to start 2NN when " + savedSd + " is locked",
savedSd.isLockSupported());
} catch (IOException ioe) {
GenericTestUtils.assertExceptionContains("already locked", ioe);
} finally {
savedSd.unlock();
}
} finally {
cleanup(secondary);
secondary = null;