public void DataSetNothingForTaskManager() { var comps = new Dictionary <int, ActiveComponent>(); comps.Add(1, new ActiveComponent() { ComponentType = ComponentType.TaskManager, SolvableProblems = new[] { "def" } }); var dict = new Dictionary <int, ProblemDataSet>(); var bytes = new byte[1] { 1 }; dict.Add(1, new ProblemDataSet() { CommonData = bytes, TaskManagerId = 0, ProblemType = "abc" }); var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict); Assert.IsNull(ret); }
public void DataSetDivideForProperTaskManager() { var comps = new Dictionary <int, ActiveComponent>(); comps.Add(1, new ActiveComponent() { ComponentType = ComponentType.TaskManager, SolvableProblems = new [] { "abc" } }); var dict = new Dictionary <int, ProblemDataSet>(); var bytes = new byte[1] { 1 }; dict.Add(1, new ProblemDataSet() { CommonData = bytes, TaskManagerId = 0, ProblemType = "abc" }); var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict); Assert.AreEqual(typeof(DivideProblem), ret.GetType()); var msg = ret.Cast <DivideProblem>(); Assert.AreEqual(1, msg.Data.Length); Assert.AreEqual(1, msg.Data[0]); Assert.AreEqual(1, dict[1].TaskManagerId); }
public void DataSetTaskManagerFailureNextTaskManagerWork() { var comps = new Dictionary <int, ActiveComponent>(); comps.Add(1, new ActiveComponent() { ComponentType = ComponentType.TaskManager, SolvableProblems = new[] { "abc" } }); comps.Add(2, new ActiveComponent() { ComponentType = ComponentType.TaskManager, SolvableProblems = new [] { "abc" } }); var dict = new Dictionary <int, ProblemDataSet>(); var bytes = new byte[1] { 1 }; dict.Add(1, new ProblemDataSet() { CommonData = bytes, TaskManagerId = 0, ProblemType = "abc" }); var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict); Assert.AreEqual(typeof(DivideProblem), ret.GetType()); DataSetOps.HandleClientMalfunction(comps, 1, dict); var ret2 = DataSetOps.GetMessageForTaskManager(comps, 2, dict); Assert.AreEqual(typeof(DivideProblem), ret2.GetType()); var msg2 = ret.Cast <DivideProblem>(); Assert.AreEqual(1, msg2.Data.Length); Assert.AreEqual(1, msg2.Data[0]); Assert.AreEqual(2, dict[1].TaskManagerId); }
public void DataSetSolutionsForTaskManager() { var comps = new Dictionary <int, ActiveComponent>(); comps.Add(1, new ActiveComponent() { ComponentType = ComponentType.TaskManager, SolvableProblems = new[] { "abc" } }); var dict = new Dictionary <int, ProblemDataSet>(); var bytes = new byte[1] { 1 }; dict.Add(1, new ProblemDataSet() { CommonData = bytes, TaskManagerId = 1, ProblemType = "abc", PartialSets = new [] { new PartialSet() { PartialProblem = new SolvePartialProblemsPartialProblem(), PartialSolution = new SolutionsSolution(), Status = PartialSetStatus.Ongoing } } }); var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict); Assert.AreEqual(typeof(Solutions), ret.GetType()); var msg = ret.Cast <Solutions>(); Assert.AreEqual(1, msg.SolutionsList.Length); Assert.AreEqual(1, msg.CommonData.Length); Assert.AreEqual(1, msg.CommonData[0]); }
protected override Message[] RespondStatusMessage(Status message, IDictionary <int, ProblemDataSet> dataSets, IDictionary <int, ActiveComponent> activeComponents, List <BackupServerInfo> backups) { //if sent by TM - send NoOp + return from CaseExtractor.GetMessageForTaskManager //if sent by CN - send NoOp + return from CaseExtractor.GetMessageForCompNode var who = (int)message.Id; if (!activeComponents.ContainsKey(who)) { return new Message[] { new Error() { ErrorMessage = "who are you?", ErrorType = ErrorErrorType.UnknownSender } } } ; activeComponents[who].StatusWatch.Restart(); Message whatToDo = null; Log.DebugFormat("Handling status message of {0}(id={1}). Searching for problems.", activeComponents[who].ComponentType, who); switch (activeComponents[who].ComponentType) { case ComponentType.ComputationalNode: whatToDo = DataSetOps.GetMessageForCompNode(activeComponents, who, dataSets); break; case ComponentType.TaskManager: whatToDo = DataSetOps.GetMessageForTaskManager(activeComponents, who, dataSets); break; case ComponentType.CommunicationServer: var msgs = SynchronizationQueue.ToList(); SynchronizationQueue = new ConcurrentQueue <Message>(); msgs.Add(new NoOperation() { BackupServersInfo = backups.ToArray() }); return(msgs.ToArray()); } var noop = new NoOperation() { BackupServersInfo = backups.ToArray() }; if (whatToDo == null) { Log.DebugFormat("Nothing additional found for {0} (id={1})", activeComponents[who].ComponentType, who); return(new Message[] { noop }); } Log.DebugFormat("Found problem ({0}) for {1} (id={2})", whatToDo.MessageType, activeComponents[who].ComponentType, who); SynchronizationQueue.Enqueue(whatToDo); return(new[] { whatToDo, noop }); }