public void Test1() { File.Delete(@"C:\Temp\fileTemp.~d2i"); File.Delete(@"C:\Temp\fileTemp.d2i"); using (SimplifiedFileWriter writer = new SimplifiedFileWriter(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, FileFlags.ManualRollover)) { using (ISupportsBinaryStream file = writer.CreateFile(SubFileName.CreateRandom())) using (BinaryStream bs = new BinaryStream(file)) { bs.Write(1); } writer.Commit(); } using (TransactionalFileStructure reader = TransactionalFileStructure.OpenFile(@"C:\Temp\fileTemp.d2i", true)) { using (SubFileStream file = reader.Snapshot.OpenFile(0)) using (BinaryStream bs = new BinaryStream(file)) { if (bs.ReadInt32() != 1) { throw new Exception(); } } } }
public void TestMultipleFiles() { Random r = new Random(1); File.Delete(@"C:\Temp\fileTemp.~d2i"); File.Delete(@"C:\Temp\fileTemp.d2i"); using (SimplifiedFileWriter writer = new SimplifiedFileWriter(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, FileFlags.ManualRollover)) { for (int i = 0; i < 10; i++) { using (ISupportsBinaryStream file = writer.CreateFile(SubFileName.CreateRandom())) using (BinaryStream bs = new BinaryStream(file)) { bs.Write((byte)1); for (int x = 0; x < 100000; x++) { bs.Write(r.NextDouble()); } } } writer.Commit(); } r = new Random(1); using (TransactionalFileStructure reader = TransactionalFileStructure.OpenFile(@"C:\Temp\fileTemp.d2i", true)) { for (int i = 0; i < 10; i++) { using (SubFileStream file = reader.Snapshot.OpenFile(i)) using (BinaryStream bs = new BinaryStream(file)) { if (bs.ReadUInt8() != 1) { throw new Exception(); } for (int x = 0; x < 100000; x++) { if (bs.ReadDouble() != r.NextDouble()) { throw new Exception(); } } } } } }