public void T18() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("t1", "Data1", 123, "Set Data1 in tbl1 to 123")), LockOp.Assert(LockOp.SetVar("t2", "Data1", 123, "Set Data1 in tbl2 to 123")) ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session1, tran); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var exists = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert( LockOp.And ( LockOp.Exists("t1", "Data1"), LockOp.Exists("t2", "Data1") ) )); result = m_Server.ExecuteLockTransaction(session1, exists); //ignore this session, since sessio1 is created under FALSE Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); result = m_Server.ExecuteLockTransaction(session2, exists); //ignore this session, since session2 is NOT the created under TRUE Aver.IsTrue(LockStatus.TransactionOK == result.Status); }
public void T17() { var tran1 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("tblMany3", "Dima1", 12345, "Set Dima to 12345")) ); var tran2 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("tA", "Key1", null, "This will be rolled back")), LockOp.Assert(LockOp.SetVar("tB", "Key2", null, "This will be rolled back")), LockOp.Assert(LockOp.SetVar("tblMany3", "Dima1", 78901, "Set Dima to 78901", allowDuplicates: false)) //DUPLICATES ARE DISALLOWED ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session3 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session1, tran1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session2, tran2); Aver.IsTrue(LockStatus.TransactionError == result.Status); //duplicates are not allowed Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); var read = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.SelectVarValue("MY-RESULT", "tA", "Key1") ); result = m_Server.ExecuteLockTransaction(session3, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); Aver.IsNull(result["MY-RESULT"]); //because the change rolled back the whole transaction }
public void Bug_20161102_DoubleSetvar() { var t1 = new LockTransaction("Bug 20161102", "Bug20161102", 0, 0, LockOp.Assert(LockOp.And(LockOp.SetVar("TBL_1", "BUG", null, allowDuplicates: false), LockOp.SetVar("TBL_2", "SAME", null, allowDuplicates: false)))); var t2 = new LockTransaction("Bug 20161102", "Bug20161102", 0, 0, LockOp.Assert(LockOp.And(LockOp.SetVar("TBL_1", "OTHER", null, allowDuplicates: false), LockOp.SetVar("TBL_2", "SAME", null, allowDuplicates: false)))); var s1 = new Agni.Locking.Server.LockSessionData(new LockSessionID("host1"), "Session 1", 1000); var s2 = new Agni.Locking.Server.LockSessionData(new LockSessionID("host2"), "Session 2", 1000); var result = m_Server.ExecuteLockTransaction(s1, t1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(s2, t2); Aver.IsTrue(LockStatus.TransactionError == result.Status); m_Server.EndLockSession(s1.ID); result = m_Server.ExecuteLockTransaction(s2, t2); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }
public void T12() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("table1", "Dima", 12345, "Set Dima to 12345 in table1")) ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "Another session", 1000); var result = m_Server.ExecuteLockTransaction(session1, tran); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var read = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.SelectVarValue("MY-RESULT", "table1", "Dima") ); result = m_Server.ExecuteLockTransaction(session2, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); Console.WriteLine(result["MY-RESULT"].GetType().FullName); var svar = (Agni.Locking.Server.Variable)result["MY-RESULT"]; Aver.AreEqual(12345, svar.Value.AsInt()); Aver.AreEqual("Set Dima to 12345 in table1", svar.Description); }
private LockTransaction arCloseStart(string facility) { return(new LockTransaction("Month End Close@'{0}'".Args(facility), "Clinical", 0, 0.0d, LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", facility))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", facility))), LockOp.Assert(LockOp.SetVar("Month-End", facility, null)) )); }
private LockTransaction mdsReviewStart(string facility, string patient, string mds) { return(new LockTransaction("MDS Review for {0}@'{1}'".Args(patient, facility), "Clinical", 0, 0.0d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", facility))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", facility, patient + mds))), LockOp.Assert(LockOp.SetVar("MDS-Review", facility, patient + mds, allowDuplicates: false)) )); }
public void T_001() { Aver.AreEqual(0, m_Server.CurrentServerCallsNorm); Aver.IsTrue(0.99d < m_Server.CurrentTrustLevel); var tran1 = new LockTransaction("Dummy call to cause traffic", "NamespaceName", 0, 0.75d, LockOp.Assert(LockOp.Not(LockOp.Exists("AAAAA", "BBBBB"))) ); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 1000); //make many calls at once LockTransactionResult result; for (var i = 0; i < 16; i++) { result = m_Server.ExecuteLockTransaction(user1, tran1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); } //then stop //Trust level normalizes with time while (m_Server.CurrentTrustLevel > 0.75d) { Console.WriteLine(" Waiting for trust to fall ... Norm: {0}; Trust: {1}".Args(m_Server.CurrentServerCallsNorm, m_Server.CurrentTrustLevel)); Thread.Sleep(500); } //trust level is low, failure result = m_Server.ExecuteLockTransaction(user1, tran1); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.MinimumRequirements == result.ErrorCause); //Trust level normalizes with time while (m_Server.CurrentTrustLevel < 0.75d) { Console.WriteLine(" ... Norm: {0}; Trust: {1}".Args(m_Server.CurrentServerCallsNorm, m_Server.CurrentTrustLevel)); Thread.Sleep(500); } //everything is OK again result = m_Server.ExecuteLockTransaction(user1, tran1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //for(var i=0; i<120; i++) //{ // if (i<30 || (i%3)==0) // { // var result = m_Server.ExecuteLockTransaction(user1, tran1); // Aver.AreEqual(LockStatus.TransactionOK, result.Status); // } // if (i==30) // Console.WriteLine("All CALLs stopped----------------"); // Thread.Sleep(500); // Console.WriteLine("Made {0} calls; Norm: {1}; Trust: {2}".Args(i, m_Server.CurrentServerCallsNorm, m_Server.CurrentTrustLevel)); //} }
public void T5() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.Or(LockOp.True, LockOp.False)) //assert(true | false) must pass ); 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); }
public void T27() { var set = new LockTransaction("Testing 101", "T27", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Sbaitso", null, "Description 1")), LockOp.Assert(LockOp.SetVar("Doctor", "Pupkin", null, "Description 2")), LockOp.Assert(LockOp.SetVar("Doctor", "Solovei", null, "Description 3")) ); var get3 = new LockTransaction("Testing 101", "T27", 0, 0.0d, LockOp.Assert(LockOp.Exists("Doctor", "Sbaitso", ignoreThisSession: false)), LockOp.Assert(LockOp.Exists("Doctor", "Pupkin", ignoreThisSession: false)), LockOp.Assert(LockOp.Exists("Doctor", "Solovei", ignoreThisSession: false)) ); var deleteOk = new LockTransaction("Testing 101", "T27", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Doctor", "Solovei")) ); var get2 = new LockTransaction("Testing 101", "T27", 0, 0.0d, LockOp.Assert(LockOp.Exists("Doctor", "Sbaitso", ignoreThisSession: false)), LockOp.Assert(LockOp.Exists("Doctor", "Pupkin", ignoreThisSession: false)), LockOp.Assert(LockOp.Not(LockOp.Exists("Doctor", "Solovei", ignoreThisSession: false))) ); var deleteFailed = new LockTransaction("Testing 101", "T27", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Doctor", "Pupkin")), LockOp.Assert(LockOp.False)//this should rollback Pupkin deletion ); var session = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session, set); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session, get3); //All 3 doctors in place Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session, deleteOk); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session, get2); //Only 2 remaining, 3rd doctor got deleted Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session, deleteFailed); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //2nd assertion failed result = m_Server.ExecuteLockTransaction(session, get2); //same as above, because previos deletion of Pupkin failed and got rolled back Aver.IsTrue(LockStatus.TransactionOK == result.Status); }
public void T6() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.And(LockOp.True, LockOp.False)) //assert(true & false) must fail ); var session = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session, tran); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("0:/AssertOp/", result.FailedStatement); }
public void SessionExpiration() { var insert = new LockTransaction("Expiration", "NamespaceName", 0, 0.0d, LockOp.Assert(LockOp.SetVar("T1", "a", 100)) ); var exists = new LockTransaction("Expiration", "NamespaceName", 0, 0.0d, LockOp.Assert(LockOp.Exists("T1", "a")) ); var dummy = new LockTransaction("Expiration", "NamespaceName", 0, 0.0d, LockOp.Assert(LockOp.True) ); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 8); //8 seconds for session max life var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 10000); 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 for (var i = 0; i < 20; i++) { Thread.Sleep(1000); //Lets wait result = m_Server.ExecuteLockTransaction(user1, dummy); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //User 1 keeps doing some stuff, so session does not epire Console.WriteLine("{0} sec. user 1 keeps sending to session 1.".Args(i)); } result = m_Server.ExecuteLockTransaction(user2, exists); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//User 2 still sees it because user 1 kept sending requests Console.WriteLine(" User 2 still sees session 1 as user 1 kept sending requests"); for (var i = 0; i < 20; i++) { Thread.Sleep(1000);//Lets wait result = m_Server.ExecuteLockTransaction(user2, exists); if (LockStatus.TransactionError == result.Status && LockErrorCause.Statement == result.ErrorCause) { return; //User 2 does not see it as user 1 session expired } Console.WriteLine("{0} sec. ... has not expired yet...".Args(i)); } Aver.Fail("Did not expire even after significant delay"); }
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 T15() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("tblMany1", "Dima1", 12345, "Set Dima to 12345")), LockOp.Assert(LockOp.SetVar("tblMany1", "Dima1", 78901, "Set Dima to 78901")) ); var session = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session, tran); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); }
public void T26() { var set1 = new LockTransaction("Testing 101", "TestNS", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Sbaitso", null, "Description 1")), LockOp.Assert(LockOp.SetVar("Doctor", "Pupkin", null, "Description 2")) ); var set2_1 = new LockTransaction("Testing 101", "TestNS", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Solovei", null, "Description 3")) ); var set2_2 = new LockTransaction("Testing 101", "TestNS", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Zhaba", "Doctor Zhaba")), LockOp.Assert(LockOp.SetVar("Doctor", "Voron", "Doctor Voron")), LockOp.Assert(LockOp.DeleteVar("Doctor", "Solovei", null)), //we Assert that deletion did delete solovei, but the tran will get aborted by the next line LockOp.Assert(LockOp.SetVar("Doctor", "Pupkin", "Doctor Pupkin duplicate")) ); var sessionSetter1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var sessionSetter2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var sessionGetter = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(sessionSetter1, set1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(sessionSetter2, set2_1); //2nd session owns SOLOVEI Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(sessionSetter2, set2_2); Aver.IsTrue(LockStatus.TransactionError == result.Status); //And Zhaba+Voron must be rolled back, Solovei deletion rolled back too Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("3:/AssertOp/", result.FailedStatement); //4th assertion failed var get = new LockTransaction("Testing 101", "TestNS", 0, 0.0d, LockOp.Assert(LockOp.Exists("Doctor", "Sbaitso")), LockOp.Assert(LockOp.Exists("Doctor", "Pupkin")), LockOp.Assert(LockOp.Exists("Doctor", "Solovei")), //Solovei still exists, because deleting tran got aborted LockOp.Assert(LockOp.Not(LockOp.Exists("Doctor", "Zhaba"))), //Zhaba did not make it because Pupkin was duplicated by 2nd setter LockOp.Assert(LockOp.Not(LockOp.Exists("Doctor", "Voron"))) //Voron same as Zhaba ); result = m_Server.ExecuteLockTransaction(sessionGetter, get); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }
public void T16() { var tran1 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("tblMany2", "Dima1", 12345, "Set Dima to 12345")) ); var tran2 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("tblMany2", "Dima1", 78901, "Set Dima to 78901", allowDuplicates: true)) //DUPLICATES ARE ALLOWED NOW ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session3 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(session1, tran1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(session2, tran2); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var read = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.SelectVarValue("MY-RESULT", "tblMany2", "Dima1", selectMany: true) ); result = m_Server.ExecuteLockTransaction(session3, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var svar = (Agni.Locking.Server.Variable[])result["MY-RESULT"]; Aver.AreEqual(2, svar.Length); Aver.AreEqual(12345, svar[0].Value.AsInt()); Aver.AreEqual("Set Dima to 12345", svar[0].Description); Aver.AreEqual(78901, svar[1].Value.AsInt()); Aver.AreEqual("Set Dima to 78901", svar[1].Description); }
private void registerThisWorker() { ensureSession(); var table = this.GetType().AssemblyQualifiedName; var value = "{0}::{1}".Args(m_Round, AgniSystem.HostName);//round must be the first - it ensures different sorting every time when round changes var descr = "{0} {1}".Args(GetType().Name, value); var script = new LockTransaction(descr, WORKSET_NS, 0, 0.0d, LockOp.SelectVarValue("Workers", table, Name, ignoreThisSession: true, abortIfNotFound: false, selectMany: true), LockOp.AnywayContinueAfter(LockOp.DeleteVar(table, Name), resetAbort: true), LockOp.Assert(LockOp.SetVar(table, Name, value, allowDuplicates: true)) ); var result = AgniSystem.LockManager.ExecuteLockTransaction(m_Session, script); if (result.ErrorCause != LockErrorCause.Unspecified) { //todo che delat? //Interumentatiopn + logging //Log() } var vars = result["Workers"] as SrvVar[]; if (vars != null) { var values = new List <string>(vars.Select(v => v.Value.AsString())); values.Add(value); //add myself values.Sort(StringComparer.InvariantCulture); //must have pre-determined order m_WorkerCount = values.Count; m_MyIndex = values.IndexOf(value);//my index in the set } else { m_WorkerCount = 1; m_MyIndex = 0; } }
public void T14() { var tran = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("table3", "Dima", 12345, "Set Dima to 12345")) ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "Another session", 1000); var result = m_Server.ExecuteLockTransaction(session1, tran); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var read = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.SelectVarValue("MY-RESULT", "different table", "Dima") //DIFFERENT TABLE NAME ); result = m_Server.ExecuteLockTransaction(session2, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); Aver.IsNull(result["MY-RESULT"]); }
public void MDSEnterReview_ARMonthEnd(int threadCount, int nsCount, int facCount, int durationSec) { var namespaces = new string[nsCount]; for (var i = 0; i < nsCount; i++) { namespaces[i] = "NS_{0}_{1}_{2}_{3}__{4}".Args(threadCount, nsCount, facCount, durationSec, i); } var facilities = new Facility[facCount]; for (var i = 0; i < facCount; i++) { facilities[i] = new Facility { ID = i * 456, Patients = Enumerable.Range(1, 100).Select(n => n).ToArray() } } ; var errors = new ConcurrentBag <Exception>(); var threads = new List <Thread>(); var totalLockAttempts = 0; var totalLockTaken = 0; var totalLocksReleaseAttempts = 0; var totalLocksReleased = 0; var totalMDSEnter = 0; var totalMDSReview = 0; var totalARMonthEnd = 0; var totalMDSEnterTaken = 0; var totalMDSReviewTaken = 0; var totalARMonthEndTaken = 0; for (var i = 0; i < threadCount; i++) { threads.Add(new Thread(() => { var user = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "user X", 10000); var sd = DateTime.Now; while ((DateTime.Now - sd).TotalSeconds < durationSec) { try { var ns = namespaces[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, namespaces.Length - 1)]; var facility = facilities[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, facilities.Length - 1)]; var patient = facility.Patients[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, facility.Patients.Length - 1)]; var chance = ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 10); LockTransaction businessOperationLockStart; LockTransaction businessOperationLockEnd; BusinessLock lockType; if (chance < 3) //MDS ENTER { lockType = BusinessLock.MDSEnter; businessOperationLockStart = new LockTransaction("MDS Entry for {0}@'{1}'".Args(patient, facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", facility.ID.ToString()))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", facility.ID.ToString(), patient.ToString()))), LockOp.Assert(LockOp.SetVar("MDS-Entry", facility.ID.ToString(), patient.ToString(), allowDuplicates: true)) ); businessOperationLockEnd = new LockTransaction("MDS Entry for {0}@'{1}' is done".Args(patient, facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("MDS-Entry", facility.ID.ToString(), patient.ToString())) ); } else if (chance < 6) //MDS REVIEW { lockType = BusinessLock.MDSReview; businessOperationLockStart = new LockTransaction("MDS Review for {0}@'{1}'".Args(patient, facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", facility.ID.ToString()))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", facility.ID.ToString(), patient.ToString()))), LockOp.Assert(LockOp.SetVar("MDS-Review", facility.ID.ToString(), patient.ToString(), allowDuplicates: false)) ); businessOperationLockEnd = new LockTransaction("MDS Review for {0}@'{1}' is done".Args(patient, facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("MDS-Review", facility.ID.ToString(), patient.ToString())) ); } else // MONTH END { lockType = BusinessLock.ARMonthEnd; //note, this is FACILITY-level lock (unlike MDSs that are patient-level) businessOperationLockStart = new LockTransaction("Month End Close@'{0}'".Args(facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", facility.ID.ToString()))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", facility.ID.ToString()))), LockOp.Assert(LockOp.SetVar("Month-End", facility.ID.ToString(), null)) ); businessOperationLockEnd = new LockTransaction("Month End Close@'{0}' is done".Args(facility.ID), ns, 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Month-End", facility.ID.ToString())) ); } Interlocked.Increment(ref totalLockAttempts); if (lockType == BusinessLock.MDSEnter) { Interlocked.Increment(ref totalMDSEnter); } else if (lockType == BusinessLock.MDSReview) { Interlocked.Increment(ref totalMDSReview); } else { Interlocked.Increment(ref totalARMonthEnd); } var tranResult = m_Server.ExecuteLockTransaction(user, businessOperationLockStart); if (tranResult.Status == LockStatus.TransactionOK) { Interlocked.Increment(ref totalLockTaken); if (lockType == BusinessLock.MDSEnter) { Interlocked.Increment(ref totalMDSEnterTaken); } else if (lockType == BusinessLock.MDSReview) { Interlocked.Increment(ref totalMDSReviewTaken); } else { Interlocked.Increment(ref totalARMonthEndTaken); } Thread.Sleep(10 + ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 150));//immitate some business work Interlocked.Increment(ref totalLocksReleaseAttempts); tranResult = m_Server.ExecuteLockTransaction(user, businessOperationLockEnd); if (tranResult.Status == LockStatus.TransactionOK) { Interlocked.Increment(ref totalLocksReleased); } } else { //locking conflict Aver.IsTrue(LockErrorCause.Statement == tranResult.ErrorCause); } } catch (Exception error) { errors.Add(error); Console.WriteLine("Total trans: {0}; ERROR: {1}".Args(totalLockAttempts, error.ToMessageWithType())); } } })); } foreach (var thread in threads) { thread.Start(); } foreach (var thread in threads) { thread.Join(); } Console.WriteLine( @" Lock attempts: {0} taken: {1} ------------------------------ Release attempts: {2} released: {3}".Args(totalLockAttempts, totalLockTaken, totalLocksReleaseAttempts, totalLocksReleased)); Console.WriteLine( @" MDS Enter: {0} out of {1} MDS Reviews: {2} out of {3} AR Month End: {4} out of {5} ".Args(totalMDSEnterTaken, totalMDSEnter, totalMDSReviewTaken, totalMDSReview, totalARMonthEndTaken, totalARMonthEnd)); Aver.AreEqual(0, errors.Count); } }
public void MDS_Entry_Review_ClosePeriod() { //note, this is FACILITY-level lock (unlike MDSs that are patient-level) var monthCloseStart = new LockTransaction("Month End Close@'Cherry Grove'", "Clinical2", 0, 0.5d, LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", "CGROVE-35"))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", "CGROVE-35"))), LockOp.Assert(LockOp.SetVar("Month-End", "CGROVE-35", null)) ); var monthCloseUnlock = new LockTransaction("Month End Close@'Cherry Grove' is done", "Clinical2", 0, 0.5d, LockOp.AnywayContinueAfter(LockOp.DeleteVar("Month-End", "CGROVE-35")) ); var mdsEnter = new LockTransaction("MDS Entry for Zak Pak@'Cherry Grove'", "Clinical2", 0, 0.5d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", "CGROVE-35"))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", "CGROVE-35", "R-45899"))), LockOp.Assert(LockOp.SetVar("MDS-Entry", "CGROVE-35", "R-45899", allowDuplicates: true)) ); var mdsReview = new LockTransaction("MDS Review for Zak Pak@'Cherry Grove'", "Clinical2", 0, 0.5d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", "CGROVE-35"))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", "CGROVE-35", "R-45899"))), LockOp.Assert(LockOp.SetVar("MDS-Review", "CGROVE-35", "R-45899", allowDuplicates: true)) ); var mdsReviewUnlock = new LockTransaction("MDS Review for Zak Pak@'Cherry Grove' is done", "Clinical2", 0, 0.5d, LockOp.AnywayContinueAfter(LockOp.DeleteVar("MDS-Review", "CGROVE-35", "R-45899")) ); var financialUser1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "Financial User 1", 1000); var financialUser2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "Financial User 2", 1000); var result = m_Server.ExecuteLockTransaction(financialUser1, monthCloseStart); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//Month end started OK result = m_Server.ExecuteLockTransaction(financialUser2, monthCloseStart); Aver.IsTrue(LockStatus.TransactionError == result.Status);//Month end start FAILED, as NOTHER user is already locking Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("2:/AssertOp/", result.FailedStatement); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 1000); var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 1000); var user3 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 3", 1000); var user4 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 4", 1000); result = m_Server.ExecuteLockTransaction(user1, mdsEnter); Aver.IsTrue(LockStatus.TransactionError == result.Status); //Cant start MDS entry while closing period Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("0:/AssertOp/", result.FailedStatement); result = m_Server.ExecuteLockTransaction(user1, monthCloseUnlock); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //mds user can not Delete month close as he did not create it //the OK is returned because of 'AnywayContinueAfter' instead of 'Assert' result = m_Server.ExecuteLockTransaction(user1, mdsEnter); Aver.IsTrue(LockStatus.TransactionError == result.Status); //STILL Cant start MDS entry while closing period Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("0:/AssertOp/", result.FailedStatement); result = m_Server.ExecuteLockTransaction(financialUser1, monthCloseUnlock); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//Now it got deleted result = m_Server.ExecuteLockTransaction(user1, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//and now , the MDS can start!!! result = m_Server.ExecuteLockTransaction(financialUser2, monthCloseStart); Aver.IsTrue(LockStatus.TransactionError == result.Status);//Now we cant start month end as someone is entering MDS Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("0:/AssertOp/", result.FailedStatement); result = m_Server.ExecuteLockTransaction(user2, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionError == result.Status); //Cant start review because someone else is entering Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //User 1 ends session, this rolls back everything Aver.IsTrue(m_Server.EndLockSession(user1.ID)); //still user 2 is present result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionError == result.Status); //Cant start review because someone else is entering Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //User 2 ends session, this rolls back everything Aver.IsTrue(m_Server.EndLockSession(user2.ID)); //No more entering people REVIEW succeeds result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //Now the review has started!!!! result = m_Server.ExecuteLockTransaction(financialUser2, monthCloseStart); Aver.IsTrue(LockStatus.TransactionError == result.Status); //Now we cant start month end as someone is REVIEWING MDS Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //but enter fails because review conflicts with it result = m_Server.ExecuteLockTransaction(user4, mdsEnter); Aver.IsTrue(LockStatus.TransactionError == result.Status); //Cant start ENTER because someone else is reviewing Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //Review is done result = m_Server.ExecuteLockTransaction(user3, mdsReviewUnlock); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //Now the review has ended!!!! //so enter now succeeds just fine result = m_Server.ExecuteLockTransaction(user4, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //Can ENTER because review is over }
public void MDS_Entry_Review() { var mdsEnter = new LockTransaction("MDS Entry for Zak Pak@'Cherry Grove'", "Clinical", 0, 0.5d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", "CGROVE-35"))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Review", "CGROVE-35", "R-45899"))), LockOp.Assert(LockOp.SetVar("MDS-Entry", "CGROVE-35", "R-45899", allowDuplicates: true)) ); var mdsReview = new LockTransaction("MDS Review for Zak Pak@'Cherry Grove'", "Clinical", 0, 0.5d, LockOp.Assert(LockOp.Not(LockOp.Exists("Month-End", "CGROVE-35"))), LockOp.Assert(LockOp.Not(LockOp.Exists("MDS-Entry", "CGROVE-35", "R-45899"))), LockOp.Assert(LockOp.SetVar("MDS-Review", "CGROVE-35", "R-45899", allowDuplicates: false)) ); var mdsReviewUnlock = new LockTransaction("MDS Review for Zak Pak@'Cherry Grove' is done", "Clinical", 0, 0.5d, LockOp.AnywayContinueAfter(LockOp.DeleteVar("MDS-Review", "CGROVE-35", "R-45899")) ); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 1000); var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 1000); var user3 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 3", 1000); var user4 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 4", 1000); var result = m_Server.ExecuteLockTransaction(user1, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(user2, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionError == result.Status);//Cant start review because someone else is entering Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //User 1 ends session, this rolls back everything Aver.IsTrue(m_Server.EndLockSession(user1.ID)); //still user 2 is present result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionError == result.Status);//Cant start review because someone else is entering Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //User 2 ends session, this rolls back everything Aver.IsTrue(m_Server.EndLockSession(user2.ID)); //No more entering people REVIEW succeeds result = m_Server.ExecuteLockTransaction(user3, mdsReview); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//Now the review has started!!!! //but enter fails because review conflicts with it result = m_Server.ExecuteLockTransaction(user4, mdsEnter); Aver.IsTrue(LockStatus.TransactionError == result.Status);//Cant start ENTER because someone else is reviewing Aver.AreEqual("1:/AssertOp/", result.FailedStatement); //Review is done result = m_Server.ExecuteLockTransaction(user3, mdsReviewUnlock); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//Now the review has ended!!!! //so enter now succeeds just fine result = m_Server.ExecuteLockTransaction(user4, mdsEnter); Aver.IsTrue(LockStatus.TransactionOK == result.Status);//Can ENTER because review is over }
public void T19() { var set1 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Patient", "Barkhan1", null, "Oleg Petrovich Barkharev")) ); var set2 = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Patient", "buloch1970", null, "S***n Genadievich Bulochkin")) ); var session1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var session3 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); //1st user var result = m_Server.ExecuteLockTransaction(session1, set1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //2nd user result = m_Server.ExecuteLockTransaction(session2, set2); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var exists = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert( LockOp.And ( LockOp.Exists("Patient", "Barkhan1"), LockOp.Exists("Patient", "buloch1970") ) )); //3rd user sees what the first two have set result = m_Server.ExecuteLockTransaction(session3, exists); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var delete = new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert( LockOp.DeleteVar("Patient", "Barkhan1", null) )); //2nd user wants to delete what the 1st set, CANT result = m_Server.ExecuteLockTransaction(session2, delete); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); //3rd user wants to delete what the 1st set, CANT result = m_Server.ExecuteLockTransaction(session3, delete); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); //3rd user still sees the two original records result = m_Server.ExecuteLockTransaction(session3, exists); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //1st user deletes what the 1st set, CAN result = m_Server.ExecuteLockTransaction(session1, delete); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //3rd user does not see the two original records anymore result = m_Server.ExecuteLockTransaction(session3, exists); Aver.IsTrue(LockStatus.TransactionError == result.Status); Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); //3rd does not see the first, but still sees the second result = m_Server.ExecuteLockTransaction(session3, new LockTransaction("Testing 101", "A", 0, 0.0d, LockOp.Assert( LockOp.And ( LockOp.Not(LockOp.Exists("Patient", "Barkhan1")), LockOp.Exists("Patient", "buloch1970") ) ))); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }
public void T25() { var set1 = new LockTransaction("Testing 101", "B", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Sbaitso", "data{ age=23}", "Description 1", allowDuplicates: true)) ); var set2 = new LockTransaction("Testing 101", "B", 0, 0.0d, LockOp.Assert(LockOp.SetVar("Doctor", "Sbaitso", "data{ score=3489}", "Description 1", allowDuplicates: true)), LockOp.Assert(LockOp.SetVar("Doctor", "Lector", "zhaba", "Description 3", allowDuplicates: true)) ); var sessionSetter1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var sessionSetter2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var sessionGetter = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "My session", 1000); var result = m_Server.ExecuteLockTransaction(sessionSetter1, set1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(sessionSetter2, set2); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var get = new LockTransaction("Testing 101", "B", 0, 0.0d, LockOp.SelectVarValue("A", "Doctor", "Sbaitso", selectMany: true) ); result = m_Server.ExecuteLockTransaction(sessionGetter, get); Aver.IsTrue(LockStatus.TransactionOK == result.Status); var v = result["A"] as Agni.Locking.Server.Variable[]; Aver.IsNotNull(v); Aver.AreEqual(2, v.Length); Console.WriteLine(v[0].Value); Aver.AreEqual(23, v[0].Value.AsLaconicConfig().AttrByName("age").ValueAsInt()); Aver.AreEqual(3489, v[1].Value.AsLaconicConfig().AttrByName("score").ValueAsInt()); var del1 = new LockTransaction("Testing 101", "B", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Doctor", "Sbaitso", "data{ age=12111113}")) ); result = m_Server.ExecuteLockTransaction(sessionSetter1, del1); Aver.IsTrue(LockStatus.TransactionError == result.Status); //because DATA does not match Aver.IsTrue(LockErrorCause.Statement == result.ErrorCause); result = m_Server.ExecuteLockTransaction(sessionGetter, get); Aver.IsTrue(LockStatus.TransactionOK == result.Status); v = result["A"] as Agni.Locking.Server.Variable[]; Aver.IsNotNull(v); Aver.AreEqual(2, v.Length); Console.WriteLine(v[0].Value); Aver.AreEqual(23, v[0].Value.AsLaconicConfig().AttrByName("age").ValueAsInt()); Aver.AreEqual(3489, v[1].Value.AsLaconicConfig().AttrByName("score").ValueAsInt()); del1 = new LockTransaction("Testing 101", "B", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Doctor", "Sbaitso", null)) ); //Reexecute delet from setter2, it shpould only remove what he has set keeping setters'1 data result = m_Server.ExecuteLockTransaction(sessionSetter2, del1); Aver.IsTrue(LockStatus.TransactionOK == result.Status); result = m_Server.ExecuteLockTransaction(sessionGetter, get); Aver.IsTrue(LockStatus.TransactionOK == result.Status); //Setters'1 data is still here, but setter's2 is gone v = result["A"] as Agni.Locking.Server.Variable[]; Aver.IsNotNull(v); Aver.AreEqual(1, v.Length); Console.WriteLine(v[0].Value); Aver.AreEqual(23, v[0].Value.AsLaconicConfig().AttrByName("age").ValueAsInt()); }
private LockTransaction arCloseStop(string facility) { return(new LockTransaction("Month End Close@'{0}' is done".Args(facility), "Clinical", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("Month-End", facility)) )); }
public void PutManyVarsSameNamespaceAndExpireVariable(bool parallel, int varCount, int tblCount) { var ns = "NS3_{0}_{1}_{2}".Args(parallel, varCount, tblCount); var ved = App.TimeSource.UTCNow.AddSeconds(7); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 10000);//the session is long, but expiration will be set on each var var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 10000); var sw = Stopwatch.StartNew(); Action <int> put = (i) => { var statements = new LockOp.StatementOp[tblCount]; for (var t = 0; t < tblCount; t++) { statements[t] = LockOp.Assert(LockOp.SetVar("t" + t.ToString(), "v" + i.ToString(), i, "Variable number " + i.ToString(), expirationTimeUTC: ved));//EXPIRATION IS SET!!!! } var insert = new LockTransaction("Set var", ns, 0, 0.0d, statements); var result = m_Server.ExecuteLockTransaction(user1, insert); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }; if (parallel) { Parallel.For(0, varCount, put); } else { for (var i = 0; i < varCount; i++) { put(i); } } Console.WriteLine("Put {0} in {1} ms at {2} ops/sec".Args(varCount, sw.ElapsedMilliseconds, varCount / (sw.ElapsedTicks / (double)Stopwatch.Frequency))); sw.Restart(); Action <int> get = (i) => { var statements = new LockOp.StatementOp[tblCount]; for (var t = 0; t < tblCount; t++) { statements[t] = LockOp.Assert(LockOp.Exists("t" + t.ToString(), "v" + i.ToString(), i));//EXISTS } var read = new LockTransaction("Get var", ns, 0, 0.0d, statements); var result = m_Server.ExecuteLockTransaction(user2, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }; if (parallel) { Parallel.For(0, varCount, get); } else { for (var i = 0; i < varCount; i++) { get(i); } } Console.WriteLine("Read/verified that all exists {0} in {1} ms at {2} ops/sec".Args(varCount, sw.ElapsedMilliseconds, varCount / (sw.ElapsedTicks / (double)Stopwatch.Frequency))); Thread.Sleep(15000);//block for sessions to timeout sw.Restart(); Action <int> get2 = (i) => { var statements = new LockOp.StatementOp[tblCount]; for (var t = 0; t < tblCount; t++) { statements[t] = LockOp.Assert(LockOp.Not(LockOp.Exists("t" + t.ToString(), "v" + i.ToString(), i))); //NOT EXISTS } var read = new LockTransaction("Get var", ns, 0, 0.0d, statements); var result = m_Server.ExecuteLockTransaction(user2, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }; if (parallel) { Parallel.For(0, varCount, get2); } else { for (var i = 0; i < varCount; i++) { get2(i); } } Console.WriteLine("Read/verified that all timed-out {0} in {1} ms at {2} ops/sec".Args(varCount, sw.ElapsedMilliseconds, varCount / (sw.ElapsedTicks / (double)Stopwatch.Frequency))); }
private LockTransaction mdsReviewStop(string facility, string patient, string mds) { return(new LockTransaction("MDS Review for {0}@'{1}' is done".Args(patient, facility), "Clinical", 0, 0.0d, LockOp.Assert(LockOp.DeleteVar("MDS-Review", facility, patient + mds)) )); }
public void PutManyVarsSameNamespace(bool parallel, int varCount, int tblCount) { var ns = "NS_{0}_{1}_{2}".Args(parallel, varCount, tblCount); var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 10000); var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 10000); var sw = Stopwatch.StartNew(); Action <int> put = (i) => { var statements = new LockOp.StatementOp[tblCount]; for (var t = 0; t < tblCount; t++) { statements[t] = LockOp.Assert(LockOp.SetVar("t" + t.ToString(), "v" + i.ToString(), i, "Variable number " + i.ToString())); } var insert = new LockTransaction("Set var", ns, 0, 0.0d, statements); var result = m_Server.ExecuteLockTransaction(user1, insert); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }; if (parallel) { Parallel.For(0, varCount, put); } else { for (var i = 0; i < varCount; i++) { put(i); } } Console.WriteLine("Put {0} in {1} ms at {2} ops/sec".Args(varCount, sw.ElapsedMilliseconds, varCount / (sw.ElapsedTicks / (double)Stopwatch.Frequency))); sw.Restart(); Action <int> get = (i) => { var statements = new LockOp.StatementOp[tblCount]; for (var t = 0; t < tblCount; t++) { statements[t] = LockOp.Assert(LockOp.Exists("t" + t.ToString(), "v" + i.ToString(), i)); } var read = new LockTransaction("Get var", ns, 0, 0.0d, statements); var result = m_Server.ExecuteLockTransaction(user2, read); Aver.IsTrue(LockStatus.TransactionOK == result.Status); }; if (parallel) { Parallel.For(0, varCount, get); } else { for (var i = 0; i < varCount; i++) { get(i); } } Console.WriteLine("Read/verified {0} in {1} ms at {2} ops/sec".Args(varCount, sw.ElapsedMilliseconds, varCount / (sw.ElapsedTicks / (double)Stopwatch.Frequency))); }