private void Check_NO_UNDO(string filename, DurableFileStream.FailedCommitCode failedCommitCode)
        {
            int bufferSize = 10005;

            byte[] writeBuffer = new byte[bufferSize];
            Helper.SetArrayRandomly(writeBuffer);

            //  Writer
            try
            {
                DurableFileStream dfs = new DurableFileStream(filename, true);
                dfs.Write(writeBuffer, 0, bufferSize);
                dfs.__FailedCommitSimulation__(failedCommitCode);
                Assert.Fail("should not pass here!");
                dfs.Close();
            }
            catch (Exception)
            {
                DurableFileStream dfs = new DurableFileStream(filename, false);
                Assert.AreEqual<long>(dfs.Position, 0);
                Assert.AreEqual<long>(dfs.Length, 0);
                dfs.Write(writeBuffer, 0, bufferSize);
                dfs.Commit();

                Assert.AreEqual<long>(dfs.Position, bufferSize);
                Assert.AreEqual<long>(dfs.Length, bufferSize);

                long x = 9876543210;
                dfs.Write(BitConverter.GetBytes(x), 0, 8);
                dfs.Commit();

                Assert.AreEqual<long>(dfs.Position, bufferSize + 8);
                Assert.AreEqual<long>(dfs.Length, bufferSize + 8);

                dfs.Close();

                dfs = new DurableFileStream(filename, false);
                byte[] readBuffer = new byte[bufferSize];
                dfs.Read(readBuffer, 0, bufferSize);
                Assert.IsTrue(Helper.EqualArray(writeBuffer, readBuffer));
                dfs.Read(readBuffer, 0, 8);
                long y = BitConverter.ToInt64(readBuffer, 0);
                Assert.AreEqual<long>(x, y);

                dfs.Close();
            }
        }
        public void TestRenewCheckpoint_AfterDiskWrite()
        {
            int bufferSize = 20000;

            byte[] writeBuffer1 = new byte[bufferSize];
            Helper.SetArrayRandomly(writeBuffer1);

            byte[] writeBuffer2 = new byte[bufferSize];
            Helper.SetArrayRandomly(writeBuffer2);

            long checkpointAdr = 0;

            try
            {
                // writer
                DurableFileStream dfs = new DurableFileStream("TestRenewCheckpoint_4.dat", true);
                dfs.Write(writeBuffer1, 0, bufferSize);
                dfs.Commit();

                dfs.Write(writeBuffer2, 0, writeBuffer2.Length);
                dfs.__FailedCommitSimulation__(DurableFileStream.FailedCommitCode.CHECKPOINT_AFTER_DISK_WRITE);
                Assert.Fail("should not pass here!");
                dfs.Close();
            }
            catch (Exception)
            {
                // reader
                DurableFileStream dfs = new DurableFileStream("TestRenewCheckpoint_4.dat", false);

                byte[] readBuffer1 = new byte[bufferSize];
                dfs.Read(readBuffer1, 0, bufferSize);
                Assert.IsTrue(Helper.EqualArray(readBuffer1, writeBuffer1));

                byte[] readBuffer2 = new byte[writeBuffer2.Length];
                dfs.Read(readBuffer2, 0, readBuffer2.Length);

                dfs.Close();
            }
        }
        public void TestRenewCheckpoint_AfterLogBegin1()
        {
            int bufferSize = 20000;

            byte[] writeBuffer = new byte[bufferSize];
            Helper.SetArrayRandomly(writeBuffer);

            try
            {
                DurableFileStream dfs = new DurableFileStream("TestRenewCheckpoint_AfterLogBegin1.dat", true);
                dfs.Write(writeBuffer, 0, bufferSize);
                dfs.__FailedCommitSimulation__(DurableFileStream.FailedCommitCode.CHECKPOINT_AFTER_LOG_BEGIN);
                Assert.Fail("should not pass here!");
                dfs.Close();
            }
            catch (Exception)
            {
                // reader
                DurableFileStream dfs = new DurableFileStream("TestRenewCheckpoint_AfterLogBegin1.dat", false);
                byte[] readBuffer = new byte[bufferSize];
                dfs.Read(readBuffer, 0, bufferSize);
                Assert.IsTrue(Helper.EqualArray(readBuffer, writeBuffer));
                dfs.Close();
            }
        }
        private void Check_REDO(string filename, DurableFileStream.FailedCommitCode failedCommitCode)
        {
            int bufferSize = 10005;
            byte[] writeBuffer = new byte[bufferSize];
            Helper.SetArrayRandomly(writeBuffer);

            try
            {
                //  Writer
                DurableFileStream dfs = new DurableFileStream(filename, true);
                dfs.Write(writeBuffer, 0, bufferSize);
                dfs.__FailedCommitSimulation__(failedCommitCode);
                Assert.Fail("should not pass here!");
                dfs.Close();
            }
            catch (Exception)
            {
                // reader
                DurableFileStream dfs = new DurableFileStream(filename, false);
                Assert.AreEqual<long>(dfs.Position, 0);
                Assert.AreEqual<long>(dfs.Length, bufferSize);

                byte[] readBuffer = new byte[bufferSize];
                dfs.Read(readBuffer, 0, bufferSize);
                Assert.IsTrue(Helper.EqualArray(writeBuffer, readBuffer));

                Assert.AreEqual<long>(dfs.Position, bufferSize);
                Assert.AreEqual<long>(dfs.Length, bufferSize);

                dfs.Close();
            }
        }