Пример #1
0
 public void Transaction2()
 {
     try
     {
         PADI_Client.TxBegin();
         PadInt padInt = PADI_Client.AccessPadInt(1);
         padInt.Write(102);
         padInt.Read();
         padInt = PADI_Client.AccessPadInt(2);
         padInt.Write(202);
         padInt.Read();
         padInt = PADI_Client.AccessPadInt(3);
         padInt.Write(302);
         padInt.Read();
         PADI_Client.TxCommit();
     }
     catch (TxException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "--" + ex.StackTrace);
     }
 }
Пример #2
0
        public void TestSimpleWrite(int uid0)
        {
            Console.WriteLine("------ Test: Simple write ------");
            Logger.Log(new String[] { "Client", "------ Test: Simple write ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);

                if (padInt0.Write(20))
                {
                    Console.WriteLine("padInt0 write done with value (20) : " + padInt0.Read());
                }

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Simple write end----------" });
        }
Пример #3
0
        public void TestFailOnWrite()
        {
            bool canBegin1 = proxy1.TxBegin();
            bool canBegin2 = proxy2.TxBegin();

            Assert.IsTrue(canBegin1, "Could not begin transaction1");
            Assert.IsTrue(canBegin2, "Could nout begin transaction2");

            PadInt padInt1 = proxy1.CreatePadInt(PAD_ID1);//os objectos criados e acedidos teem handlers para read/write. ou seja, abrem transaccao à primeira escrita.
            PadInt padInt2 = proxy2.CreatePadInt(PAD_ID2);

            Assert.IsNotNull(padInt1, "Could not create padint1 on transaction1");
            Assert.IsNotNull(padInt2, "Could not create padint2 on transaction1");


            int padint1Read = padInt1.Read();

            Thread.Sleep(2000);
            int padint2Read = padInt2.Read();

            Assert.IsNotNull(padint1Read, "Could not read padint1 on transaction1");
            Assert.IsNotNull(padint2Read, "Could not read padint2 on transaction1");
            Console.WriteLine("========================proxy1 accessing padint 2: ====================" + PAD_ID2);

            padInt1 = proxy1.AccessPadInt(PAD_ID2);
            Assert.IsNotNull(padInt1, "Could not access padint2 on transaction1");
            Console.WriteLine("========================Write====================");
            proxy1.Status();
            padInt1.Write(20);
        }
Пример #4
0
    static void Main(string[] args)
    {
        bool res;

        PadiDstm.Init();

        res = PadiDstm.TxBegin();
        PadInt pi_a = PadiDstm.CreatePadInt(0);
        PadInt pi_b = PadiDstm.CreatePadInt(1);

        res = PadiDstm.TxCommit();

        res  = PadiDstm.TxBegin();
        pi_a = PadiDstm.AccessPadInt(0);
        pi_b = PadiDstm.AccessPadInt(1);
        PadInt pi_c = PadiDstm.AccessPadInt(0);
        PadInt pi_d = PadiDstm.AccessPadInt(1);

        pi_a.Write(36);
        pi_b.Write(37);
        Console.WriteLine("a = " + pi_a.Read());
        Console.WriteLine("b = " + pi_b.Read());
        PadiDstm.Status();
        // The following 3 lines assume we have 2 servers: one at port 2001 and another at port 2002
        res = PadiDstm.Freeze("tcp://localhost:2001/Server");
        res = PadiDstm.Recover("tcp://localhost:2001/Server");
        //res = PadiDstm.Fail("tcp://localhost:2003/Server"); // mudei para 2003 porque no 2002 ta o backup do 2001
        res = PadiDstm.TxCommit();
    }
Пример #5
0
        public void TestFailWhileInTransaction()
        {
            const int UID1  = 10;
            const int UID2  = -10;
            const int WRITE = 5;

            const int MAX = 100;

            bool result = PadiDstm.Init();


            bool beginSuccess = PadiDstm.TxBegin();

            PadInt padInt1 = PadiDstm.CreatePadInt(UID1);

            padInt1.Write(WRITE);


            PadInt padInt2 = PadiDstm.CreatePadInt(UID2);

            padInt2.Write(WRITE);


            //Servers de 1 a 2
            //Fail do server 1

            server[kill].Kill();


            Thread.Sleep(3000);
            PadiDstm.TxCommit();

            //Depois de falhar
            PadiDstm.Status();

            //PadiDstm.Fail(failedServerURL);
            bool f = PadiDstm.Freeze(failedServerURL);

            Assert.IsFalse(f);
            bool r = PadiDstm.Recover(failedServerURL);

            Assert.IsFalse(r);

            //Server falhou antes de fazer commit de t1,
            //logo deve

            Thread.Sleep(1000);

            //Server nao consegui fazer commit
            //fez abort dos creates
            //access deve retornar null
            beginSuccess = PadiDstm.TxBegin();
            padInt1      = PadiDstm.AccessPadInt(UID1);
            Assert.IsNull(padInt1);


            padInt2 = PadiDstm.AccessPadInt(UID2);
            Assert.IsNull(padInt2);
            PadiDstm.TxCommit();
        }
Пример #6
0
    /*
     * public bool TestCreateTwoPadIntsOneServerFrozen(){
     *  // Test7: Recovers both servers, freezes one and tries to create two padInts
     *  // Expected result: both padInts assigned to the same server
     *  launchMaster();
     *  launchTwoServers();
     *  try {
     *      bool res = PadiDstm.TxBegin();
     *      //res = PadiDstm.Recover("tcp://localhost:2001/Server"); // continuacao do metodo anterior
     *      //res = PadiDstm.Recover("tcp://localhost:2002/Server"); // continuacao do metodo anterior
     *      res = PadiDstm.Freeze("tcp://localhost:2001/Server");
     *      PadInt pi_j = PadiDstm.CreatePadInt(7);
     *      PadInt pi_k = PadiDstm.CreatePadInt(8);
     *      res = PadiDstm.TxCommit();
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return res;
     *  } catch (TxException e) {
     *      Console.WriteLine("TestCreateTwoPadIntsOneServerFrozen error: " + e);
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return false;
     *  }
     * }
     */

    /* DataServers status tests */

    /*
     * public bool TestAccessPadIntOnFrozenSever(){
     *  // Test8: Tries to access a padInt on the frozen server
     *  // Fails the 2002 server first to grant assignment to 2001 server
     *  // Expected result: delay, exception or error message?
     *  launchMaster();
     *  launchTwoServers();
     *  try {
     *      bool res = PadiDstm.TxBegin();
     *      // res = PadiDstm.Recover("tcp://localhost:2001/Server"); // continuacao do metodo anterior
     *      res = PadiDstm.Fail("tcp://localhost:2002/Server");
     *      PadInt pi_l = PadiDstm.CreatePadInt(9); // assigned to 2001
     *      res = PadiDstm.Recover("tcp://localhost:2002/Server");
     *      res = PadiDstm.Freeze("tcp://localhost:2001/Server");
     *      PadInt pi_m = PadiDstm.AccessPadInt(9); // fica à espera do Recover
     *      res = PadiDstm.TxCommit();
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return res;
     *  } catch (TxException e) {
     *      Console.WriteLine("TestAccessPadIntOnFrozenSever error: " + e);
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return false;
     *  }
     * }
     */

    public bool TestAccessPadIntOnFailedServer()
    {
        // Test9: Tries to access, read and write a padInt on the failed server
        // Fails the 2001 server first to grant assignment to 2002 server
        // Expected result: exception or error message?
        launchMaster();
        launchTwoServers();
        try {
            bool res = PadiDstm.TxBegin();
            // res = PadiDstm.Recover("tcp://localhost:2001/Server"); // continuacao do metodo anterior
            res = PadiDstm.Fail("tcp://localhost:2001/Server");
            PadInt pi_n = PadiDstm.CreatePadInt(10); // assigned to 2002
            res  = PadiDstm.Recover("tcp://localhost:2001/Server");
            res  = PadiDstm.Fail("tcp://localhost:2002/Server");
            pi_n = PadiDstm.AccessPadInt(10);
            Console.WriteLine(pi_n.Read());
            pi_n.Write(5);
            Console.WriteLine(pi_n.Read());
            res = PadiDstm.TxCommit();
            //Assert.Fail("No exception thrown!"); // não deve chegar aqui!
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(res);
        } catch (TxException e) {
            Console.WriteLine("TestAccessPadIntOnFailedServer error: " + e);
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(false);
        }
    }
Пример #7
0
 public void Transaction3()
 {
     try
     {
         PADI_Client.TxBegin();
         PadInt padInt = PADI_Client.AccessPadInt(1);
         padInt.Write(103);
         padInt = PADI_Client.AccessPadInt(2);
         padInt.Write(203);
         padInt = PADI_Client.AccessPadInt(3);
         padInt.Write(303);
         PADI_Client.TxCommit();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Пример #8
0
        public void TestSimpleAbort(int uid0)
        {
            Console.WriteLine("------ Test: Simple Abort ------");
            Logger.Log(new String[] { "Client", "------ Test: Simple Abort ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);

                if (padInt0.Write(20))
                {
                    Console.WriteLine("padInt0 write done with value (20) : " + padInt0.Read());
                }

                PadiDstm.TxAbort();
                Console.WriteLine("txAbort Done");

                /* do a read to test if the abort was successful */
                Console.WriteLine("I will test if the abort was successful...");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0A = PadiDstm.AccessPadInt(uid0);

                /* the padInt's value must be equal to initialization value */
                int value = padInt0A.Read();

                if (value == 0)
                {
                    Console.WriteLine("it's OK");
                }
                else
                {
                    Console.WriteLine("BUG!!!!!: abort was not successful... value = " + value);
                }
                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Simple abort end----------" });
        }
Пример #9
0
 private void writeButton_Click(object sender, EventArgs e)
 {
     //statusTextBox.Clear();
     try {
         String   selectedItem = listBox.SelectedItem.ToString();
         string[] parser       = selectedItem.Split(':');
         int      uid          = Convert.ToInt32(parser[1]);
         PadInt   obj          = (PadInt)myObjects[uid];
         obj.Write(Convert.ToInt32(writeTextBox.Text));
         listBox.ClearSelected();
     } catch (TxException te) {
         statusTextBox.AppendText("Cannot Write, transaction " + te.Tid + " | Reason: " + te.Msg);
     }
 }
Пример #10
0
        public void TestReadAfterCommit()
        {
            bool beginSuccess = false;
            int  uid2         = 2; //object 1 uid
            // int uid2 = 2; //object 2 uid
            const int DEFAULT_PADINT_VALUE = 0;
            const int WRITE_VALUE          = 5;

            bool result = PadiDstm.Init();

            Assert.IsTrue(result, "Failed to load library.");

            //T1
            beginSuccess = PadiDstm.TxBegin();

            Assert.IsTrue(beginSuccess, "Failed to begin transaction.");

            PadInt padInt1 = PadiDstm.CreatePadInt(uid2);

            Assert.IsNotNull(padInt1, "CreatePadint returned null for uid:" + uid2);


            int firstRead = padInt1.Read();

            Assert.AreEqual(firstRead, DEFAULT_PADINT_VALUE, String.Format("Read:{0} Expected:{1}", firstRead, DEFAULT_PADINT_VALUE));

            padInt1.Write(WRITE_VALUE);
            int secondRead = padInt1.Read();

            Assert.AreEqual(secondRead, WRITE_VALUE, String.Format("Read:{0} Expected:{1}", secondRead, WRITE_VALUE));
            bool status = PadiDstm.Status();

            Thread.Sleep(3000);
            bool didCommit = PadiDstm.TxCommit();


            beginSuccess = PadiDstm.TxBegin();
            PadInt pad = PadiDstm.AccessPadInt(uid2);

            int thirdRead = pad.Read();

            Assert.IsTrue(didCommit, "Failed to commit transaction.");
            didCommit = PadiDstm.TxCommit();

            PadiDstm.Status();
            Assert.IsTrue(didCommit, "Failed to commit transaction.");
            Assert.IsTrue(status, "Status operation not done.");
        }
Пример #11
0
        public void TestReadWrite(int uid0)
        {
            Console.WriteLine("------ Test: Read write ------");
            Logger.Log(new String[] { "Client", "------ Test: Read write ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);

                //read
                Console.WriteLine("padInt0 read: " + padInt0.Read());

                //Library.txCommit();
                //Console.WriteLine("txCommit Done");

                // write
                Console.WriteLine("now I will do a write...");

                //Library.TxBegin();
                //Console.WriteLine("txBegin Done");

                /* the padInt's value must be equal to initialization value */
                //PadInt padInt0A = Library.AccessPadInt(uid0);

                if (padInt0.Write(211))
                {
                    Console.WriteLine("padInt0 write done with value (211) : " + padInt0.Read());
                }

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Read write end----------" });
        }
Пример #12
0
        public void TestFreezeFail(int uid0)
        {
            Console.WriteLine("------ Test: Freeze (o cliente1 tem que ja ter feito o freeze/fail) ------");
            Logger.Log(new String[] { "Client", "------ Test: Freeze/Fail ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);


                Console.WriteLine("####################################################################");
                Console.WriteLine("Vou fazer ciclo de 10 writes.");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                for (int i = 0; i <= 10; i++)
                {
                    Console.WriteLine("Fiz um Write no uid 2. uid() = " + padInt0.Write(i).ToString());
                }

                Console.WriteLine("####################################################################");
                Console.WriteLine("Fiz os 10 writes. (valor deve ser 10) padInt0.Read() =" + padInt0.Read() + "Press enter para commit.");
                Console.WriteLine("####################################################################");
                Console.ReadLine();

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Read Freeze end----------" });
        }
Пример #13
0
    public bool TestReadPadIntAfterWritingTransactionCommited()
    {
        // Test11: Locally writes on a PadInt, and aborts this transaction. Another transaction will read the PadInt.
        // Expected result: The PadInt must have the initial values, no modifications.
        launchMaster();
        launchTwoServers();
        try {
            bool   res  = PadiDstm.TxBegin();
            PadInt pi_p = PadiDstm.CreatePadInt(12);
            pi_p = PadiDstm.AccessPadInt(12);
            //Console.WriteLine(pi_p.Read());
            Assert.AreEqual(pi_p.Read(), 0); // tem que estar a zero, valor inicial
            res = PadiDstm.TxCommit();

            res = PadiDstm.TxBegin();
            pi_p.Write(100);
            //Console.WriteLine(pi_p.Read());
            Assert.AreEqual(pi_p.Read(), 100); // tem que estar a 100, modificação local
            res = PadiDstm.TxCommit();         // conclui a transacção

            res = PadiDstm.TxBegin();
            Assert.AreEqual(pi_p.Read(), 100); // tem que estar a 100, valor actualizado
            res = PadiDstm.TxCommit();

            master.Kill();
            server1.Kill();
            server2.Kill();
            return(res);
        } catch (Exception e) {
            Console.WriteLine("TestReadPadIntAfterWritingTransactionCommited error: " + e);
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(false);
        }
    }
Пример #14
0
        public void TestCheckLoadBalancing()
        {
            bool beginSuccess = false;

            const int MAX_UID = 500;
            const int DEFAULT_PADINT_VALUE = 0;
            const int WRITE_VALUE          = 5;

            bool result = PadiDstm.Init();

            Assert.IsTrue(result, "Failed to load library.");

            for (int i = 0; i < MAX_UID; i++)
            {
                beginSuccess = PadiDstm.TxBegin();

                Assert.IsTrue(beginSuccess, "Failed to begin transaction.");

                PadInt padInt1 = PadiDstm.CreatePadInt(i);
                Assert.IsNotNull(padInt1, "CreatePadint returned null for uid:" + i);


                int firstRead = padInt1.Read();
                Assert.AreEqual(firstRead, DEFAULT_PADINT_VALUE, String.Format("Read:{0} Expected:{1}", firstRead, DEFAULT_PADINT_VALUE));

                padInt1.Write(WRITE_VALUE);
                int secondRead = padInt1.Read();
                Assert.AreEqual(secondRead, WRITE_VALUE, String.Format("Read:{0} Expected:{1}", secondRead, WRITE_VALUE));


                bool didCommit = PadiDstm.TxCommit();
                //Thread.Sleep(1000);
            }

            bool status = PadiDstm.Status();
        }
Пример #15
0
        public void TestPartitioning()
        {
            bool beginSuccess = false;
            int  uid2         = -1000; //object 1 uid
            int  uid3         = 1000;
            // int uid2 = 2; //object 2 uid
            const int DEFAULT_PADINT_VALUE = 0;
            const int WRITE_VALUE          = 5;

            bool result = PadiDstm.Init();

            Assert.IsTrue(result);

            //T1
            beginSuccess = PadiDstm.TxBegin();
            //bool status = PadiDstm.Status();
            Assert.IsTrue(beginSuccess);

            PadInt padInt1 = PadiDstm.CreatePadInt(uid2);
            PadInt padInt2 = PadiDstm.CreatePadInt(uid3);

            Assert.IsNotNull(padInt1);


            int firstRead = padInt1.Read();

            Assert.AreEqual(firstRead, DEFAULT_PADINT_VALUE);


            padInt2.Write(WRITE_VALUE);
            //int secondRead = padInt1.Read();
            //Assert.AreEqual(secondRead, WRITE_VALUE, String.Format("Read:{0} Expected:{1}", secondRead, WRITE_VALUE));

            bool didCommit = PadiDstm.TxCommit();

            //bool status = PadiDstm.Status();

            StartServer();

            Console.WriteLine("Depois de arrancar o 2 server");



            Thread.Sleep(5000);
            bool status = PadiDstm.Status();

            beginSuccess = PadiDstm.TxBegin();

            Assert.IsTrue(beginSuccess);

            PadInt pad = PadiDstm.AccessPadInt(uid3);

            Assert.IsNotNull(pad);


            int readAfterStart = pad.Read();

            Assert.AreEqual(readAfterStart, WRITE_VALUE, String.Format("Read:{0} Expected:{1}", readAfterStart, WRITE_VALUE));



            Assert.IsTrue(didCommit, "Failed to commit transaction.");
            didCommit = PadiDstm.TxCommit();

            Assert.IsTrue(didCommit, "Failed to commit transaction.");

            status = PadiDstm.Status();
        }
Пример #16
0
        //Criado 3
        //1-> 3
        //2 -> 10
        //3-> 30
        private bool transaction2()
        {
            bool succeed;

            try {
                Console.WriteLine("Primeira transaccao começa");
                succeed = PadiDstm.TxBegin();
                if (!succeed)
                {
                    return(false);
                }

                PadInt pad = PadiDstm.CreatePadInt(2);
                Console.WriteLine("Antes do write");
                pad = PadiDstm.AccessPadInt(2);
                pad.Write(10);
                pad.Write(20);

                Console.WriteLine("Deve ler 20 ->" + pad.Read());


                succeed = PadiDstm.TxCommit();


                if (!succeed)
                {
                    PadiDstm.TxAbort();
                    return(false);
                }
                Console.WriteLine("Segunda transaccao começa");

                succeed = PadiDstm.TxBegin();
                if (!succeed)
                {
                    return(false);
                }

                pad = PadiDstm.AccessPadInt(2);
                pad.Write(10);
                Console.WriteLine("Deve dar 10 -> " + pad.Read());

                succeed = PadiDstm.TxCommit();

                if (!succeed)
                {
                    PadiDstm.TxAbort();
                    return(false);
                }

                //T3
                succeed = PadiDstm.TxBegin();
                if (!succeed)
                {
                    return(false);
                }

                pad = PadiDstm.CreatePadInt(3);
                pad.Write(30);
                Console.WriteLine("Deve dar 30 -> " + pad.Read());

                succeed = PadiDstm.TxCommit();

                if (!succeed)
                {
                    PadiDstm.TxAbort();
                    return(false);
                }

                Console.ReadLine();
            }
            catch (TxException e)
            {
                Console.WriteLine(e);
            }

            return(true);
        }
Пример #17
0
        public void Start()
        {
            try
            {
                //operationArray = ConfigurationManager.AppSettings[APP_SET_TASK].Split(SEP_CHAR_COMMA);
                string commands = tbxOperations.Text.Trim();
                if (!String.IsNullOrEmpty(commands))
                {
                    operationArray = commands.Split(SEP_CHAR_COMMA);
                    string[] tmp;
                    PadInt   padInt = null;
                    foreach (var operation in operationArray)
                    {
                        tmp = operation.Split(SEP_CHAR_COLON);
                        bool status = false;
                        switch (tmp[0])
                        {
                        case BEGIN_TRANSACTION:
                            status = PADI_Client.TxBegin();
                            UpdateResultPanel("Transaction started. " + status);
                            break;

                        case END_TRANSACTION:
                            status = PADI_Client.TxCommit();
                            UpdateResultPanel("Transaction committed. " + status);
                            break;

                        case CREATE_PADINT:
                            padInt = PADI_Client.CreatePadInt(Int32.Parse(tmp[1]));
                            break;

                        case ACCESS_PADINT:
                            padInt = PADI_Client.AccessPadInt(Int32.Parse(tmp[1]));
                            break;

                        case READ:
                            if (padInt != null)
                            {
                                UpdateResultPanel("Read value = " + padInt.Read());
                            }
                            else
                            {
                                UpdateResultPanel("PadInt is null - READ");
                            }
                            break;

                        case WRITE:
                            if (padInt != null)
                            {
                                padInt.Write(Int32.Parse(tmp[1]));
                                UpdateResultPanel("Write issued = " + tmp[1]);
                            }
                            else
                            {
                                Console.WriteLine("PadInt is null - WRITE");
                            }
                            break;

                        case STATUS_DUMP:
                            PADI_Client.Status();
                            UpdateResultPanel("Dumped Status");
                            break;
                        }
                    }
                }
            }
            catch (TxException ex)
            {
                UpdateResultPanel(ex.Message);
            }
            catch (Exception ex)
            {
                UpdateResultPanel(ex.Message);
            }
        }
Пример #18
0
        public void TestCreateTransaction()
        {
            const int UID1  = 10;
            const int UID2  = -10;
            const int WRITE = 5;

            bool result = PadiDstm.Init();

            //Falha create
            bool   beginSuccess = PadiDstm.TxBegin();
            PadInt padInt1      = PadiDstm.CreatePadInt(UID1);

            padInt1.Write(WRITE);
            PadInt padInt2 = PadiDstm.CreatePadInt(UID2);

            padInt1.Write(WRITE);
            PadiDstm.TxAbort();


            //Falha access

            beginSuccess = PadiDstm.TxBegin();
            padInt1      = PadiDstm.AccessPadInt(UID1);
            Assert.IsNull(padInt1);
            padInt2 = PadiDstm.AccessPadInt(UID2);
            Assert.IsNull(padInt2);
            PadiDstm.TxCommit();


            //Pode criar
            beginSuccess = PadiDstm.TxBegin();
            padInt1      = PadiDstm.CreatePadInt(UID1);
            padInt1.Write(WRITE);
            padInt2 = PadiDstm.CreatePadInt(UID2);
            padInt2.Write(WRITE);
            PadiDstm.TxCommit();

            //Pode ler
            beginSuccess = PadiDstm.TxBegin();
            Assert.IsTrue(beginSuccess);

            padInt1 = PadiDstm.AccessPadInt(UID1);
            Assert.IsNotNull(padInt1);
            int r1 = padInt1.Read();

            Assert.AreEqual(r1, WRITE);

            padInt2 = PadiDstm.AccessPadInt(UID2);
            Assert.IsNotNull(padInt2);
            int r2 = padInt2.Read();

            Assert.AreEqual(r2, WRITE);

            PadiDstm.TxCommit();


            //Ja esta criado
            beginSuccess = PadiDstm.TxBegin();
            padInt1      = PadiDstm.CreatePadInt(UID1);
            Assert.IsNull(padInt1);
            padInt2 = PadiDstm.CreatePadInt(UID2);
            Assert.IsNull(padInt1);
            PadiDstm.TxCommit();
        }
Пример #19
0
        public void TestFailWhileInTransactionWithRead()
        {
            const int UID1  = 10;
            const int UID2  = -10;
            const int WRITE = 5;

            bool result = PadiDstm.Init();

            bool   beginSuccess = PadiDstm.TxBegin();
            PadInt padInt1      = PadiDstm.CreatePadInt(UID1);

            padInt1.Write(WRITE);

            PadInt padInt2 = PadiDstm.CreatePadInt(UID2);

            padInt1.Write(WRITE);


            //Servers de 1 a 2
            //Fail do server 1

            server[kill].Kill();


            Thread.Sleep(1000);
            PadiDstm.TxCommit();

            //Depois de falhar
            PadiDstm.Status();


            //Server falhou antes de fazer commit de t1,
            //logo deve

            Thread.Sleep(1000);

            //Server nao consegui fazer commit
            //fez abort dos creates
            //access deve retornar null
            //A seguir cria pad ints e escreve
            beginSuccess = PadiDstm.TxBegin();
            padInt1      = PadiDstm.AccessPadInt(UID1);
            Assert.IsNull(padInt1);

            padInt1 = PadiDstm.CreatePadInt(UID1);
            Assert.IsNotNull(padInt1);
            padInt1.Write(WRITE);

            padInt2 = PadiDstm.AccessPadInt(UID2);
            Assert.IsNull(padInt2);

            padInt2 = PadiDstm.CreatePadInt(UID2);
            Assert.IsNotNull(padInt2);
            padInt2.Write(WRITE);

            PadiDstm.TxCommit();


            //Desta vez vai ter sucesso a
            //aceder
            beginSuccess = PadiDstm.TxBegin();

            padInt1 = PadiDstm.AccessPadInt(UID1);
            Assert.IsNotNull(padInt1);
            int r1 = padInt1.Read();

            Assert.AreEqual(r1, WRITE);

            padInt2 = PadiDstm.AccessPadInt(UID2);
            Assert.IsNotNull(padInt2);
            int r2 = padInt2.Read();

            Assert.AreEqual(r2, WRITE);

            PadiDstm.TxCommit();
        }
Пример #20
0
        public void TestFreezeCreate(int uid0)
        {
            Console.WriteLine("------ Test: Freeze Create ------");
            Logger.Log(new String[] { "Client", "------ Test: Freeze Create ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);


                Console.WriteLine("####################################################################");
                Console.WriteLine("Vou fazer o primeiro ciclo de 5 writes. Depois vem o freeze");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                int i = 0;
                for (; i <= 5; i++)
                {
                    Console.WriteLine("Fiz um Write no uid 1. uid() = " + padInt0.Write(i).ToString());
                }

                Console.WriteLine("####################################################################");
                Console.WriteLine("Vou fazer o freeze Nota: Podem ser imprimidas writas que estao a ser feitas em cache! so vai parar quando fizer pedido ao server");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                // The following 2 lines assume we have 2 servers: one at port 2001 and another at port 2002
                bool res = PadiDstm.Freeze("tcp://localhost:2001/PadIntServer");
                //res = Library.Fail("tcp://localhost:2002/PadIntServer");
                Console.WriteLine("####################################################################");
                Console.WriteLine("Fiz o freeze res= " + res + "Vou fazer o segundo ciclo de 5 writes. Depois vem o commit");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                for (; i <= 10; i++)
                {
                    Console.WriteLine("Fiz um Write no uid 1. uid() = " + padInt0.Write(i).ToString());
                }

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");
                /* the padInt's value must be equal to initialization value */
                PadInt padInt0A = PadiDstm.AccessPadInt(uid0);
                Console.WriteLine("####################################################################");
                Console.WriteLine("Fiz os 10 writes. padInt0A.Read()= " + padInt0A.Read() + " Press enter para commit.");
                Console.WriteLine("####################################################################");
                Console.ReadLine();

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Read Freeze end----------" });
        }
Пример #21
0
    static void Main(string[] args)
    {
        bool res = false;
        int  aborted = 0, committed = 0;

        PadiDstm.Init();
        try {
            if ((args.Length > 0) && (args[0].Equals("C")))
            {
                res = PadiDstm.TxBegin();
                for (int i = 0; i < 10001; i++)
                {
                    PadInt pi_a = PadiDstm.CreatePadInt(i);
                    pi_a.Write(i);
                }
                res = PadiDstm.TxCommit();
            }
            Console.WriteLine("####################################################################");
            Console.WriteLine("Finished creating PadInts. Press enter for sum transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
        } catch (Exception e) {
            Console.WriteLine("Exception: " + e.Message);
            Console.WriteLine("####################################################################");
            Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
            PadiDstm.TxAbort();
        }
        try {
            int    sum = 0;
            PadInt pi_a;
            res = PadiDstm.TxBegin();
            for (int i = 0; i < 9999; i++)
            {
                pi_a = PadiDstm.AccessPadInt(i);
                sum += pi_a.Read();
            }
            Console.WriteLine("sum= " + sum);
            if (args[0].Equals("D1"))
            {
                pi_a = PadiDstm.AccessPadInt(10000);
                pi_a.Write(sum);
            }
            if (args[0].Equals("D2"))
            {
                pi_a = PadiDstm.AccessPadInt(10001);
                pi_a.Write(sum);
            }
            res = PadiDstm.TxCommit();
            if (res)
            {
                committed++; Console.Write(".");
            }
            else
            {
                aborted++;
                Console.WriteLine("$$$$$$$$$$$$$$ ABORT $$$$$$$$$$$$$$$$$");
            }
        } catch (Exception e) {
            Console.WriteLine("Exception: " + e.Message);
            Console.WriteLine("####################################################################");
            Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
            PadiDstm.TxAbort();
            aborted++;
        }


        Console.WriteLine("####################################################################");
        Console.WriteLine("committed = " + committed + " ; aborted = " + aborted);
        Console.WriteLine("Press enter for status.");
        Console.WriteLine("####################################################################");
        Console.ReadLine();
        PadiDstm.Status();
        Console.WriteLine("####################################################################");
        Console.WriteLine("Press enter for verification transaction.");
        Console.WriteLine("####################################################################");

        try {
            res = PadiDstm.TxBegin();
            PadInt pi_g = PadiDstm.AccessPadInt(10000);
            int    g    = pi_g.Read();
            res = PadiDstm.TxCommit();
            Console.WriteLine("####################################################################");
            Console.WriteLine("sum = " + g);
            Console.WriteLine("Status post verification transaction. Press enter for exit.");
            Console.WriteLine("####################################################################");
            PadiDstm.Status();
            Console.ReadLine();
        } catch (Exception e) {
            Console.WriteLine("Exception: " + e.Message);
            Console.WriteLine("####################################################################");
            Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
            PadiDstm.TxAbort();
        }
    }
Пример #22
0
        public void TestFailCreate(int uid0)
        {
            Console.WriteLine("------ Test: Fail Create ------");
            Logger.Log(new String[] { "Client", "------ Test: Fail Create ------" });

            Console.WriteLine("library created");

            try {
                Console.WriteLine("init() Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");

                PadInt padInt0 = PadiDstm.CreatePadInt(uid0);
                Console.WriteLine("padInt0 created with uid: " + uid0);


                Console.WriteLine("####################################################################");
                Console.WriteLine("Vou fazer o primeiro ciclo de 5 writes. Depois vem o fail");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                int i = 0;
                for (; i <= 5; i++)
                {
                    Console.WriteLine("Fiz um Write no uid 1. uid() = " + padInt0.Write(i).ToString());
                }

                Console.WriteLine("####################################################################");
                Console.WriteLine("Vou fazer o fail");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                // The following 2 lines assume we have 2 servers: one at port 2001 and another at port 2002
                //bool res = Library.Freeze("tcp://localhost:2001/PadIntServer");
                bool res = PadiDstm.Fail("tcp://localhost:2001/PadIntServer");
                Console.WriteLine("####################################################################");
                Console.WriteLine("Fiz o fail res= " + res + "Vou fazer o segundo ciclo de 5 writes. Depois vem o commit");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                for (; i <= 10; i++)
                {
                    Console.WriteLine("Fiz um Write no uid 1. uid() = " + padInt0.Write(i).ToString());
                }

                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                PadiDstm.TxBegin();
                Console.WriteLine("txBegin Done");
                PadInt padInt0A = PadiDstm.AccessPadInt(uid0);
                Console.WriteLine("####################################################################");
                Console.WriteLine("Fiz os 10 writes. padInt0A.Read()= " + padInt0A.Read() + " Press enter para commit.");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                PadiDstm.TxCommit();
                Console.WriteLine("txCommit Done");

                Console.WriteLine("closeChannel Done");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------Read Fail end----------" });
        }
Пример #23
0
        public void CicleTest()
        {
            bool res = false; int aborted = 0, committed = 0;

            PadiDstm.Init();
            try
            {
                //if ((args.Length > 0) && (args[0].Equals("C"))) {
                res = PadiDstm.TxBegin();
                PadInt pi_a = PadiDstm.CreatePadInt(2);
                Assert.IsNotNull(pi_a, "Padint a failed to create.");
                PadInt pi_b = PadiDstm.CreatePadInt(2000000001);
                Assert.IsNotNull(pi_b, "Padint b failed to create.");
                PadInt pi_c = PadiDstm.CreatePadInt(1000000000);
                Assert.IsNotNull(pi_c, "Padint c failed to create.");
                pi_a.Write(0);
                pi_b.Write(0);
                res = PadiDstm.TxCommit();
                Assert.IsTrue(res, "Failed to commit first transaction.");
                //}
                Console.WriteLine("####################################################################");
                Console.WriteLine("Finished creating PadInts. Press enter for 300 R/W transaction cycle.");
                Console.WriteLine("####################################################################");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                Console.WriteLine("####################################################################");
                Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
                Console.WriteLine("####################################################################");
                PadiDstm.TxAbort();
                Assert.Fail("Failed to commit first transaction.");
            }
            int previousD = 0;
            int previousE = 0;
            int previousF = 0;

            for (int i = 0; i < 300; i++)
            {
                try
                {
                    res = PadiDstm.TxBegin();
                    PadInt pi_d = PadiDstm.AccessPadInt(2);
                    Assert.IsNotNull(pi_d, "Padint a failed to access.");
                    PadInt pi_e = PadiDstm.AccessPadInt(2000000001);
                    Assert.IsNotNull(pi_e, "Padint e failed to access.");
                    PadInt pi_f = PadiDstm.AccessPadInt(1000000000);
                    Assert.IsNotNull(pi_f, "Padint f failed to access.");

                    int d = pi_d.Read();
                    Assert.AreEqual(previousD, d, "Object d does not have a consistent value.");
                    d++;
                    pi_d.Write(d);
                    previousD = d;
                    int e = pi_e.Read();
                    Assert.AreEqual(previousE, e, "Object e does not have a consistent value.");
                    e++;
                    pi_e.Write(e);
                    previousE = e;
                    int f = pi_f.Read();
                    Assert.AreEqual(previousF, f, "Object f does not have a consistent value.");
                    f++;
                    pi_f.Write(f);
                    previousF = f;
                    Console.Write(".");
                    res = PadiDstm.TxCommit();
                    Assert.IsTrue(res, "Failed to commit second transaction.");
                    if (res)
                    {
                        committed++; Console.Write(".");
                    }
                    else
                    {
                        aborted++;
                        Console.WriteLine("$$$$$$$$$$$$$$ ABORT $$$$$$$$$$$$$$$$$");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception: " + e.Message);
                    Console.WriteLine("####################################################################");
                    Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
                    Console.WriteLine("####################################################################");
                    PadiDstm.TxAbort();
                    aborted++;
                }
            }
            Console.WriteLine("####################################################################");
            Console.WriteLine("committed = " + committed + " ; aborted = " + aborted);
            Console.WriteLine("Status after cycle. Press enter for verification transaction.");
            Console.WriteLine("####################################################################");
            PadiDstm.Status();

            try
            {
                res = PadiDstm.TxBegin();
                PadInt pi_g = PadiDstm.AccessPadInt(2);
                PadInt pi_h = PadiDstm.AccessPadInt(2000000001);
                PadInt pi_j = PadiDstm.AccessPadInt(1000000000);
                int    g    = pi_g.Read();
                Assert.AreEqual(previousD, g, "Object g does not have a consistent value.");
                int h = pi_h.Read();
                Assert.AreEqual(previousE, h, "Object d does not have a consistent value.");
                int j = pi_j.Read();
                Assert.AreEqual(previousF, j, "Object d does not have a consistent value.");
                res = PadiDstm.TxCommit();
                Assert.IsTrue(res, "Failed to commit last transaction.");
                Console.WriteLine("####################################################################");
                Console.WriteLine("2 = " + g);
                Console.WriteLine("2000000001 = " + h);
                Console.WriteLine("1000000000 = " + j);
                Console.WriteLine("Status post verification transaction. Press enter for exit.");
                Console.WriteLine("####################################################################");
                PadiDstm.Status();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                Console.WriteLine("####################################################################");
                Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
                Console.WriteLine("####################################################################");
                PadiDstm.TxAbort();
                Assert.IsTrue(res, "Failed to commit last transaction.");
            }
        }
Пример #24
0
        static void Main(string[] args)
        {
            Common.Logger().LogInfo("Client started", string.Empty, string.Empty);
            // ClientForm f = new ClientForm();
            // Application.Run(f);
            // Client c = new Client();
            //  c.Start();

            try
            {
                bool res;

                PADI_Client.Init();
                //  res = PADI_Client.TxBegin();
                //  PADI_Client.Status();
                //  PADI_Client.TxAbort();
                //  Console.ReadLine();
                // res = PADI_Client.Fail("tcp://127.0.0.1:25051/PADI_Worker");
                // res = PADI_Client.Recover("tcp://127.0.0.1:25051/PADI_Worker");
                // Thread.Sleep(5000);

                /*    res = PADI_Client.TxBegin();
                 *   PadInt pi_a = PADI_Client.CreatePadInt(0);
                 *   PadInt pi_b = PADI_Client.CreatePadInt(1);
                 *   PadInt pi_c = PADI_Client.CreatePadInt(2);
                 *    pi_a.Write(33);
                 *    pi_b.Write(34);
                 *    pi_c.Write(35);
                 *   res = PADI_Client.TxCommit();
                 *   PADI_Client.Status(); */


                res = PADI_Client.TxBegin();
                PadInt pi_a = PADI_Client.AccessPadInt(0);
                if (pi_a == null)
                {
                    pi_a = PADI_Client.CreatePadInt(0);
                }
                PadInt pi_b = PADI_Client.AccessPadInt(1);
                if (pi_b == null)
                {
                    pi_b = PADI_Client.CreatePadInt(1);
                }
                PadInt pi_c = PADI_Client.AccessPadInt(2);
                if (pi_c == null)
                {
                    pi_c = PADI_Client.CreatePadInt(2);
                }
                pi_a.Write(101);
                pi_b.Write(102);
                pi_c.Write(103);
                res = PADI_Client.TxCommit();
                PADI_Client.Status();

                Console.WriteLine("Press enter to check timeout");
                Console.ReadLine();

                res  = PADI_Client.TxBegin();
                pi_c = PADI_Client.AccessPadInt(2);
                pi_c.Write(500);
                Console.WriteLine("Checking whether this will automatically timeout");
                Console.ReadLine();
                res = PADI_Client.TxCommit();
                PADI_Client.Status();

                Console.ReadLine();

                int index = 1500;
                while (true)
                {
                    try
                    {
                        res  = PADI_Client.TxBegin();
                        pi_a = PADI_Client.AccessPadInt(0);
                        pi_b = PADI_Client.AccessPadInt(1);
                        pi_c = PADI_Client.AccessPadInt(2);
                        if (index % 6 == 0)
                        {
                            Console.WriteLine(pi_a.Read() + ", " + pi_b.Read() + ", " + pi_c.Read());
                        }
                        Thread.Sleep(500);
                        pi_a.Write(index);
                        pi_b.Write(index * 3);
                        pi_c.Write(index * 5);
                        if (index == 1700)
                        {
                            Console.WriteLine("Enter to finish....");
                            Console.ReadLine();
                            PADI_Client.TxCommit();
                            break;
                        }
                        index++;
                        PADI_Client.TxCommit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                PADI_Client.Status();



                /*     res = PADI_Client.TxBegin();
                 *   pi_a = PADI_Client.CreatePadInt(4);
                 *   pi_a.Write(200);
                 *   PADI_Client.Status();
                 *   Console.ReadLine();
                 *   pi_a = PADI_Client.CreatePadInt(5);
                 *   pi_a.Write(300);
                 *   res = PADI_Client.TxCommit();
                 *   PADI_Client.Status();
                 *
                 *   Console.ReadLine();  */

                /*    PADI_Client.TxBegin();
                 *  PadInt a = PADI_Client.AccessPadInt(5);
                 *  Console.WriteLine(a.Read());
                 *
                 *  PadInt b = PADI_Client.AccessPadInt(3);
                 *  Console.WriteLine(b.Read());
                 *  PADI_Client.TxCommit();
                 *  PADI_Client.Status(); */

                /*  res = PADI_Client.TxBegin();
                 * PADI_Client.Freeze("tcp://localhost:25051/PADI_Worker");
                 * pi_a = PADI_Client.AccessPadInt(0);
                 * pi_b = PADI_Client.AccessPadInt(1);
                 * pi_a.Write(36);
                 * pi_b.Write(37);
                 * Console.WriteLine("a = " + pi_a.Read());
                 * Console.WriteLine("b = " + pi_b.Read());
                 * res = PADI_Client.Recover("tcp://localhost:25051/PADI_Worker");
                 * PADI_Client.Status();
                 * // The following 3 lines assume we have 2 servers: one at port 2001 and another at port 2002
                 * // res = PADI_Client.Freeze("tcp://localhost:25052/PADI_Worker");
                 * // res = PADI_Client.Recover("tcp://localhost:25052/PADI_Worker");
                 *
                 * res = PADI_Client.TxCommit();*/
            }
            catch (TxException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.Status();
            }
            catch (Exception ex)
            {
                // Console.WriteLine(ex.Message);
                //Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                // PADI_Client.TxAbort();
            }
            finally
            {
                Console.WriteLine("-----------Client execution ended----------");
                Console.ReadLine();
            }
        }
Пример #25
0
    static void Main(string[] args)
    {
        bool res = false; int aborted = 0, committed = 0;

        PadiDstm.Init();
        String key = Console.ReadLine();

        if (key.Equals("C"))
        {
            args = new String[] { "C" };
        }
        Stopwatch sw = Stopwatch.StartNew();

        try
        {
            if ((args.Length > 0) && (args[0].Equals("C")))
            {
                res = PadiDstm.TxBegin();
                PadInt pi_a = PadiDstm.CreatePadInt(2);
                PadInt pi_b = PadiDstm.CreatePadInt(12);
                PadInt pi_c = PadiDstm.CreatePadInt(20);
                pi_a.Write(0);
                pi_b.Write(0);
                res = PadiDstm.TxCommit();
            }
            Console.WriteLine("####################################################################");
            Console.WriteLine("Finished creating PadInts. Press enter for 300 R/W transaction cycle.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
            Console.WriteLine("####################################################################");
            Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
            PadiDstm.TxAbort();
        }
        for (int i = 0; i < 300; i++)
        {
            try
            {
                res = PadiDstm.TxBegin();
                PadInt pi_d = PadiDstm.AccessPadInt(2);
                PadInt pi_e = PadiDstm.AccessPadInt(12);
                PadInt pi_f = PadiDstm.AccessPadInt(20);
                int    d    = pi_d.Read();
                d++;
                pi_d.Write(d);
                int e = pi_e.Read();
                e++;
                pi_e.Write(e);
                int f = pi_f.Read();
                f++;
                pi_f.Write(f);
                Console.Write(".");
                res = PadiDstm.TxCommit();
                if (res)
                {
                    committed++; Console.Write(".");
                }
                else
                {
                    aborted++;
                    Console.WriteLine("$$$$$$$$$$$$$$ ABORT $$$$$$$$$$$$$$$$$");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                Console.WriteLine("####################################################################");
                Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
                Console.WriteLine("####################################################################");
                Console.ReadLine();
                PadiDstm.TxAbort();
                aborted++;
            }
        }
        Console.WriteLine("####################################################################");
        Console.WriteLine("committed = " + committed + " ; aborted = " + aborted);
        Console.WriteLine("Status after cycle. Press enter for verification transaction.");
        Console.WriteLine("####################################################################");
        PadiDstm.Status();
        Console.ReadLine();

        try
        {
            res = PadiDstm.TxBegin();
            PadInt pi_g = PadiDstm.AccessPadInt(2);
            PadInt pi_h = PadiDstm.AccessPadInt(12);
            PadInt pi_j = PadiDstm.AccessPadInt(20);
            int    g    = pi_g.Read();
            int    h    = pi_h.Read();
            int    j    = pi_j.Read();
            res = PadiDstm.TxCommit();
            Console.WriteLine("####################################################################");
            Console.WriteLine("2 = " + g);
            Console.WriteLine("2000000001 = " + h);
            Console.WriteLine("1000000000 = " + j);
            Console.WriteLine("Status post verification transaction. Press enter for exit.");
            Console.WriteLine("####################################################################");
            PadiDstm.Status();
            Console.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
            Console.WriteLine("####################################################################");
            Console.WriteLine("AFTER create ABORT. Commit returned " + res + " . Press enter for abort and next transaction.");
            Console.WriteLine("####################################################################");
            Console.ReadLine();
            PadiDstm.TxAbort();
        }
        sw.Stop();
        Console.WriteLine("{Total time (ms) : " + (long)sw.ElapsedMilliseconds);
        Console.ReadLine();
    }
Пример #26
0
        public void Start()
        {
            try
            {
                for (int i = 0; i < Int32.Parse(ConfigurationManager.AppSettings[APP_SET_SLEEP_TIME]); i++)
                {
                    Console.WriteLine("Starts : " + (Int32.Parse(ConfigurationManager.AppSettings[APP_SET_SLEEP_TIME]) - i));
                    Thread.Sleep(1000);
                }
                operationArray = ConfigurationManager.AppSettings[APP_SET_TASK].Split(SEP_CHAR_COMMA);
                string[] tmp;
                PadInt   padInt = null;
                foreach (var operation in operationArray)
                {
                    tmp = operation.Split(SEP_CHAR_HYPHEN);
                    bool status = false;
                    switch (tmp[0])
                    {
                    case BEGIN_TRANSACTION:
                        status = PADI_Client.TxBegin();
                        Console.WriteLine("Transaction started. " + status);
                        break;

                    case END_TRANSACTION:
                        status = PADI_Client.TxCommit();
                        Console.WriteLine("Transaction committed. " + status);
                        break;

                    case CREATE_PADINT:
                        padInt = PADI_Client.CreatePadInt(Int32.Parse(tmp[1]));
                        break;

                    case ACCESS_PADINT:
                        padInt = PADI_Client.AccessPadInt(Int32.Parse(tmp[1]));
                        break;

                    case READ:
                        if (padInt != null)
                        {
                            Console.WriteLine("Read value = " + padInt.Read());
                        }
                        else
                        {
                            Console.WriteLine("PadInt is null - READ");
                        }
                        break;

                    case WRITE:
                        if (padInt != null)
                        {
                            padInt.Write(Int32.Parse(tmp[1]));
                            Console.WriteLine("Write issued = " + tmp[1]);
                        }
                        else
                        {
                            Console.WriteLine("PadInt is null - WRITE");
                        }
                        break;

                    case STATUS_DUMP:
                        PADI_Client.Status();
                        Console.WriteLine("Dumped Status");
                        break;

                    case FREEZE:
                        PADI_Client.Freeze(tmp[1]);
                        break;

                    case FAIL:
                        PADI_Client.Fail(tmp[1]);
                        break;

                    case RECOVER:
                        PADI_Client.Recover(tmp[1]);
                        Thread.Sleep(5000);     //wait until it stables
                        break;

                    default:
                        Console.WriteLine("Invalid input");
                        break;
                    }
                }
            }
            catch (TxException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.Status();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.TxAbort();
            }
            finally
            {
                Console.WriteLine("-----------Client execution ended----------");
                Console.ReadLine();
            }
        }