private static void TestCreateNewFile(DiskIo stream, FileHeaderBlock fat)
        {
            SubFileName id1 = SubFileName.CreateRandom();
            SubFileName id2 = SubFileName.CreateRandom();
            SubFileName id3 = SubFileName.CreateRandom();
            TransactionalEdit trans = new TransactionalEdit(stream);
            //create 3 files

            SubFileStream fs1 = trans.CreateFile(id1);
            SubFileStream fs2 = trans.CreateFile(id2);
            SubFileStream fs3 = trans.CreateFile(id3);
            if (fs1.SubFile.FileName != id1)
                throw new Exception();
            //write to the three files
            SubFileStreamTest.TestSingleByteWrite(fs1);
            SubFileStreamTest.TestCustomSizeWrite(fs2, 5);
            SubFileStreamTest.TestCustomSizeWrite(fs3, BlockDataLength + 20);

            //read from them and verify content.
            SubFileStreamTest.TestCustomSizeRead(fs3, BlockDataLength + 20);
            SubFileStreamTest.TestCustomSizeRead(fs2, 5);
            SubFileStreamTest.TestSingleByteRead(fs1);

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();

            trans.CommitAndDispose();
        }
Пример #2
0
        private static void TestCreateNewFile(DiskIo stream, FileHeaderBlock fat)
        {
            SubFileName       id1   = SubFileName.CreateRandom();
            SubFileName       id2   = SubFileName.CreateRandom();
            SubFileName       id3   = SubFileName.CreateRandom();
            TransactionalEdit trans = new TransactionalEdit(stream);
            //create 3 files

            SubFileStream fs1 = trans.CreateFile(id1);
            SubFileStream fs2 = trans.CreateFile(id2);
            SubFileStream fs3 = trans.CreateFile(id3);

            if (fs1.SubFile.FileName != id1)
            {
                throw new Exception();
            }
            //write to the three files
            SubFileStreamTest.TestSingleByteWrite(fs1);
            SubFileStreamTest.TestCustomSizeWrite(fs2, 5);
            SubFileStreamTest.TestCustomSizeWrite(fs3, BlockDataLength + 20);

            //read from them and verify content.
            SubFileStreamTest.TestCustomSizeRead(fs3, BlockDataLength + 20);
            SubFileStreamTest.TestCustomSizeRead(fs2, 5);
            SubFileStreamTest.TestSingleByteRead(fs1);

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();

            trans.CommitAndDispose();
        }
Пример #3
0
        private void CreateArchiveFile <TKey, TValue>(SubFileName fileName, EncodingDefinition storageMethod, int maxSortedTreeBlockSize)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            if (maxSortedTreeBlockSize < 1024)
            {
                throw new ArgumentOutOfRangeException(nameof(maxSortedTreeBlockSize), "Must be greater than 1024");
            }
            if ((object)storageMethod == null)
            {
                throw new ArgumentNullException("storageMethod");
            }

            using (TransactionalEdit trans = m_fileStructure.BeginEdit())
            {
                using (SubFileStream fs = trans.CreateFile(fileName))
                    using (BinaryStream bs = new BinaryStream(fs))
                    {
                        int blockSize = m_fileStructure.Snapshot.Header.DataBlockSize;

                        while (blockSize > maxSortedTreeBlockSize)
                        {
                            blockSize >>= 2;
                        }

                        SortedTree <TKey, TValue> tree = SortedTree <TKey, TValue> .Create(bs, blockSize, storageMethod);

                        tree.Flush();
                    }
                trans.ArchiveType = FileType;
                trans.CommitAndDispose();
            }
        }
Пример #4
0
        public void TestSequentialWriteAmplification()
        {
            MemoryPoolTest.TestMemoryLeak();
            double size;

            Stats.ChecksumCount      = 0;
            DiskIoSession.WriteCount = 0;
            DiskIoSession.ReadCount  = 0;

            using (TransactionalFileStructure file = TransactionalFileStructure.CreateInMemory(4096))
                using (TransactionalEdit edit = file.BeginEdit())
                    using (SubFileStream stream = edit.CreateFile(SubFileName.CreateRandom()))
                        using (BinaryStream bs = new BinaryStream(stream))
                        {
                            Stats.ChecksumCount      = 0;
                            DiskIoSession.WriteCount = 0;
                            DiskIoSession.ReadCount  = 0;

                            //Write 8 million
                            for (long s = 0; s < 1000000; s++)
                            {
                                bs.Write(s);
                            }
                            size = bs.Position / 4096.0;
                        }

            System.Console.WriteLine("Read: " + (DiskIoSession.ReadCount / size).ToString("0.0"));
            System.Console.WriteLine("Write: " + (DiskIoSession.WriteCount / size).ToString("0.0"));
            System.Console.WriteLine("Checksums: " + (Stats.ChecksumCount / size).ToString("0.0"));
            MemoryPoolTest.TestMemoryLeak();
        }
Пример #5
0
        private static void TestRollback(DiskIo stream, FileHeaderBlock fat)
        {
            SubFileName       id1   = SubFileName.CreateRandom();
            SubFileName       id2   = SubFileName.CreateRandom();
            SubFileName       id3   = SubFileName.CreateRandom();
            TransactionalEdit trans = new TransactionalEdit(stream);

            //create 3 files additional files
            SubFileStream fs21 = trans.CreateFile(id1);
            SubFileStream fs22 = trans.CreateFile(id2);
            SubFileStream fs23 = trans.CreateFile(id3);

            //open files
            SubFileStream fs1 = trans.OpenFile(0);
            SubFileStream fs2 = trans.OpenFile(1);
            SubFileStream fs3 = trans.OpenFile(2);

            //read from them and verify content.
            SubFileStreamTest.TestSingleByteRead(fs2);
            SubFileStreamTest.TestCustomSizeRead(fs3, 5);
            SubFileStreamTest.TestCustomSizeRead(fs1, BlockDataLength + 20);

            //rewrite bad data.
            SubFileStreamTest.TestSingleByteWrite(fs3);
            SubFileStreamTest.TestCustomSizeWrite(fs1, 5);
            SubFileStreamTest.TestCustomSizeWrite(fs2, BlockDataLength + 20);

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();

            fs21.Dispose();
            fs22.Dispose();
            fs23.Dispose();

            trans.RollbackAndDispose();
        }
