コード例 #1
0
 public bool TestCreateDuplicatePadInt()
 {
     // Test3: tries to create an already existant PadInt
     // Expected result: exception or error message - PadInt 0 already exists
     launchMaster();
     launchTwoServers();
     try {
         bool   res  = PadiDstm.TxBegin();
         PadInt pi_c = PadiDstm.CreatePadInt(0);
         PadInt pi_d = PadiDstm.CreatePadInt(0);
         if (pi_d == null)
         {
             throw new Exception("Trying to create duplicate 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("TestCreateDuplicatePadInt error: " + e);
         master.Kill();
         server1.Kill();
         server2.Kill();
         return(false);
     }
 }
コード例 #2
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);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: gayana06/padi
 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);
     }
 }
コード例 #4
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);
        }
    }
コード例 #5
0
 public void connect(int slavePort)
 {
     try {
         _slavePort   = slavePort;
         _slaveServer = (IDataServer)Activator.GetObject(typeof(IDataServer), PortToUrl(_slavePort));
         Console.WriteLine("Backup ServerAt{0} registered", slavePort);
         SerializableDictionary <int, int> updateall = new SerializableDictionary <int, int> ();
         foreach (DictionaryEntry pair in PadInts)
         {
             Console.WriteLine("{0}={1}", pair.Key, pair.Value);
             int    a = (int)pair.Key;
             PadInt b = (PadInt)pair.Value;
             int    c = b.Value;
             updateall.Add(a, c);
         }
         _slaveServer.receiveUpdateAll(updateall);
         if (_isPrimary)
         {
             Console.WriteLine(" Connected with the Slave at: " + PortToUrl(_slavePort));
             pingService = new Ping(_slaveServer, this);
             pingService.StartReceive();
         }
     } catch (RemotingException re) {
         Console.WriteLine("[connect]:\n" + re);
         throw new OperationException("Server " + name + "cannot connect: SlaveServer is not avaiable.");
     }
 }
コード例 #6
0
    /* Round Robin atribution tests */

    /*
     * public bool TestCreateTwoPadIntsOneServerDown() {
     *  // Test4: Creates two PadInts when one server is down
     *  // Expected result: both padInts assigned to the same server (2002)
     *  launchMaster();
     *  launchTwoServers();
     *  try {
     *      bool res = PadiDstm.TxBegin();
     *      res = PadiDstm.Fail("tcp://localhost:2001/Server");
     *      PadInt pi_d = PadiDstm.CreatePadInt(1);
     *      PadInt pi_e = PadiDstm.CreatePadInt(2);
     *      res = PadiDstm.TxCommit();
     *          master.Kill();
     *          server1.Kill();
     *          server2.Kill();
     *      return res;
     *  } catch (TxException e) {
     *      Console.WriteLine("TestCreateTwoPadIntsOneServerDown error: " + e);
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return false;
     *  }
     * }
     */

    /*
     * public bool TestCreateTwoPadIntsAfterFailedServerRecover(){
     *  // Test5: Recovers the failed server and tries to create another pair of PadInts
     *  // Expected result: one padInt assigned to each server
     *  launchMaster();
     *  launchTwoServers();
     *  try {
     *      bool res = PadiDstm.TxBegin();
     *      res = PadiDstm.Fail("tcp://localhost:2001/Server");
     *      res = PadiDstm.Recover("tcp://localhost:2001/Server"); // vinha do metodo anterior
     *      PadInt pi_f = PadiDstm.CreatePadInt(3);
     *      PadInt pi_g = PadiDstm.CreatePadInt(4);
     *      res = PadiDstm.TxCommit();
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return res;
     *  } catch (TxException e) {
     *      Console.WriteLine("TestCreateTwoPadIntsAfterFailedServerRecover error: " + e);
     *      master.Kill();
     *      server1.Kill();
     *      server2.Kill();
     *      return false;
     *  }
     * }
     */

    public bool TestCreateTwoPadIntsBothServersFailed()
    {
        // Test6: Fails both servers and tries to create two padInts
        // Expected result: exception or error message
        launchMaster();
        launchTwoServers();
        try {
            bool res = PadiDstm.TxBegin();
            res = PadiDstm.Fail("tcp://localhost:2001/Server");
            res = PadiDstm.Fail("tcp://localhost:2002/Server");
            PadInt pi_h = PadiDstm.CreatePadInt(5);
            PadInt pi_i = PadiDstm.CreatePadInt(6);
            if ((pi_i == null) || (pi_h == null))
            {
                throw new Exception("No data servers avaiable, can't create PadInts.");
            }
            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("TestCreateTwoPadIntsBothServersFailed error: " + e);
            master.Kill();
            server1.Kill();
            server2.Kill();
            return(false);
        }
    }
