public void StatusWithNullsTest() { //Arrange Status s = new Status(123, new List<ComputationalThread>() { new ComputationalThread(ComputationalThreadState.Busy, 100, 300, 200, "name"), new ComputationalThread(ComputationalThreadState.Idle, 200, null, null, "name2")}); //Act byte[] data = s.GetXmlData(); //Assert Assert.IsNotNull(data); Debug.WriteLine(System.Text.Encoding.UTF8.GetString(data)); }
public void StatusParseTest() { //Arrange Status s = new Status(123, new List<ComputationalThread>() { new ComputationalThread(ComputationalThreadState.Busy, 100, 300, 200, "name"), new ComputationalThread(ComputationalThreadState.Idle, 200, null, null, "name2")}); byte[] data = s.GetXmlData(); //Act XMLParser parser = new XMLParser(data); //Assert Assert.IsNotNull(parser); Assert.AreEqual(MessageTypes.Status, parser.MessageType); Status rs = (Status)parser.Message; Assert.AreEqual(s.Id, rs.Id); Assert.AreEqual(s.Threads.Count, rs.Threads.Count); ComputationalThread t = s.Threads[0]; ComputationalThread rt = rs.Threads[0]; Assert.AreEqual(t.HowLong, rt.HowLong); Assert.AreEqual(t.ProblemInstanceId, rt.ProblemInstanceId); Assert.AreEqual(t.State, rt.State); Assert.AreEqual(t.TaskId, rt.TaskId); }
public void SendStatusMessage() { Status status_msg = new Status(id, threads); Console.WriteLine("TM: sending status message..."); byte[] response = client.Work(status_msg.GetXmlData()); if (response == null) { Console.WriteLine("TM: response is set to null"); } else { XMLParser parser = new XMLParser(response); switch (parser.MessageType) { case MessageTypes.DivideProblem: Console.WriteLine("TM divides and send problem to CS"); DivideProblem msg = (DivideProblem)parser.Message; ComputationalThread ct = threads.Find(x => x.State == ComputationalThreadState.Idle); threads.Remove(ct); ComputationalThread new_thread = new ComputationalThread(ComputationalThreadState.Busy, 0, msg.Id, 1, msg.ProblemType); threads.Add(new_thread); Thread t = new Thread(() => DivideThreadFunc(msg, new_thread)); t.Start(); break; case MessageTypes.Solutions: Console.WriteLine("TM: try merge solutions is starting"); Solutions sol_msg = (Solutions)parser.Message; Console.WriteLine("TM try to Merge solution of the problem with id = {0} into final", sol_msg.Id); //check if solved problems number is equal to if (!PartialSolutions.ContainsKey(sol_msg.Id)) PartialSolutions.Add(sol_msg.Id, new List<byte[]>()); SolverRegisteredProblem p = ongoing_problems.Find(x => sol_msg.Id == x.ProblemId); if (p != null) { foreach (Solution s in sol_msg.SolutionsList) { if (s.Data != null) { p.MarkAsSolved((ulong)s.TaskId); PartialSolutions[sol_msg.Id].Add(s.Data); p.SetComputationsTime(s.ComputationsTime); } } } else Console.WriteLine("Not foung Solver registered problem"); if (p != null && p.IsProblemSolved()) { ongoing_problems.Remove(p); Console.WriteLine("TM: Ready to merge solution"); //one common solution ComputationalThread sol_ct = threads.Find(x => x.State == ComputationalThreadState.Idle); threads.Remove(sol_ct); ComputationalThread new_sol_thread = new ComputationalThread(ComputationalThreadState.Busy, p.computation_time, sol_msg.Id, 1, sol_msg.ProblemType); threads.Add(new_sol_thread); Thread sol_t = new Thread(() => MergeThreadFunc(sol_msg, new_sol_thread)); sol_t.Start(); } else { client.Work(sol_msg.GetXmlData()); } break; default: Console.WriteLine("received other message: " + response.GetType().ToString()); client.Work(status_msg.GetXmlData()); break; } } }
public void SendStatusMessage() { Status status_msg = new Status(id, threads); Console.WriteLine("CN: sending status message..."); byte[] response = client.Work(status_msg.GetXmlData()); if (response == null) { Console.WriteLine("CN: response is equal to null"); } else { XMLParser parser = new XMLParser(response); switch (parser.MessageType) { case MessageTypes.SolvePartialProblems: // Thread problem_solve_thread = new Console.WriteLine("CN: Received solve partial problems message"); SolveProblem((SolvePartialProblems)parser.Message); break; default: Console.WriteLine("Different message than SolvePartialProblems received"); Console.WriteLine(parser.MessageType); break; } } }