Пример #1
0
        /// <summary>
        /// Reacts to connection request.
        /// </summary>
        private void ReactToConnectRequest(object o, EventArgs e)
        {
            SetupInfo setupInfo = new SetupInfo(); //The setup info to be checked and then updated to the setup info in model if valid.

            setupInfo.Ip = view.SetupWindow.IpTextBox;

            uint result;
            bool res = uint.TryParse(view.SetupWindow.TableBox, out result);

            if (!res)
            {
                view.ShowMessageBox("Table number cannot be negative");
                return;
            }
            setupInfo.TableNo = uint.Parse(view.SetupWindow.TableBox);
            if (setupInfo.Ip.Length == 0)
            {
                view.ShowMessageBox("Please type in the target connection");
                return;
            }

            string password = view.SetupWindow.Password; //Password from setup window to be tested.

            try
            {
                //Tests inf there is a connection to the voter box.
                PessimisticVoterDAO pvdao = new PessimisticVoterDAO(setupInfo.Ip, password);
                pvdao.StartTransaction();
                pvdao.EndTransaction();
            }
            catch (Exception e1)
            {
                if (e1.Message.Contains("Access"))
                {
                    view.ShowMessageBox("Incorrect password");
                    return;
                }
                if (e1.Message.Contains("connect"))
                {
                    view.ShowMessageBox("No connection to server. Please check connection or target address.");
                    return;
                }
            }

            //feed the model with setup information.
            model.SetupInfo = setupInfo;
            model.AdminPass = password;

            //Tries to write setup information to the setup.conf file.
            try
            {
                model.WriteToConfig();
            }
            catch (Exception e2)
            {
                view.ShowMessageBox("unable to write to config file. " + e2.StackTrace);
            }
            view.SetupWindow.Hide();
            view.ScannerWindow.Show();
        }
Пример #2
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();
        }
Пример #3
0
        public PessimisticVoterDAO StaticPvdaoGet()
        {
            PessimisticVoterDAO result = Model.StaticPvdao;

            return(result);
            // TODO: add assertions to method ModelTest.StaticPvdaoGet()
        }
Пример #4
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"));
            }
        }
Пример #5
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();
        }
Пример #6
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();
        }
Пример #7
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"));
            }
        }
Пример #8
0
 public void StaticPvdaoSet(PessimisticVoterDAO value)
 {
     Model.StaticPvdao = value;
     // TODO: add assertions to method ModelTest.StaticPvdaoSet(PessimisticVoterDAO)
 }
Пример #9
0
 /// <summary>
 /// Initializes and starts the pessimistic voter DAO's transaction.
 /// </summary>
 public void initializeStaticDAO()
 {
     staticPvdao = new PessimisticVoterDAO(setupInfo.Ip, adminPass); //Initialize the pvdao.
     staticPvdao.StartTransaction();
 }
Пример #10
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();
        }