public virtual void TestEditLogFileNotExistsWhenReadingMetadata() { 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 = Org.Mockito.Mockito.Spy(BKJMUtil.ConnectZooKeeper()); bkjm.SetZooKeeper(zkspy); Org.Mockito.Mockito.DoThrow(new KeeperException.NoNodeException(zkpath2 + " doesn't exists" )).When(zkspy).GetData(zkpath2, false, null); IList <EditLogLedgerMetadata> ledgerList = bkjm.GetLedgerList(false); NUnit.Framework.Assert.AreEqual("List contains the metadata of non exists path.", 1, ledgerList.Count); NUnit.Framework.Assert.AreEqual("LogLedgerMetadata contains wrong zk paths.", zkpath1 , ledgerList[0].GetZkPath()); } finally { bkjm.Close(); } }
public virtual void TestEmptyInputStream() { ZooKeeper zk = BKJMUtil.ConnectZooKeeper(); BookKeeper bkc = new BookKeeper(new ClientConfiguration(), zk); try { LedgerHandle lh = bkc.CreateLedger(BookKeeper.DigestType.Crc32, Sharpen.Runtime.GetBytesForString ("foobar")); lh.Close(); EditLogLedgerMetadata metadata = new EditLogLedgerMetadata("/foobar", HdfsConstants .NamenodeLayoutVersion, lh.GetId(), unchecked ((int)(0x1234))); try { new BookKeeperEditLogInputStream(lh, metadata, -1); NUnit.Framework.Assert.Fail("Shouldn't get this far, should have thrown"); } catch (IOException ioe) { NUnit.Framework.Assert.IsTrue(ioe.Message.Contains("Invalid first bk entry to read" )); } metadata = new EditLogLedgerMetadata("/foobar", HdfsConstants.NamenodeLayoutVersion , lh.GetId(), unchecked ((int)(0x1234))); try { new BookKeeperEditLogInputStream(lh, metadata, 0); NUnit.Framework.Assert.Fail("Shouldn't get this far, should have thrown"); } catch (IOException ioe) { NUnit.Framework.Assert.IsTrue(ioe.Message.Contains("Invalid first bk entry to read" )); } } finally { bkc.Close(); zk.Close(); } }
public virtual void Setup() { zkc = BKJMUtil.ConnectZooKeeper(); }