public void CommitAndRollbackTest() { int[] toCommitData = new[] { 1, 3, 5, 7 }; int[] toRollbackData = new[] { 2, 6, 8, 10 }; HashTableWrapper wrapper = new HashTableWrapper(); wrapper.BeginTransaction(); for (int i = 0; i < toCommitData.Length; i++) { wrapper.Add(toCommitData[i], toCommitData[i]); } wrapper.CommitTransaction(); wrapper.BeginTransaction(); for (int i = 0; i < toRollbackData.Length; i++) { wrapper.Add(toRollbackData[i], toRollbackData[i]); } wrapper.RollbackTransaction(); for (int i = 0; i < toCommitData.Length; i++) { Assert.IsTrue(wrapper.ContainsKey(toCommitData[i]), "Data committed successfully."); } for (int i = 0; i < toRollbackData.Length; i++) { Assert.IsFalse(wrapper.ContainsKey(toRollbackData[i]), "Data rollback performed successfully."); } }
public static HashTableWrapper <int, string> GetTestData() { HashTableWrapper <int, string> table_ = new HashTableWrapper <int, string>(); table_.Add(0, "Нуль"); table_.Add(1, "Один"); table_.Add(2, "Два"); table_.Add(3, "Три"); return(table_); }
public void TestWhenHashTableBlockedByAnotherTransaction() { HashTableWrapper wrapper = new HashTableWrapper(); Task.Factory.StartNew(() => { wrapper.BeginTransaction(); bool add1 = wrapper.Add(1, 1); wrapper.CommitTransaction(); Assert.IsTrue(add1, "May add record in current transaction."); }); Task.Run(() => { try { wrapper.BeginTransaction(); Assert.Fail("Not blocked by another transaction."); } catch (AccessViolationException e) { // nope. } }); }
public void HashTableBlockedByTransactionTest() { HashTableWrapper wrapper = new HashTableWrapper(); wrapper.BeginTransaction(); for (int i = 0; i < 1000; i++) { wrapper.Add(i, i); } Assert.IsTrue(wrapper.IsLocked, "Data locked by transaction successfully."); wrapper.RollbackTransaction(); }
public void RollbackTest() { HashTableWrapper wrapper = new HashTableWrapper(); wrapper.BeginTransaction(); int expectedNumberOfElements = 0; for (int i = 0; i < 1000; i++) { wrapper.Add(i, i); } wrapper.RollbackTransaction(); Assert.AreEqual(expectedNumberOfElements, wrapper.Count); }