Exemplo n.º 1
0
 // noop
 /// <exception cref="System.IO.IOException"/>
 public override void Close()
 {
     SetReadyToFlush();
     FlushAndSync(true);
     try
     {
         lh.Close();
     }
     catch (Exception ie)
     {
         throw new IOException("Interrupted waiting on close", ie);
     }
     catch (BKException bke)
     {
         throw new IOException("BookKeeper error during close", bke);
     }
 }
        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();
            }
        }