示例#1
0
        public void PossitiveConcurrencyTest3()
        {
            PessimisticVoterDAO dao1 = new PessimisticVoterDAO(server, password);
            PessimisticVoterDAO dao2 = new PessimisticVoterDAO(server, password);

            this.daos = this.daos.Concat(new List <PessimisticVoterDAO> {
                dao1, dao2
            });

            uint voter1ID = (uint)this.voters.First().PrimaryKey;
            uint voter2ID = (uint)this.voters.Last().PrimaryKey;

            Debug.Assert(voter1ID != voter2ID);

            dao1.StartTransaction();
            dao1.Read(voter1ID);

            dao2.StartTransaction();
            dao2.Read(voter2ID);
            dao2.Update(voter2ID, true);

            dao1.Update(voter1ID, true);

            dao1.EndTransaction();
            dao2.EndTransaction();
        }
示例#2
0
        /// <summary>
        /// Registeres the current voter as registered in the voter box.
        /// </summary>
        public void RegisterCurrentVoter()
        {
            Contract.Requires(currentVoter.Voted == false);
            Contract.Requires(currentVoter != null);
            Contract.Ensures(currentVoter.Voted == true);
            try
            {
                staticPvdao.Update((uint)currentVoter.PrimaryKey, true);

                //refresh the current voter to reflect the new voted status
                currentVoter = FetchVoter((uint)currentVoter.PrimaryKey);

                //Update log with write entry
                staticPvdao.EndTransaction();
                this.UpdateLog(ActivityEnum.W); //Update log with nregister entry
            }
            catch (Exception)
            {
                ConnectionError();
                return;
            }
        }
示例#3
0
        public void PositiveConcurrencyTest2()
        {
            PessimisticVoterDAO dao1 = new PessimisticVoterDAO(server, password);
            PessimisticVoterDAO dao2 = new PessimisticVoterDAO(server, password);
            this.daos = this.daos.Concat(new List<PessimisticVoterDAO> { dao1, dao2 });

            uint voterID = (uint)this.voters.First().PrimaryKey;

            dao1.StartTransaction();
            dao1.Read(voterID);
            dao1.Update(voterID, true);
            dao1.EndTransaction();

            dao2.StartTransaction();
            dao2.Read(voterID);
            dao2.EndTransaction();
        }