public virtual void TestDoubleBuffer()
        {
            EditsDoubleBuffer buf = new EditsDoubleBuffer(1024);

            NUnit.Framework.Assert.IsTrue(buf.IsFlushed());
            byte[] data = new byte[100];
            buf.WriteRaw(data, 0, data.Length);
            NUnit.Framework.Assert.AreEqual("Should count new data correctly", data.Length, buf
                                            .CountBufferedBytes());
            NUnit.Framework.Assert.IsTrue("Writing to current buffer should not affect flush state"
                                          , buf.IsFlushed());
            // Swap the buffers
            buf.SetReadyToFlush();
            NUnit.Framework.Assert.AreEqual("Swapping buffers should still count buffered bytes"
                                            , data.Length, buf.CountBufferedBytes());
            NUnit.Framework.Assert.IsFalse(buf.IsFlushed());
            // Flush to a stream
            DataOutputBuffer outBuf = new DataOutputBuffer();

            buf.FlushTo(outBuf);
            NUnit.Framework.Assert.AreEqual(data.Length, outBuf.GetLength());
            NUnit.Framework.Assert.IsTrue(buf.IsFlushed());
            NUnit.Framework.Assert.AreEqual(0, buf.CountBufferedBytes());
            // Write some more
            buf.WriteRaw(data, 0, data.Length);
            NUnit.Framework.Assert.AreEqual("Should count new data correctly", data.Length, buf
                                            .CountBufferedBytes());
            buf.SetReadyToFlush();
            buf.FlushTo(outBuf);
            NUnit.Framework.Assert.AreEqual(data.Length * 2, outBuf.GetLength());
            NUnit.Framework.Assert.AreEqual(0, buf.CountBufferedBytes());
            outBuf.Close();
        }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"/>
        public override void Close()
        {
            // EditLogOutputStream
            // close should have been called after all pending transactions
            // have been flushed & synced.
            int size = doubleBuf.CountBufferedBytes();

            if (size != 0)
            {
                throw new IOException("BackupEditStream has " + size + " records still to be flushed and cannot be closed."
                                      );
            }
            RPC.StopProxy(backupNode);
            // stop the RPC threads
            doubleBuf.Close();
            doubleBuf = null;
        }