Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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;
            }
        }
Example #4
0
 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))
                                ));
 }
Example #5
0
 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 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);
        }
    }
Example #7
0
        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
        }
Example #8
0
        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
        }
Example #9
0
        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());
        }
Example #10
0
        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);
        }