public void ReproduceEmptyTempvalue() { // s. NstmList.RemoveAt(): After commit the value of some objects is null because the logentry tempvalue seems to not have been set despite ReadWrite access var o = StmTransaction.CreateObject <MyInt>(); var i = new MyInt { Value = 1 }; o.Write(i); using (var tx = StmTransaction.BeginTransaction( StmTransactionScopeOption.RequiresNested, StmTransactionIsolationLevel.ReadCommitted, StmTransactionCloneMode.CloneOnWrite)) { var j = o.Read(StmReadOption.PassingReadOnly); Assert.AreEqual(i, j); j = o.Read(StmReadOption.ReadWrite); Assert.AreNotEqual(i, j); j.Value = 2; tx.Commit(); } Assert.AreEqual(2, o.Read().Value); }
public void TestRequiredOrNested() { bool newTxCreated; // inner tx compatible with outer; no new tx created using (var tx0 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite, out newTxCreated)) { Assert.IsTrue(newTxCreated); using (var tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.RequiredOrNested, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite, out newTxCreated)) { Assert.IsFalse(newTxCreated); Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); Assert.IsFalse(tx1.IsNested); Assert.AreEqual(tx0, tx1); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); } // inner tx not compatible with outer; create new nested tx using (var tx0 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite)) { using (var tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.RequiredOrNested, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnRead, out newTxCreated)) { Assert.IsTrue(newTxCreated); Assert.AreEqual(2, StmTransaction.ActiveTransactionCount); Assert.IsTrue(tx1.IsNested); Assert.AreNotEqual(tx0, tx1); } Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); } }
public void TestSingleTx() { Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); using (var tx0 = StmTransaction.BeginTransaction()) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); }
public void TestReadMultiple() { var o = StmTransaction.CreateObject(1); using (var tx = StmTransaction.BeginTransaction()) { Assert.AreEqual(1, o.Read(StmReadOption.ReadOnly)); Assert.AreEqual(1, o.Read(StmReadOption.ReadOnly)); } }
public void TestCloneScalarValues() { var oString = StmTransaction.CreateObject("hello"); var oDouble = StmTransaction.CreateObject(3.14); var oDateTime = StmTransaction.CreateObject(new DateTime(2007, 6, 27)); using (var tx = StmTransaction.BeginTransaction()) { Assert.AreEqual("hello", oString.Read(StmReadOption.ReadWrite)); Assert.AreEqual(3.14, oDouble.Read(StmReadOption.ReadWrite)); Assert.AreEqual(new DateTime(2007, 6, 27), oDateTime.Read(StmReadOption.ReadWrite)); } }
public void TestCloneCustomValueType() { var vt = new MyValueType { I = 1, S = "hello" }; var oVt = StmTransaction.CreateObject(vt); using (var tx = StmTransaction.BeginTransaction()) { var vt2 = oVt.Read(StmReadOption.ReadWrite); Assert.AreEqual(vt.I, vt2.I); Assert.AreEqual(vt.S, vt2.S); } }
public void TestRequiresNestedTx() { // create nested tx using (var tx0 = StmTransaction.BeginTransaction()) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); using (var tx1 = StmTransaction.BeginTransaction()) { Assert.AreEqual(2, StmTransaction.ActiveTransactionCount); Assert.IsTrue(tx1.IsNested); } Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); }
public void TestCloseTxInWrongOrder() { var txA = StmTransaction.BeginTransaction(); ITransaction txB = StmTransaction.BeginTransaction(StmTransactionScopeOption.RequiresNew, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite); try { txA.Commit(); // this is wrong; the tx created first needs to be finished last (FILO) } catch (InvalidOperationException ex) { Assert.IsTrue(ex.Message.IndexOf("overlapping") >= 0); txB.Rollback(); txA.Rollback(); } }
public void TestRequiresNewTx() { // create new, independent tx while another is still active using (var tx0 = StmTransaction.BeginTransaction()) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); bool newTxCreated; using (var tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.RequiresNew, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite, out newTxCreated)) { Assert.IsTrue(newTxCreated); Assert.AreEqual(2, StmTransaction.ActiveTransactionCount); Assert.IsFalse(tx1.IsNested); Assert.AreNotEqual(tx0, tx1); } Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); }
public void TestCloneClass() { var c = new MyCloneableClass { I = 1, S = "hello" }; var oC = StmTransaction.CreateObject(c); using (var tx = StmTransaction.BeginTransaction()) { var c2 = oC.Read(StmReadOption.ReadWrite); Assert.AreNotEqual(c, c2); Assert.AreEqual(c.I, c2.I); Assert.AreEqual(c.S, c2.S); } using (var tx = StmTransaction.BeginTransaction()) { var c2 = oC.Read(); // the default read option is "ReadWrite" Assert.AreNotEqual(c, c2); } }
public void TestRequiredTx() { using (ITransaction tx0 = StmTransaction.BeginTransaction()) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); bool newTxCreated; using (ITransaction tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite, out newTxCreated)) { Assert.IsFalse(newTxCreated); Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); Assert.IsFalse(tx1.IsNested); Assert.AreEqual(tx0, tx1); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); //-- tx required: no tx active & current tx has compatible settings for second tx using (var tx0 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnRead)) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); using (var tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite)) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); } } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); //-- tx required: no tx active & current tx does not match requirements using (var tx0 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnWrite)) { Assert.AreEqual(1, StmTransaction.ActiveTransactionCount); using (var tx1 = StmTransaction.BeginTransaction(StmTransactionScopeOption.Required, StmTransactionIsolationLevel.Serializable, StmTransactionCloneMode.CloneOnRead)) { Assert.AreEqual(2, StmTransaction.ActiveTransactionCount); } } Assert.AreEqual(0, StmTransaction.ActiveTransactionCount); }
public void TestVersion() { var o = StmTransaction.CreateObject <int>(); Assert.AreEqual(0, o.Version); o.Write(1); Assert.AreEqual(1, o.Version); using (var tx = StmTransaction.BeginTransaction()) { o.Write(2); Assert.AreEqual(1, o.Version); tx.Commit(); } Assert.AreEqual(2, o.Version); using (var tx = StmTransaction.BeginTransaction()) { o.Write(3); Assert.AreEqual(2, o.Version); } Assert.AreEqual(2, o.Version); }