예제 #1
0
        /// <summary>
        /// TM dies before receiving Done from all RMs, on recovery, TM should recommit
        /// </summary>
        public void TMFailsBeforeReceivingAllDone2PC()
        {
            StartUp();

            Transaction t = WorkflowControl.Start();

            TransactionManager.SelfDestruct(false, true);
            WorkflowControl.AddCars(t, "Seattle", 10, 100);
            ThreadPool.QueueUserWorkItem(o => WorkflowControl.Commit(t));

            // TM shall be kill, now restart it
            Console.Write("TM is killed, next is to restart it");
            Pause();
            StartTM();
            // Wait to make sure all recover job is done
            // shall see the transaction recommits.
            t = WorkflowControl.Start();
            string actual = PrintCars();

            Assert.AreEqual("Vegas,1,3;NewYork,10,30;", actual);
            actual = PrintRooms();
            Assert.AreEqual("Vegas,2,1;NewYork,20,10;", actual);
            actual = PrintFlights();
            Assert.AreEqual("SEA->LAX,10,2;LAX->LAV,12,3;SEA->JFK,8,4;", actual);
            actual = PrintCustomers();
            Assert.AreEqual("", actual);
        }
예제 #2
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);
        }
예제 #3
0
        private void InitInventory()
        {
            Transaction t = WorkflowControl.Start();

            WorkflowControl.AddCars(t, "Vegas", 1, 3);
            WorkflowControl.AddRooms(t, "Vegas", 2, 1);
            WorkflowControl.AddCars(t, "NewYork", 10, 30);
            WorkflowControl.AddRooms(t, "NewYork", 20, 10);
            WorkflowControl.AddSeats(t, "SEA->LAX", 10, 2);
            WorkflowControl.AddSeats(t, "LAX->LAV", 12, 3);
            WorkflowControl.AddSeats(t, "SEA->JFK", 8, 4);
            WorkflowControl.Commit(t);
        }