/**
   * Tests that the edit log file meta data reading from ZooKeeper should be able to handle the
   * NoNodeException. bkjm.getInputStream(fromTxId, inProgressOk) should suppress the
   * NoNodeException and continue. HDFS-3441.
   */
  @Test
  public void testEditLogFileNotExistsWhenReadingMetadata() throws Exception {
    URI uri = BKJMUtil.createJournalURI("/hdfsjournal-editlogfile");
    NamespaceInfo nsi = newNSInfo();
    BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri, nsi);
    bkjm.format(nsi);

    try {
      // start new inprogress log segment with txid=1
      // and write transactions till txid=50
      String zkpath1 = startAndFinalizeLogSegment(bkjm, 1, 50);

      // start new inprogress log segment with txid=51
      // and write transactions till txid=100
      String zkpath2 = startAndFinalizeLogSegment(bkjm, 51, 100);

      // read the metadata from ZK. Here simulating the situation
      // when reading,the edit log metadata can be removed by purger thread.
      ZooKeeper zkspy = spy(BKJMUtil.connectZooKeeper());
      bkjm.setZooKeeper(zkspy);
      Mockito.doThrow(new KeeperException.NoNodeException(zkpath2 + " doesn't exists"))
          .when(zkspy)
          .getData(zkpath2, false, null);

      List<EditLogLedgerMetadata> ledgerList = bkjm.getLedgerList(false);
      assertEquals("List contains the metadata of non exists path.", 1, ledgerList.size());
      assertEquals(
          "LogLedgerMetadata contains wrong zk paths.", zkpath1, ledgerList.get(0).getZkPath());
    } finally {
      bkjm.close();
    }
  }
 @Before
 public void setup() throws Exception {
   zkc = BKJMUtil.connectZooKeeper();
 }