/* * 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); } }
/* 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 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 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----------" }); }