예제 #1
0
 public bool TestAccessNonCreatedPadInt()
 {
     // Test2: tries to access a non-created PadInt
     // Expected result: exception or error message - PadInt 1 does not exist
     launchMaster();
     launchTwoServers();
     try {
         bool   res  = PadiDstm.TxBegin();
         PadInt pi_b = PadiDstm.CreatePadInt(0);
         pi_b = PadiDstm.AccessPadInt(1);
         if (pi_b == null)
         {
             throw new Exception("Trying to access a non created PadInt.");
         }
         res = PadiDstm.TxCommit();
         //Assert.Fail("No exception thrown!"); // não deve chegar aqui!
         master.Kill();
         server1.Kill();
         server2.Kill();
         return(res);
     } catch (Exception e) {
         Console.WriteLine("TestAccessNonCreatedPadInt error: " + e);
         master.Kill();
         server1.Kill();
         server2.Kill();
         return(false);
     }
 }
예제 #2
0
    /* Library tests */

    public bool TestCommandsWithNoTransaction()
    {
        // Test1: tries to call all the commands before starting a transaction
        // Expected result: exception or error message - must start a transaction
        launchMaster();
        launchTwoServers();
        try {
            PadInt pi_a = PadiDstm.CreatePadInt(0);
            pi_a = PadiDstm.AccessPadInt(0);
            pi_a.Read();

            /*if (pi_a == null) {
             *  throw new Exception("Trying to access an object before starting a transaction.");
             * }*/
            //pi_a.Read();
            //pi_a.Write(36);
            //Assert.Fail("No exception thrown!"); // não deve chegar aqui!
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(true);
        } catch (TxException e) {
            Console.WriteLine("TestCommandsWithNoTransaction Exception:" + e);
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(false);
        }
    }
예제 #3
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);
        }
    }
예제 #4
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.");
        }
예제 #5
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);
        }
    }
예제 #6
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);
        }