Exemplo n.º 1
0
 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))
                                ));
 }
Exemplo n.º 2
0
 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))
                                ));
 }
Exemplo n.º 3
0
        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));
            //}
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void T3()
        {
            var tran = new LockTransaction("Testing 101", "A", 0, 0.0d,
                                           LockOp.Assert(LockOp.Not(LockOp.False)) //assert(!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);
        }
Exemplo n.º 6
0
        public void T4()
        {
            var tran = new LockTransaction("Testing 101", "A", 0, 0.0d,
                                           LockOp.Assert(LockOp.Not(LockOp.Not(LockOp.False))) //assert(!!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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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);
        }
    }
Exemplo n.º 10
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
        }
Exemplo n.º 11
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
        }
Exemplo n.º 12
0
        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)));
        }
Exemplo n.º 13
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);
        }