コード例 #7
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);
        }
    }
コード例 #8
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();
    }
コード例 #9
0
 public IPadInt store(int uid)
 {
     lock (_stateLockObj) {
         if (isFail)
         {
             Console.WriteLine("[!STORE] Error: DataServer " + name + " is set to [Fail] mode!");
             Console.WriteLine("---");
             while (true)
             {
                 ;
             }
             //throw new RemotingException("Server is in Fail Mode");
         }
         else if (isFreeze)
         {
             lock (SingletonCounter.Instance) {
                 SingletonCounter.Instance.incrementLockCounter();
                 Monitor.Wait(SingletonCounter.Instance);
             }
         }
     }
     if (!padInts.Contains(uid))
     {
         PadInt obj = new PadInt(uid, this);
         padInts.Add(uid, obj);
         if (_isPrimary)
         {
             _slaveServer.store(uid);
         }
         Console.WriteLine("[STORE] DataServer " + name + " stored PadInt " + uid);
         Console.WriteLine("---");
         return(obj);
     }
     return(null);
 }
コード例 #10
0
ファイル: TestFail.cs プロジェクト: BrunoMCBraga/PADI-DSTM
        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();
        }
コード例 #11
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----------" });
        }
コード例 #12
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);
        }
コード例 #13
0
 public ServerTransaction(int txId, PadInt Obj)
 {
     this.txId      = txId;
     copies         = new SerializableDictionary <PadInt, int>();
     valuestobackup = new SerializableDictionary <int, int>();
     copies.Add(Obj, Obj.Value);
     abort      = false;
     locksStack = new Stack <Lock>();
 }
コード例 #14
0
        public void FailOnDuplicate()
        {
            PadInt pad = proxy.CreatePadInt(PAD_ID);

            Assert.IsNotNull(pad, "Failed to create first padInt");

            pad = proxy.CreatePadInt(PAD_ID);

            Assert.IsNull(pad, "Duplicated padint created");
        }
コード例 #15
0
 public void receiveUpdateAll(SerializableDictionary <int, int> updatesx)
 {
     foreach (KeyValuePair <int, int> pair in updatesx)
     {
         store(pair.Key);
         PadInt p = (PadInt)padInts[pair.Key];
         p.Value = pair.Value;
         Console.WriteLine("Updating {0}={1}", pair.Key, pair.Value);
     }
 }
コード例 #16
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----------" });
        }
コード例 #17
0
        public PadInt AccessPadInt(int uid)
        {
            IServer server = null;
            PadInt  remote = null;


            try
            {
                server = lookupService.GetServer(uid);

                Console.WriteLine("server: " + uid + " ");

                remote = server.AccessPadInt(currentTid, uid);
                if (remote == null)
                {
                    Console.WriteLine("remote null");
                }
                Console.WriteLine("remote uid: " + uid);
            }
            catch (SocketException e)
            {
                Console.WriteLine("exception: " + e.Message);

                //Recuperacao
                masterService.Master.RemoveServer(lookupService.GetServerEndpoint(uid));

                //Recuperacao concluida
                //Tenta executar novamente
                //lookupService.AddParticipant(currentTid, uid);

                server = lookupService.GetServer(uid);



                AccessPadInt(uid);

                //throw new NotImplementedException(); //////////////////////////////////////////////tEMOS DE IMPLEMENTAR ISTO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }


            if (remote == null)
            {
                return(null);
            }

            int value = remote.Read();

            PadIntLocal local = new PadIntLocal(uid, value);

            local.changeHandler += this.OnPadintChange;
            local.readHandler   += this.OnPadintRead;

            return(local);
        }
コード例 #18
0
 public void receiveupdatefromprimary(SerializableDictionary <int, int> updatetobackup, int Tid)
 {
     foreach (KeyValuePair <int, int> entry in updatetobackup)
     {
         if (padInts.Contains(entry.Key))
         {
             PadInt p = (PadInt)padInts[entry.Key];
             p.Value = entry.Value;
             Console.WriteLine("<Debug Mode> Padint with id: " + p.Id + "has now the value: " + p.Value);
         }
     }
     _lastTransactionId = Tid;
     Console.WriteLine("Received update from primary according to the transaction id: " + Tid);
 }
コード例 #19
0
ファイル: ClientUI.cs プロジェクト: franciscofreire/padi-dstm
 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);
     }
 }
