public void AllTypesOfNodesAreProperlyRegistered() { _overseer = new ComponentOverseer(5, 5); var solvableProblems = new List <string> { "dvrp" }; var serverInfo = new ServerInfo { IpAddress = "127.0.0.1", Port = 9135 }; ComponentInfo taskManager = new SolverNodeInfo(ComponentType.TaskManager, solvableProblems, 5); ComponentInfo computationalNode = new SolverNodeInfo(ComponentType.ComputationalNode, solvableProblems, 5); ComponentInfo backupServer = new BackupServerInfo(serverInfo, 5); Assert.IsNull(taskManager.ComponentId); Assert.IsNull(computationalNode.ComponentId); Assert.IsNull(backupServer.ComponentId); _overseer.TryRegister(taskManager); _overseer.TryRegister(computationalNode); _overseer.TryRegister(backupServer); Assert.IsTrue(_overseer.IsRegistered(taskManager.ComponentId.Value)); Assert.IsTrue(_overseer.IsRegistered(computationalNode.ComponentId.Value)); Assert.IsTrue(_overseer.IsRegistered(backupServer.ComponentId.Value)); }
/// <summary> /// Handle registration message. /// </summary> /// <param name="msg">Register message.</param> /// <param name="metadata">Information about data and the TCP connection it came from.</param> /// <returns>List of response messages.</returns> private List <Message> HandleMessage(RegisterMessage msg, TcpDataProviderMetadata metadata) { ComponentInfo componentInfo; switch (msg.ComponentType) { case ComponentType.CommunicationServer: var serverInfo = new ServerInfo { IpAddress = metadata.SenderAddress.Address.ToString(), Port = (ushort)metadata.SenderAddress.Port }; componentInfo = new BackupServerInfo(serverInfo, msg.ParallelThreads); break; case ComponentType.ComputationalNode: case ComponentType.TaskManager: componentInfo = new SolverNodeInfo(msg.ComponentType, msg.SolvableProblems, msg.ParallelThreads); break; default: throw new InvalidOperationException("Invalid component type registration (" + msg.ComponentType + ")."); } _componentOverseer.TryRegister(componentInfo); var responseMsg = new RegisterResponseMessage { AssignedId = componentInfo.ComponentId.Value, BackupServers = CreateBackupList(), CommunicationTimeout = _componentOverseer.CommunicationTimeout }; return(new List <Message> { responseMsg }); }