public void CascadeUpdateTest() { throw new StackOverflowException(); var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); const ulong itself = Links.Itself; using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { var l1 = links.Create(itself, itself); var l2 = links.Create(itself, itself); l2 = links.Update(l2, l2, l1, l2); links.Create(l2, itself); links.Create(l2, itself); l2 = links.Update(l2, l1); links.Delete(l2); Global.Trash = links.Total; } Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); File.Delete(tempDatabaseFilename); File.Delete(tempTransactionLogFilename); }
public void TransactionsTest() { var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); const ulong itself = Links.Itself; // Auto Reverted (Because no commit at transaction) using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { using (var transaction = links.BeginTransaction()) { var l1 = links.Create(itself, itself); var l2 = links.Create(itself, itself); Global.Trash = links.Update(l2, l2, l1, l2); links.Delete(l1); Global.Trash = transaction; } Global.Trash = links.Total; } Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); // User Code Error (Autoreverted) try { using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { using (var transaction = links.BeginTransaction()) { var l1 = links.Create(itself, itself); var l2 = links.Create(itself, itself); l2 = links.Update(l2, l2, l1, l2); links.Create(l2, itself); links.Create(l2, itself); ExceptionThrower(); l2 = links.Update(l2, l1); // TODO: Fix CascadeUpdateTest and move ExceptionThrower() before transaction.Commit() links.Delete(l2); transaction.Commit(); } Global.Trash = links.Total; } } catch { Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); } // Commit using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { using (var transaction = links.BeginTransaction()) { var l1 = links.Create(itself, itself); var l2 = links.Create(itself, itself); Global.Trash = links.Update(l2, l2, l1, l2); links.Delete(l1); transaction.Commit(); } Global.Trash = links.Total; } Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); // Damage database FileHelpers .WriteFirst(tempTransactionLogFilename, new Links.Transition { TransactionId = 555 }); // Try load damaged database try { // TODO: Fix using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { Global.Trash = links.Total; } } catch (NotSupportedException ex) { Assert.IsTrue(ex.Message == "Database is damaged, autorecovery is not supported yet."); } Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); File.Delete(tempDatabaseFilename); File.Delete(tempTransactionLogFilename); }
public void BasicTransactionLogTest() { var tempDatabaseFilename = Path.GetTempFileName(); var tempTransactionLogFilename = Path.GetTempFileName(); const ulong itself = Links.Itself; using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024)) { var l1 = links.Create(itself, itself); var l2 = links.Create(itself, itself); Global.Trash = links.Update(l2, l2, l1, l2); links.Delete(l1); } Global.Trash = FileHelpers .ReadAll<Links.Transition>(tempTransactionLogFilename); File.Delete(tempDatabaseFilename); File.Delete(tempTransactionLogFilename); }