public void NodeIsDeregisteredAfterTimeout() { uint communicationTimeout = 1; uint checkInterval = 1; var stopwatch = new Stopwatch(); var deregistrationEventLock = new AutoResetEvent(false); _overseer = new ComponentOverseer(communicationTimeout, checkInterval); _overseer.Deregistration += (o, e) => { deregistrationEventLock.Set(); }; _overseer.StartMonitoring(); var solvableProblems = new List<string> {"dvrp"}; ComponentInfo computationalNode = new SolverNodeInfo(ComponentType.ComputationalNode, solvableProblems, 5); _overseer.TryRegister(computationalNode); stopwatch.Start(); Assert.IsTrue(_overseer.IsRegistered(computationalNode.ComponentId.Value)); deregistrationEventLock.WaitOne(1000*(int) (communicationTimeout + checkInterval + 1)); stopwatch.Stop(); Assert.IsFalse(_overseer.IsRegistered(computationalNode.ComponentId.Value)); Assert.IsTrue((ulong) stopwatch.ElapsedMilliseconds >= communicationTimeout); _overseer.StopMonitoring(); }
public void NodeIsDeregisteredAfterTimeout() { uint communicationTimeout = 1; uint checkInterval = 1; var stopwatch = new Stopwatch(); var deregistrationEventLock = new AutoResetEvent(false); _overseer = new ComponentOverseer(communicationTimeout, checkInterval); _overseer.Deregistration += (o, e) => { deregistrationEventLock.Set(); }; _overseer.StartMonitoring(); var solvableProblems = new List <string> { "dvrp" }; ComponentInfo computationalNode = new SolverNodeInfo(ComponentType.ComputationalNode, solvableProblems, 5); _overseer.TryRegister(computationalNode); stopwatch.Start(); Assert.IsTrue(_overseer.IsRegistered(computationalNode.ComponentId.Value)); deregistrationEventLock.WaitOne(1000 * (int)(communicationTimeout + checkInterval + 1)); stopwatch.Stop(); Assert.IsFalse(_overseer.IsRegistered(computationalNode.ComponentId.Value)); Assert.IsTrue((ulong)stopwatch.ElapsedMilliseconds >= communicationTimeout); _overseer.StopMonitoring(); }
/// <summary> /// Stops the server. /// </summary> public void Stop() { _tcpServer.StopListening(); _componentOverseer.StopMonitoring(); _msgProcessor.StopProcessing(); }