Пример #6
0
        public void TestSubFileStream()
        {
            const int BlockSize = 256;

            MemoryPoolTest.TestMemoryLeak();
            //string file = Path.GetTempFileName();
            //System.IO.File.Delete(file);
            try
            {
                //using (FileSystemSnapshotService service = FileSystemSnapshotService.CreateFile(file))
                using (TransactionalFileStructure service = TransactionalFileStructure.CreateInMemory(BlockSize))
                {
                    using (TransactionalEdit edit = service.BeginEdit())
                    {
                        SubFileStream fs = edit.CreateFile(SubFileName.Empty);
                        BinaryStream  bs = new BinaryStream(fs);

                        for (int x = 0; x < 20000000; x++)
                        {
                            bs.Write(1L);
                        }

                        bs.Position = 0;

                        BinaryStreamBenchmark.Run(bs, false);

                        bs.Dispose();
                        fs.Dispose();
                        edit.CommitAndDispose();
                    }
                }
            }
            finally
            {
                //System.IO.File.Delete(file);
            }

            MemoryPoolTest.TestMemoryLeak();
        }
        public void Test()
        {
            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
            //string file = Path.GetTempFileName();
            //System.IO.File.Delete(file);
            try
            {
                //using (FileSystemSnapshotService service = FileSystemSnapshotService.CreateFile(file))
                using (TransactionalFileStructure service = TransactionalFileStructure.CreateInMemory(BlockSize))
                {
                    using (TransactionalEdit edit = service.BeginEdit())
                    {
                        SubFileStream fs = edit.CreateFile(SubFileName.CreateRandom());
                        BinaryStream  bs = new BinaryStream(fs);
                        bs.Write((byte)1);
                        bs.Dispose();
                        fs.Dispose();
                        edit.CommitAndDispose();
                    }
                    {
                        ReadSnapshot  read = service.Snapshot;
                        SubFileStream f1   = read.OpenFile(0);
                        BinaryStream  bs1  = new BinaryStream(f1);
                        if (bs1.ReadUInt8() != 1)
                        {
                            throw new Exception();
                        }

                        using (TransactionalEdit edit = service.BeginEdit())
                        {
                            SubFileStream f2  = edit.OpenFile(0);
                            BinaryStream  bs2 = new BinaryStream(f2);
                            if (bs2.ReadUInt8() != 1)
                            {
                                throw new Exception();
                            }
                            bs2.Write((byte)3);
                            bs2.Dispose();
                        } //rollback should be issued;
                        if (bs1.ReadUInt8() != 0)
                        {
                            throw new Exception();
                        }
                        bs1.Dispose();

                        {
                            ReadSnapshot  read2 = service.Snapshot;
                            SubFileStream f2    = read2.OpenFile(0);
                            BinaryStream  bs2   = new BinaryStream(f2);
                            if (bs2.ReadUInt8() != 1)
                            {
                                throw new Exception();
                            }
                            if (bs2.ReadUInt8() != 0)
                            {
                                throw new Exception();
                            }
                            bs2.Dispose();
                        }
                    }
                    using (TransactionalEdit edit = service.BeginEdit())
                    {
                        SubFileStream f2  = edit.OpenFile(0);
                        BinaryStream  bs2 = new BinaryStream(f2);
                        bs2.Write((byte)13);
                        bs2.Write((byte)23);
                        bs2.Dispose();
                        edit.RollbackAndDispose();
                    } //rollback should be issued;
                }
            }
            finally
            {
                //System.IO.File.Delete(file);
            }

            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
            Assert.IsTrue(true);
        }
        private static void TestRollback(DiskIo stream, FileHeaderBlock fat)
        {
            SubFileName id1 = SubFileName.CreateRandom();
            SubFileName id2 = SubFileName.CreateRandom();
            SubFileName id3 = SubFileName.CreateRandom();
            TransactionalEdit trans = new TransactionalEdit(stream);

            //create 3 files additional files
            SubFileStream fs21 = trans.CreateFile(id1);
            SubFileStream fs22 = trans.CreateFile(id2);
            SubFileStream fs23 = trans.CreateFile(id3);

            //open files
            SubFileStream fs1 = trans.OpenFile(0);
            SubFileStream fs2 = trans.OpenFile(1);
            SubFileStream fs3 = trans.OpenFile(2);

            //read from them and verify content.
            SubFileStreamTest.TestSingleByteRead(fs2);
            SubFileStreamTest.TestCustomSizeRead(fs3, 5);
            SubFileStreamTest.TestCustomSizeRead(fs1, BlockDataLength + 20);

            //rewrite bad data.
            SubFileStreamTest.TestSingleByteWrite(fs3);
            SubFileStreamTest.TestCustomSizeWrite(fs1, 5);
            SubFileStreamTest.TestCustomSizeWrite(fs2, BlockDataLength + 20);

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();

            fs21.Dispose();
            fs22.Dispose();
            fs23.Dispose();

            trans.RollbackAndDispose();
        }