public void TransactionDamage() { var itself = Constants.Itself; var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); // Commit using (var memoryManager = new UInt64LinksMemoryManager(tempDatabaseFilename)) using (var links = new UInt64Links(memoryManager, tempTransactionLogFilename)) { using (var transaction = links.BeginTransaction()) { var l1 = links.CreateAndUpdate(itself, itself); var l2 = links.CreateAndUpdate(itself, itself); Global.Trash = links.Update(l2, l2, l1, l2); links.Delete(l1); transaction.Commit(); } Global.Trash = links.Count(); } Global.Trash = FileHelpers.ReadAll<UInt64Links.Transition>(tempTransactionLogFilename); // Damage database FileHelpers .WriteFirst(tempTransactionLogFilename, new UInt64Links.Transition { TransactionId = 555 }); // Try load damaged database try { // TODO: Fix using (var memoryManager = new UInt64LinksMemoryManager(tempDatabaseFilename)) using (var links = new UInt64Links(memoryManager, tempTransactionLogFilename)) { Global.Trash = links.Count(); } } catch (NotSupportedException ex) { Assert.True(ex.Message == "Database is damaged, autorecovery is not supported yet."); } Global.Trash = FileHelpers .ReadAll<UInt64Links.Transition>(tempTransactionLogFilename); File.Delete(tempDatabaseFilename); File.Delete(tempTransactionLogFilename); }
public void Bug1Test() { var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); var itself = Constants.Itself; // User Code Error (Autoreverted), some data saved try { ulong l1; ulong l2; using (var memoryManager = new UInt64LinksMemoryManager(tempDatabaseFilename)) using (var links = new UInt64Links(memoryManager, tempTransactionLogFilename)) { l1 = links.CreateAndUpdate(itself, itself); l2 = links.CreateAndUpdate(itself, itself); l2 = links.Update(l2, l2, l1, l2); links.CreateAndUpdate(l2, itself); links.CreateAndUpdate(l2, itself); } Global.Trash = FileHelpers.ReadAll<UInt64Links.Transition>(tempTransactionLogFilename); using (var memoryManager = new UInt64LinksMemoryManager(tempDatabaseFilename)) using (var links = new UInt64Links(memoryManager, tempTransactionLogFilename)) { using (var transaction = links.BeginTransaction()) { l2 = links.Update(l2, l1); links.Delete(l2); ExceptionThrower(); transaction.Commit(); } Global.Trash = links.Count(); } } catch { Global.Trash = FileHelpers .ReadAll<UInt64Links.Transition>(tempTransactionLogFilename); } File.Delete(tempDatabaseFilename); File.Delete(tempTransactionLogFilename); }
public void TransactionCommit() { var itself = Constants.Itself; var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); // Commit using (var memoryManager = new UInt64LinksMemoryManager(tempDatabaseFilename)) using (var links = new UInt64Links(memoryManager, tempTransactionLogFilename)) { using (var transaction = links.BeginTransaction()) { var l1 = links.CreateAndUpdate(itself, itself); var l2 = links.CreateAndUpdate(itself, itself); Global.Trash = links.Update(l2, l2, l1, l2); links.Delete(l1); transaction.Commit(); } Global.Trash = links.Count(); } Global.Trash = FileHelpers.ReadAll<UInt64Links.Transition>(tempTransactionLogFilename); }