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(); }
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); } }
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."); }
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----------" }); }
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"); } }
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(); }
public void CrossedLocksTest() { bool res = false; PadInt pi_a, pi_b; PadiDstm.Init(); // if ((args.Length > 0) && (args[0].Equals("C"))) // { try { res = PadiDstm.TxBegin(); Assert.IsTrue(res, "Failed to begin first transaction."); pi_a = PadiDstm.CreatePadInt(1); Assert.IsNotNull(pi_a, "Failed to create padint a."); pi_b = PadiDstm.CreatePadInt(2000000000); Assert.IsNotNull(pi_b, "Failed to create padint b."); Console.WriteLine("####################################################################"); Console.WriteLine("BEFORE create commit. Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); res = PadiDstm.TxCommit(); Assert.IsTrue(res, "Failed to commit first transaction."); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER create commit. commit = " + res + " . Press enter for next transaction."); 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 finalize first transaction."); } // } try { res = PadiDstm.TxBegin(); Assert.IsTrue(res, "Failed to begin second transaction."); // if ((args.Length > 0) && ((args[0].Equals("A")) || (args[0].Equals("C")))) // { pi_b = PadiDstm.AccessPadInt(2000000000); Assert.IsNotNull(pi_b, "Failed to access padint 2000000000 on second transaction."); pi_b.Write(211); Console.WriteLine("####################################################################"); Console.WriteLine("Status post first op: write. Press enter for second op."); Console.WriteLine("####################################################################"); PadiDstm.Status(); pi_a = PadiDstm.AccessPadInt(1); Assert.IsNotNull(pi_a, "Failed to access padint 1 on second transaction."); //pi_a.Write(212); Console.WriteLine("####################################################################"); Console.WriteLine("Status post second op: read. uid(1)= " + pi_a.Read() + ". Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); // } // else // { pi_a = PadiDstm.AccessPadInt(1); Assert.IsNotNull(pi_a, "Failed to access padint 1 on second transaction."); pi_a.Write(221); Console.WriteLine("####################################################################"); Console.WriteLine("Status post first op: write. Press enter for second op."); Console.WriteLine("####################################################################"); PadiDstm.Status(); pi_b = PadiDstm.AccessPadInt(2000000000); Assert.IsNotNull(pi_b, "Failed to access padint 2000000000 on second transaction."); //pi_b.Write(222); Console.WriteLine("####################################################################"); Console.WriteLine("Status post second op: read. uid(1)= " + pi_b.Read() + ". Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); //} res = PadiDstm.TxCommit(); Assert.IsTrue(res, "Failed to commit second transaction"); Console.WriteLine("####################################################################"); Console.WriteLine("commit = " + res + " . Press enter for verification transaction."); Console.WriteLine("####################################################################"); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER r/w ABORT. Commit returned " + res + " . Press enter for abort and next transaction."); Console.WriteLine("####################################################################"); PadiDstm.TxAbort(); } try { res = PadiDstm.TxBegin(); PadInt pi_c = PadiDstm.AccessPadInt(1); PadInt pi_d = PadiDstm.AccessPadInt(2000000000); Console.WriteLine("0 = " + pi_c.Read()); Console.WriteLine("2000000000 = " + pi_d.Read()); Console.WriteLine("####################################################################"); Console.WriteLine("Status after verification read. Press enter for verification commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); res = PadiDstm.TxCommit(); Assert.IsTrue(res, "Failed to commit third transaction."); Console.WriteLine("####################################################################"); Console.WriteLine("commit = " + res + " . Press enter for exit."); Console.WriteLine("####################################################################"); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER verification ABORT. Commit returned " + res + " . Press enter for abort and exit."); Console.WriteLine("####################################################################"); PadiDstm.TxAbort(); Assert.Fail("Exception block. Failed to commit."); } }
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(); } }
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."); } }
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(); } }
static void Main(string[] args) { bool res = false; PadInt pi_a, pi_b; PadiDstm.Init(); if ((args.Length > 0) && (args[0].Equals("C"))) { try{ res = PadiDstm.TxBegin(); pi_a = PadiDstm.CreatePadInt(1); pi_b = PadiDstm.CreatePadInt(2000000000); Console.WriteLine("####################################################################"); Console.WriteLine("BEFORE create commit. Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); Console.ReadLine(); res = PadiDstm.TxCommit(); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER create commit. commit = " + res + " . Press enter for next 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 { res = PadiDstm.TxBegin(); if ((args.Length > 0) && ((args[0].Equals("A")) || (args[0].Equals("C")))) { pi_b = PadiDstm.AccessPadInt(2000000000); pi_b.Write(211); Console.WriteLine("####################################################################"); Console.WriteLine("Status post first op: write. Press enter for second op."); Console.WriteLine("####################################################################"); PadiDstm.Status(); Console.ReadLine(); pi_a = PadiDstm.AccessPadInt(1); //pi_a.Write(212); Console.WriteLine("####################################################################"); Console.WriteLine("Status post second op: read. uid(1)= " + pi_a.Read() + ". Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); Console.ReadLine(); } else { pi_a = PadiDstm.AccessPadInt(1); pi_a.Write(221); Console.WriteLine("####################################################################"); Console.WriteLine("Status post first op: write. Press enter for second op."); Console.WriteLine("####################################################################"); PadiDstm.Status(); Console.ReadLine(); pi_b = PadiDstm.AccessPadInt(2000000000); //pi_b.Write(222); Console.WriteLine("####################################################################"); Console.WriteLine("Status post second op: read. uid(1)= " + pi_b.Read() + ". Press enter for commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); Console.ReadLine(); } res = PadiDstm.TxCommit(); Console.WriteLine("####################################################################"); Console.WriteLine("commit = " + res + " . Press enter for verification transaction."); Console.WriteLine("####################################################################"); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER r/w ABORT. Commit returned " + res + " . Press enter for abort and next transaction."); Console.WriteLine("####################################################################"); Console.ReadLine(); PadiDstm.TxAbort(); } try { res = PadiDstm.TxBegin(); PadInt pi_c = PadiDstm.AccessPadInt(1); PadInt pi_d = PadiDstm.AccessPadInt(2000000000); Console.WriteLine("0 = " + pi_c.Read()); Console.WriteLine("2000000000 = " + pi_d.Read()); Console.WriteLine("####################################################################"); Console.WriteLine("Status after verification read. Press enter for verification commit."); Console.WriteLine("####################################################################"); PadiDstm.Status(); res = PadiDstm.TxCommit(); Console.WriteLine("####################################################################"); Console.WriteLine("commit = " + res + " . Press enter for exit."); Console.WriteLine("####################################################################"); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); Console.WriteLine("####################################################################"); Console.WriteLine("AFTER verification ABORT. Commit returned " + res + " . Press enter for abort and exit."); Console.WriteLine("####################################################################"); Console.ReadLine(); PadiDstm.TxAbort(); } }
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----------" }); }
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----------" }); }
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----------" }); }
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(); }
//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); }
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); } }
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(); }
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(); }
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(); } }