public void TestWriteToTemporaryCopy() { Dictionary <Guid, TestInfo> first, data = new Dictionary <Guid, TestInfo>(); using (TempFile temp = new TempFile()) { temp.Delete(); var options = GetOptions(temp); options.TransactionLogFileName = Path.ChangeExtension(options.FileName, ".tlog"); using (var tree = new BPlusTree <Guid, TestInfo>(options)) { Insert(tree, data, 1, 100, TimeSpan.MaxValue); TestInfo.AssertEquals(data, tree); Assert.IsFalse(temp.Exists); } // All data commits to output file Assert.IsTrue(temp.Exists); TestInfo.AssertEquals(data, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); first = new Dictionary <Guid, TestInfo>(data); using (var tree = new BPlusTree <Guid, TestInfo>(options)) { Insert(tree, data, 1, 100, TimeSpan.MaxValue); //We are writing to a backup, the original file still contains 100 items: TestInfo.AssertEquals(first, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); //Commit the changes and the original file will now contain our changes: tree.CommitChanges(); TestInfo.AssertEquals(data, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); //Add a few more records... Insert(tree, data, 1, 100, TimeSpan.MaxValue); } //Dispose of the tree will commit changes... TestInfo.AssertEquals(data, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); } }
public void TestWriteToTemporaryCopy() { Dictionary<Guid, TestInfo> first, data = new Dictionary<Guid, TestInfo>(); using(TempFile temp = new TempFile()) { temp.Delete(); var options = GetOptions(temp); options.TransactionLogFileName = Path.ChangeExtension(options.FileName, ".tlog"); using (var tree = new BPlusTree<Guid, TestInfo>(options)) { Insert(tree, data, 1, 100, TimeSpan.MaxValue); TestInfo.AssertEquals(data, tree); Assert.IsFalse(temp.Exists); } // All data commits to output file Assert.IsTrue(temp.Exists); TestInfo.AssertEquals(data, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); first = new Dictionary<Guid, TestInfo>(data); using (var tree = new BPlusTree<Guid, TestInfo>(options)) { Insert(tree, data, 1, 100, TimeSpan.MaxValue); //We are writing to a backup, the original file still contains 100 items: TestInfo.AssertEquals(first, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); //Commit the changes and the original file will now contain our changes: tree.CommitChanges(); TestInfo.AssertEquals(data, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); //Add a few more records... Insert(tree, data, 1, 100, TimeSpan.MaxValue); } //Dispose of the tree will commit changes... TestInfo.AssertEquals(data, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); } }