コード例 #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
ファイル: PVDAOTest.cs プロジェクト: nielssj/GroupCJN-E2011
        public void NegativeConcurrencyTest()
        {
            /*
             * Testing method explained:
             * My first thought was to simply expect this method to throw any kind
             * of MySqlException. However, such an exception is very broad, and can cover a
             * lot of failures, also some that we DON'T expect, and ones that do not mean a
             * passed test. E.g. the test might throw an excetion because the database
             * was not reachable, and then we cannot conclude anything about the concurrency that
             * we are testing. Therefore i chose to catch the exception myself, and check that the
             * error messgae contains something about timeout, which would mean the transaction was
             * blocked by another one. If the read operation does not thrown an exception, as it is
             * expected to do, the test fails as the program reaches assert false.
             */

            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);

            try
            {
                dao2.StartTransaction();
                dao2.Read(voterID);
                Debug.Assert(false);
            }
            catch (MySqlException e)
            {
                Debug.Assert(e.Message.Contains("timeout"));
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates the current voter with the voter matching the cprno.
        ///
        /// </summary>
        /// <param name="cprno">The cpr number of the voter to be found</param>
        public void FindVoter(uint cprno)
        {
            Contract.Requires(cprno != null);
            Contract.Ensures(cprno == currentVoter.PrimaryKey);
            try
            {
                currentVoter = staticPvdao.Read(cprno);

                //Update the current voter with the found voter
                CurrentVoterChanged(currentVoter);
                //Update log with read entry
                this.UpdateLog(ActivityEnum.R);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ConnectionError(); // notify that the connection has been lost.
                return;
            }
        }
コード例 #4
0
        public void PositiveConcurrencyTest()
        {
            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.EndTransaction();

            dao2.StartTransaction();
            dao2.Read(voterID);
            dao2.EndTransaction();
        }
コード例 #5
0
        public void NegativeConcurrencyTest()
        {
            /*
             * Testing method explained:
             * My first thought was to simply expect this method to throw any kind
             * of MySqlException. However, such an exception is very broad, and can cover a
             * lot of failures, also some that we DON'T expect, and ones that do not mean a
             * passed test. E.g. the test might throw an excetion because the database
             * was not reachable, and then we cannot conclude anything about the concurrency that
             * we are testing. Therefore i chose to catch the exception myself, and check that the
             * error messgae contains something about timeout, which would mean the transaction was
             * blocked by another one. If the read operation does not thrown an exception, as it is
             * expected to do, the test fails as the program reaches assert false.
             */

            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);

            try
            {
                dao2.StartTransaction();
                dao2.Read(voterID);
                Debug.Assert(false);
            }
            catch (MySqlException e)
            {
                Debug.Assert(e.Message.Contains("timeout"));
            }
        }
コード例 #6
0
ファイル: PVDAOTest.cs プロジェクト: nielssj/GroupCJN-E2011
        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();
        }