Ejemplo n.º 1
0
        /// <summary>
        /// T1, T2 write R1, T1 commit, T2 abort, see only T1's change in. Demo abort.
        /// </summary>
        public void ConcurrentCommitAbort()
        {
            StartUp();
            Transaction    t1    = WorkflowControl.Start();
            Transaction    t2    = WorkflowControl.Start();
            AutoResetEvent sync1 = new AutoResetEvent(false);
            AutoResetEvent sync2 = new AutoResetEvent(false);

            ThreadPool.QueueUserWorkItem(o =>
            {
                WorkflowControl.AddCars(t1, "Seattle", 1, 3);
                WorkflowControl.Commit(t1);
                sync1.Set();
            });
            ThreadPool.QueueUserWorkItem(o =>
            {
                WorkflowControl.AddCars(t2, "Seattle", 2, 2);
                WorkflowControl.Abort(t2);
                sync2.Set();
            });
            // here is just to make sure t2 commits before t1, so the price will be 2.
            sync1.WaitOne();
            sync2.WaitOne();

            string actual = PrintCars();

            Assert.AreEqual("Vegas,1,3;NewYork,10,30;Seattle,1,3;", actual);
        }