### Question:
BootstrapStandby implements Tool, Configurable { @Override public int run(String[] args) throws Exception { parseArgs(args); parseConfAndFindOtherNN(); NameNode.checkAllowFormat(conf); InetSocketAddress myAddr = NameNode.getAddress(conf); SecurityUtil.login(conf, DFS_NAMENODE_KEYTAB_FILE_KEY, DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, myAddr.getHostName()); return SecurityUtil.doAsLoginUserOrFatal(new PrivilegedAction<Integer>() { @Override public Integer run() { try { return doRun(); } catch (IOException e) { throw new RuntimeException(e); } } }); }  @Override int run(String[] args); @Override void setConf(Configuration conf); @Override Configuration getConf(); static int run(String[] argv, Configuration conf);  }### Answer:
@Test public void testSuccessfulBaseCase() throws Exception { removeStandbyNameDirs(); try { cluster.restartNameNode(1); fail("Did not throw"); } catch (IOException ioe) { GenericTestUtils.assertExceptionContains( "storage directory does not exist or is not accessible", ioe); } int rc = BootstrapStandby.run( new String[]{"-nonInteractive"}, cluster.getConfiguration(1)); assertEquals(0, rc); FSImageTestUtil.assertNNHasCheckpoints(cluster, 1, ImmutableList.of(0)); FSImageTestUtil.assertNNFilesMatch(cluster); cluster.restartNameNode(1); }
@Test public void testDownloadingLaterCheckpoint() throws Exception { nn0.getRpcServer().rollEditLog(); nn0.getRpcServer().rollEditLog(); NameNodeAdapter.enterSafeMode(nn0, false); NameNodeAdapter.saveNamespace(nn0); NameNodeAdapter.leaveSafeMode(nn0); long expectedCheckpointTxId = NameNodeAdapter.getNamesystem(nn0) .getFSImage().getMostRecentCheckpointTxId(); assertEquals(6, expectedCheckpointTxId); int rc = BootstrapStandby.run( new String[]{"-force"}, cluster.getConfiguration(1)); assertEquals(0, rc); FSImageTestUtil.assertNNHasCheckpoints(cluster, 1, ImmutableList.of((int)expectedCheckpointTxId)); FSImageTestUtil.assertNNFilesMatch(cluster); cluster.restartNameNode(1); }
@Test public void testSharedEditsMissingLogs() throws Exception { removeStandbyNameDirs(); CheckpointSignature sig = nn0.getRpcServer().rollEditLog(); assertEquals(3, sig.getCurSegmentTxId()); URI editsUri = cluster.getSharedEditsDir(0, 1); File editsDir = new File(editsUri); File editsSegment = new File(new File(editsDir, "current"), NNStorage.getFinalizedEditsFileName(1, 2)); GenericTestUtils.assertExists(editsSegment); assertTrue(editsSegment.delete()); LogCapturer logs = GenericTestUtils.LogCapturer.captureLogs( LogFactory.getLog(BootstrapStandby.class)); try { int rc = BootstrapStandby.run( new String[]{"-force"}, cluster.getConfiguration(1)); assertEquals(BootstrapStandby.ERR_CODE_LOGS_UNAVAILABLE, rc); } finally { logs.stopCapturing(); } GenericTestUtils.assertMatches(logs.getOutput(), "FATAL.*Unable to read transaction ids 1-3 from the configured shared"); }
@Test public void testStandbyDirsAlreadyExist() throws Exception { int rc = BootstrapStandby.run( new String[]{"-nonInteractive"}, cluster.getConfiguration(1)); assertEquals(BootstrapStandby.ERR_CODE_ALREADY_FORMATTED, rc); rc = BootstrapStandby.run( new String[]{"-force"}, cluster.getConfiguration(1)); assertEquals(0, rc); }
@Test(timeout=30000) public void testOtherNodeNotActive() throws Exception { cluster.transitionToStandby(0); int rc = BootstrapStandby.run( new String[]{"-force"}, cluster.getConfiguration(1)); assertEquals(0, rc); }