/// <summary> /// Rolls back all edits that are made to the archive file and disposes of this class. /// </summary> public override void Rollback() { if (m_disposed) { throw new ObjectDisposedException(GetType().FullName); } m_tree = null; if (m_binaryStream1 != null) { m_binaryStream1.Dispose(); m_binaryStream1 = null; } if (m_subStream != null) { m_subStream.Dispose(); m_subStream = null; } m_currentTransaction.RollbackAndDispose(); InternalDispose(); }
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(); }
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); }