コード例 #20
0
            public void reportFailure()
            {
                foreach (DictionaryEntry pair in PadInts)
                {
                    PadInt b = (PadInt)pair.Value;
                    b.changeServer(this);
                }
                //_masterServer.registerNewPrimaryServer(_url, _Id);
                // Quero passar é o id do primary que vou substiruir!!! (Neste caso id = port)
                _masterServer.registerNewPrimaryServer(_url, _primaryPort);

                // lança no master;
                _isPrimary   = true;
                _primaryPort = 0;
            }
コード例 #21
0
        public PadInt CreatePadInt(int uid)
        {
            IServer server = null;
            PadInt  padInt = null;

            try
            {
                server = lookupService.GetServer(uid);

                if (currentTid == 0)
                {
                    currentTid = server.GetTid();
                }

                lookupService.AddParticipant(currentTid, uid);
                padInt = server.CreatePadInt(currentTid, uid);
            }
            catch (SocketException e)
            {
                //Recuperacao
                masterService.Master.RemoveServer(lookupService.GetServerEndpoint(uid));

                CreatePadInt(uid);


                //throw new NotImplementedException(); //////////////////////////////////////////////tEMOS DE IMPLEMENTAR ISTO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }


            if (padInt == null)
            {
                return(null);
            }


            PadIntLocal local = new PadIntLocal(uid);

            if (local == null)
            {
                return(null);
            }


            local.changeHandler += this.OnPadintChange;
            local.readHandler   += this.OnPadintRead;

            return(local);
        }
コード例 #22
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.");
        }
コード例 #23
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----------" });
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: gayana06/padi
 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);
     }
 }
コード例 #25
0
        public void TestMultipleRead(int uid0, int uid1, int uid2)
        {
            Console.WriteLine("------ Test: Multiple read ------");
            Logger.Log(new String[] { "Client", "------ Test: Multiple read ------" });

            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);
                PadInt padInt1 = PadiDstm.CreatePadInt(uid1);
                Console.WriteLine("padInt1 created with uid: " + uid1);
                PadInt padInt2 = PadiDstm.CreatePadInt(uid2);
                Console.WriteLine("padInt2 created with uid: " + uid2);

                bool result = padInt0.Read() == 0;
                result = (padInt0.Read() == padInt1.Read());
                result = (padInt0.Read() == padInt2.Read());

                if (result)
                {
                    Console.WriteLine("it's OK");
                }
                else
                {
                    Console.WriteLine("BUG!!!!!: multiple read was not successful...");
                }

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

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

            Console.WriteLine("------------");
            Logger.Log(new String[] { "---------multiple read end----------" });
        }
コード例 #26
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----------" });
        }
コード例 #27
0
ファイル: ClientUI.cs プロジェクト: franciscofreire/padi-dstm
            private void accessButton_Click(object sender, EventArgs e)
            {
                int id = Convert.ToInt32(accessTextBox.Text);

                _createdObj = PadiDstm.AccessPadInt(id);
                if (!(_createdObj == null))
                {
                    if (!myObjects.Contains(id))
                    {
                        myObjects.Add(id, _createdObj);
                        listBox.Items.Add("Id:" + id);
                    }
                }
                else
                {
                    MessageBox.Show("PadInt with id " + id + " does not exists!",
                                    "AccessPadInt",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
コード例 #28
0
ファイル: ClientUI.cs プロジェクト: franciscofreire/padi-dstm
            private void readButton_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];

                    // NOSSO BUG:
                    // O server no myObjects nao é actualizado
                    //statusTextBox.AppendText(obj.Remote.Server.ToString()); // rebenta

                    int value = obj.Read();
                    readTextBox.Text = value.ToString();
                    listBox.ClearSelected();
                } catch (TxException te) {
                    statusTextBox.AppendText("Cannot Read, transaction " + te.Tid + " . Reason: " + te.Msg + ".\r\n");
                }
            }
コード例 #29
0
ファイル: ClientUI.cs プロジェクト: franciscofreire/padi-dstm
            private void failButton_Click(object sender, EventArgs e)
            {
                ArrayList aux = new ArrayList();

                // Vai haver um fail, vou eliminar os objectos deste server do myObjects e da minha listBox
                // porque nao se consegue actualizar as referencias para o server velho aqui :(
                foreach (DictionaryEntry pair in myObjects)
                {
                    PadInt p      = (PadInt)pair.Value;
                    int    pIndex = (int)pair.Key;
                    int    res    = String.Compare(p.Remote.Server, failTextBox.Text.ToString());
                    if (res == 0)
                    {
                        aux.Add(pIndex);
                    }
                }
                foreach (int x in aux)
                {
                    myObjects.Remove(x);
                    listBox.Items.RemoveAt(x - 1);
                }
                PadiDstm.Fail(failTextBox.Text.ToString());
            }
コード例 #30
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();
        }