Exemplo n.º 1
0
        void UpdateDepartment(object p)
        {
            SQLDataLayer           dl  = null;
            UpdateDepartmentParams par = (UpdateDepartmentParams)p;

            try
            {
                dl = new SQLDataLayer(ResourceSettings.Instance.GetDBConnString());
                dl.BeginTransaction();
                DataSet ds = dl.ExecuteSP("dbo.sp_Department_Update",
                                          dl.CreateParam("piDepartmentSid", par.DepartmentSid),
                                          dl.CreateParam("piDepartment", par.DeptValue),
                                          dl.CreateParam("piIsIT", true),
                                          dl.CreateParam("piActive", true));
                dl.Commit();
                if ((int)ds.Tables[0].Rows[0]["RowsAffected"] > 0)
                {
                    TestContext.WriteLine(string.Format("INSERTED for {0}{1}", par.DeptValue, par.ThreadNum));
                }
                else
                {
                    TestContext.WriteLine(string.Format("Already exists for {0}{1}", par.DeptValue, par.ThreadNum));
                }
            }
            catch (Exception ex)
            {
                dl.Rollback();
                ErrorOnThread = true;
                TestContext.WriteLine(string.Format("Exception for {0}:{1}", par.ThreadNum, ex.Message));
            }
            finally
            {
                dl.Dispose();
            }
        }
Exemplo n.º 2
0
        public void DepartmentUpdate()
        {
            Thread[] threads = new Thread[1];
            DataSet  ds      = GetTopTwoDepartments();

            //run it 30 times.
            for (int x = 0; x < 30; x++)
            {
                //get a unique value per run for computer detail
                string deptValue = DateTime.Now.Ticks.ToString();

                for (int i = 0; i < threads.Length; i++)
                {
                    threads[i] = new Thread(new ParameterizedThreadStart(UpdateDepartment));
                }

                for (int i = 0; i < threads.Length; i++)
                {
                    Thread thread             = threads[i];
                    UpdateDepartmentParams p2 = new UpdateDepartmentParams
                                                (
                        i,
                        (int)ds.Tables[0].Rows[0]["Department_SID"],
                        (string)ds.Tables[0].Rows[1]["Department"]
                                                );
                    thread.Start(p2);
                }

                //join all of them (wait)
                foreach (Thread thread in threads)
                {
                    thread.Join();
                }
                threads = new Thread[1];
                for (int i = 0; i < threads.Length; i++)
                {
                    threads[i] = new Thread(new ParameterizedThreadStart(UpdateDepartment));
                }
                for (int i = 0; i < threads.Length; i++)
                {
                    Thread thread             = threads[i];
                    UpdateDepartmentParams p2 = new UpdateDepartmentParams
                                                (
                        i,
                        (int)ds.Tables[0].Rows[1]["Department_SID"],
                        (string)ds.Tables[0].Rows[0]["Department"]
                                                );
                    thread.Start(p2);
                }

                foreach (Thread thread in threads)
                {
                    thread.Join();
                }

                if (ErrorOnThread)
                {
                    Assert.Fail("Dupe Test failed");
                }
            }
        }