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(); }
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----------" }); }
/* * 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); } }
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); } }
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); } }
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(); }
/* 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); } }
public void TestRecover() { Console.WriteLine("------ Test: Recover ------"); Logger.Log(new String[] { "Client", "------ Test: Recover ------" }); Console.WriteLine("library created"); try { Console.WriteLine("init() Done"); PadiDstm.TxBegin(); Console.WriteLine("txBegin Done"); // The following 2 lines assume we have 2 servers: one at port 2001 and another at port 2002 bool res = PadiDstm.Recover("tcp://localhost:2001/PadIntServer"); Console.WriteLine("####################################################################"); Console.WriteLine("Fiz o recover res= " + res + " Depois vem o 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----------" }); }
/* 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); } }
private void txAbortButton_Click(object sender, EventArgs e) { //statusTextBox.Clear(); try { PadiDstm.TxAbort(); txBeginButton.Enabled = true; } catch (TxException) { statusTextBox.AppendText("Cannot abort. No active Transaction.\r\n"); } }
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----------" }); }
private void txBeginButton_Click(object sender, EventArgs e) { //statusTextBox.Clear(); try { PadiDstm.TxBegin(); txBeginButton.Enabled = false; } catch (TxException te) { statusTextBox.AppendText("Cannot start new transaction." + "Transaction with id" + te.Tid + "is active.\r\n"); } }
private void txCommitButton_Click(object sender, EventArgs e) { //statusTextBox.Clear(); try { PadiDstm.TxCommit(); txBeginButton.Enabled = true; } catch (TxException) { statusTextBox.AppendText("Cannot commit. No active Transaction.\r\n"); } catch (OperationException oe) { statusTextBox.AppendText(oe.Msg + "\r\n"); txBeginButton.Enabled = true; } }
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 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----------" }); }
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----------" }); }
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----------" }); }
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); } }
static void Main(string[] args) { TcpChannel channel = new TcpChannel(); ChannelServices.RegisterChannel(channel, false); ClientApp clientApp = new ClientApp(); PadiDstm.Init(); //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server"); //Console.WriteLine("About to recover"); //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Status(); //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Freeze("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Freeze("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server"); //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server"); //Console.WriteLine("After fail"); //Console.ReadLine(); //clientApp.transaction1(); //clientApp.transaction2(); Console.ReadLine(); PadiDstm.Status(); Console.ReadLine(); }
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()); }
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); } }
static void Main(string[] args) { PadiDstm.Init(); Tests tests = new Tests(); Assert.AreEqual(tests.TestCommandsWithNoTransaction(), false); // falha Assert.AreEqual(tests.TestAccessNonCreatedPadInt(), false); // falha Assert.AreEqual(tests.TestCreateDuplicatePadInt(), false); // falha //Assert.AreEqual(tests.TestCreateTwoPadIntsOneServerDown(), true); //Assert.AreEqual(tests.TestCreateTwoPadIntsAfterFailedServerRecover(), true); Assert.AreEqual(tests.TestCreateTwoPadIntsBothServersFailed(), false); // falha //Assert.AreEqual(tests.TestCreateTwoPadIntsOneServerFrozen(), false); //Assert.AreEqual(tests.TestAccessPadIntOnFrozenSever(), true); // fica em espera (devolve true?) Assert.AreEqual(tests.TestAccessPadIntOnFailedServer(), false); // falha //Assert.AreEqual(tests.TestReadPadIntOnFrozenServer(), true); // fica em espera (devolve true?) // estes dois correm se estiverem isolados, na sequência crasham... não percebemos porquê // Assert.AreEqual(tests.TestReadPadIntAfterWritingTransactionAborted(), true); // pq rebenta? // Assert.AreEqual(tests.TestReadPadIntAfterWritingTransactionCommited(), true); // pq rebenta? }
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 static void Maina(string[] args) { Client client = new Client(); Console.Title = "Client"; Console.WriteLine("Client up and running.."); if (PadiDstm.Init()) { string input; while (true) { Console.WriteLine("----------------------HELP-------------------------"); Console.WriteLine("Please, insert the number of the test that you want to run:"); Console.WriteLine("Tests with just one client"); Console.WriteLine("1- testRandom"); Console.WriteLine("Tests with one client:"); Console.WriteLine("2- Base: testSimpleRead"); Console.WriteLine("3- Base: testSimpleWrite"); Console.WriteLine("4- Base: testSimpleAbort"); Console.WriteLine("5- Base: testSimpleCommit"); Console.WriteLine("6- Base: testMultipleReads"); Console.WriteLine("7- Base: testReadWrite"); Console.WriteLine("8- Base: testWriteRead"); Console.WriteLine("---Freeze---"); Console.WriteLine("9- Base: testFreezeCreate (client1)"); Console.WriteLine("10- Base: testFailCreate (client1)"); Console.WriteLine("11- Base: testFreezeFail (client2)"); Console.WriteLine("12- Base: testRecover"); Console.WriteLine("13- status"); Console.WriteLine("---------"); Console.Write(">"); input = Console.ReadLine(); if (input.Equals("1")) { client.TestRandom(); } if (input.Equals("2")) { client.TestSimpleRead(client.GetNextUid()); } if (input.Equals("3")) { client.TestSimpleWrite(client.GetNextUid()); } if (input.Equals("4")) { client.TestSimpleAbort(client.GetNextUid()); } if (input.Equals("5")) { client.TestSimpleCommit(client.GetNextUid()); } if (input.Equals("6")) { client.TestMultipleRead(client.GetNextUid(), client.GetNextUid(), client.GetNextUid()); } if (input.Equals("7")) { client.TestReadWrite(client.GetNextUid()); } if (input.Equals("8")) { client.TestWriteRead(client.GetNextUid()); } if (input.Equals("9")) { client.TestFreezeCreate(1); } if (input.Equals("10")) { client.TestFailCreate(1); } if (input.Equals("11")) { client.TestFreezeFail(2); } if (input.Equals("12")) { client.TestRecover(); } if (input.Equals("13")) { PadiDstm.Status(); } } } else { Logger.Log(new String[] { "There are no servers available" }); } }
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(); }
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(); } }
private void recoverButton_Click(object sender, EventArgs e) { PadiDstm.Recover(recoverTextBox.Text.ToString()); }
private void statusButton_Click(object sender, EventArgs e) { // sabemos que não faz nada PadiDstm.Status(statusTextBox); }
private void initButton_Click(object sender, EventArgs e) { PadiDstm.Init(); initButton.Enabled = false; }
private void createButton_Click(object sender, EventArgs e) { _createdObj = PadiDstm.CreatePadInt(Convert.ToInt32(createTextBox.Text)); }