Ejemplo n.º 1
0
        /// <summary>
        /// Add an itinerary, kill RM before commit. Restart the RMs and you can see nothing changed (still c1 state). Demo shadow copy works after failure
        /// </summary>
        public void UncommittedScenario()
        {
            StartUp();
            Console.WriteLine("Flight RM shall terminate before transaction commits. ");
            Customer c = new Customer("12345678-1234-1234-1234-123456789012");

            FlightsRM.SelfDestruct(2, 0, 0, 0);
            string[] flights = new string[] { "SEA->LAX", "LAX->LAV" };
            try
            {
                WorkflowControl.ReserveItinerary(c, flights, "Vegas", true, true);
            }
            catch (WebException e)
            {
                // Expected error because one of the RM will be selfdestroyed.
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Restarting flight RM");
            StartFlightsRM();
            Transaction t      = WorkflowControl.Start();
            string      actual = WorkflowControl.QueryItinerary(t, c);

            Console.WriteLine(actual);
            Assert.AreEqual("", actual);
            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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// All RM prepared, one RM dies before receiving Commit, on recovery, the RM should recover the transaction, WC shouldn’t notice this
        /// </summary>
        public void ReCommitAfterRmFailTransaction2PC()
        {
            StartUp();

            CarsRM.SelfDestruct(0, 0, 1, 0);
            Customer c = new Customer("12345678-1234-1234-1234-123456789012");

            string[] flights = new string[] { "SEA->LAX", "LAX->LAV" };
            ThreadPool.QueueUserWorkItem(o => { Thread.Sleep(1000); CarsRM.SelfDestruct(0, 0, 0, 0); });
            WorkflowControl.ReserveItinerary(c, flights, "Vegas", true, true);
            // We shall see some commit retry message from TM but the transaction shall success.
            Transaction t      = WorkflowControl.Start();
            string      actual = WorkflowControl.QueryItinerary(t, c);

            Console.WriteLine(actual);
            Assert.AreEqual("F:SEA->LAX,F:LAX->LAV,C:Vegas,R:Vegas", actual);
            actual = PrintCars();
            Assert.AreEqual("Vegas,0,3;NewYork,10,30;", actual);
            actual = PrintRooms();
            Assert.AreEqual("Vegas,1,1;NewYork,20,10;", actual);
            actual = PrintFlights();
            Assert.AreEqual("SEA->LAX,9,2;LAX->LAV,11,3;SEA->JFK,8,4;", actual);
            actual = PrintCustomers();
            Assert.AreEqual("12345678-1234-1234-1234-123456789012;", actual);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// All RMs returns prepared, except one fails to prepare, the transaction should abort
        /// </summary>
        public void RollbackAfterRmFailTransaction2PC()
        {
            StartUp();
            CarsRM.SelfDestruct(0, 1, 0, 0);
            Customer c = new Customer("12345678-1234-1234-1234-123456789012");

            string[] flights = new string[] { "SEA->LAX", "LAX->LAV" };
            WorkflowControl.ReserveItinerary(c, flights, "Vegas", true, true);
            // We shall see some rollback message from TM.
            Console.WriteLine("One RM failed at prepare. TM will rollback all prepared RMs");
            Pause();
            Transaction t      = WorkflowControl.Start();
            string      actual = WorkflowControl.QueryItinerary(t, c);

            Console.WriteLine(actual);
            Assert.AreEqual("", actual);
            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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Submit an itinerary with car, flight and hotel. Show the values are updated. Demo Read, write and commit.
        /// </summary>
        public void AddOneItinerary()
        {
            StartUp();
            Customer c = new Customer("12345678-1234-1234-1234-123456789012");

            string[] flights = new string[] { "SEA->LAX", "LAX->LAV" };
            WorkflowControl.ReserveItinerary(c, flights, "Vegas", true, true);
            Transaction t      = WorkflowControl.Start();
            string      actual = WorkflowControl.QueryItinerary(t, c);

            Console.WriteLine(actual);
            Assert.AreEqual("F:SEA->LAX,F:LAX->LAV,C:Vegas,R:Vegas", actual);
            actual = PrintCars();
            Assert.AreEqual("Vegas,0,3;NewYork,10,30;", actual);
            actual = PrintRooms();
            Assert.AreEqual("Vegas,1,1;NewYork,20,10;", actual);
            actual = PrintFlights();
            Assert.AreEqual("SEA->LAX,9,2;LAX->LAV,11,3;SEA->JFK,8,4;", actual);
            actual = PrintCustomers();
            Assert.AreEqual("12345678-1234-1234-1234-123456789012;", actual);
        }