public void VariableExpiration(int EXPIRE_IN_SEC) { var expireUTC = App.TimeSource.UTCNow.AddSeconds(EXPIRE_IN_SEC);//EXPIRE_IN_SEC seconds from now it will end var insert = new LockTransaction("Expiration", "NamespaceName_" + EXPIRE_IN_SEC, 0, 0.0d, LockOp.Assert(LockOp.SetVar("T1", "a", 100, expirationTimeUTC: expireUTC)), //This will expire soon LockOp.Assert(LockOp.SetVar("T1", "b", 200)) //but this will only expire with session ); var exists = new LockTransaction("Expiration", "NamespaceName_" + EXPIRE_IN_SEC, 0, 0.0d, LockOp.SelectOperatorValue("existsA", LockOp.Exists("T1", "a")), LockOp.SelectOperatorValue("existsB", LockOp.Exists("T1", "b")) ); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 100000); var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 100000); var result = m_Server.ExecuteLockTransaction(user1, insert); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(user2, exists); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //User 2 sees it Aver.IsTrue(result["existsA"].AsBool()); Aver.IsTrue(result["existsB"].AsBool()); for (var i = 0; i < EXPIRE_IN_SEC + 10; i++) { Thread.Sleep(1000);//Lets wait result = m_Server.ExecuteLockTransaction(user2, exists); Aver.IsTrue(LockStatus.TransactionOK == result.Status); Aver.IsTrue(result["existsB"].AsBool()); if (!(bool)result["existsA"]) { if (i < EXPIRE_IN_SEC - 2) { Aver.Fail("Expired too early"); } return; } Console.WriteLine("{0} sec. ... has not expired yet...".Args(i)); } Aver.Fail("Did not expire even after significant delay"); }
public void T20() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.SelectOperatorValue("A", LockOp.True), LockOp.SelectOperatorValue("B", LockOp.Not(LockOp.True)) ); var session = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session, tran); Aver.IsTrue(LockStatus.TransactionOK == result.Status); Aver.IsTrue(result["A"].AsBool()); Aver.IsFalse(result["B"].AsBool()); }