public WorkerWrapper(IInvokeHandler invokeHandler, NodeConfiguration nodeConfiguration, TrySendNodeStartUpNotificationToManagerTimer nodeStartUpNotificationToManagerTimer, Timer pingToManagerTimer, TrySendJobDoneStatusToManagerTimer trySendJobDoneStatusToManagerTimer, TrySendJobCanceledToManagerTimer trySendJobCanceledStatusToManagerTimer, TrySendJobFaultedToManagerTimer trySendJobFaultedStatusToManagerTimer, TrySendJobDetailToManagerTimer trySendJobDetailToManagerTimer) { _handler = invokeHandler; _nodeConfiguration = nodeConfiguration; WhoamI = _nodeConfiguration.CreateWhoIAm(Environment.MachineName); _nodeStartUpNotificationToManagerTimer = nodeStartUpNotificationToManagerTimer; _nodeStartUpNotificationToManagerTimer.TrySendNodeStartUpNotificationSucceded += NodeStartUpNotificationToManagerTimer_TrySendNodeStartUpNotificationSucceded; _pingToManagerTimer = pingToManagerTimer; _trySendJobDoneStatusToManagerTimer = trySendJobDoneStatusToManagerTimer; _trySendJobCanceledStatusToManagerTimer = trySendJobCanceledStatusToManagerTimer; _trySendJobFaultedStatusToManagerTimer = trySendJobFaultedStatusToManagerTimer; _trySendJobDetailToManagerTimer = trySendJobDetailToManagerTimer; isWorking = false; _trySendJobDetailToManagerTimer.Start(); _nodeStartUpNotificationToManagerTimer.Start(); }
public void ShouldBeAbleToSend200ProgressesWith10ConcurrentProcesses() { const int numberOfProgesses = 200; const int numberOfConcurrentProcesses = 10; var timer = new TrySendJobDetailToManagerTimer(_nodeConfiguration, _httpSenderFake, 1000); var numberOfProgressesReceived = 0; timer.SendJobDetailWithSuccessEventHandler += (sender, model) => { numberOfProgressesReceived++; }; List<Task<int>> tasks=new List<Task<int>>(); for (var i = 0; i < numberOfConcurrentProcesses; i++) { tasks.Add(new Task<int>(() => { var newGuid = Guid.NewGuid(); for (var progressLoop = 0; progressLoop < numberOfProgesses; progressLoop++) { timer.SendProgress(newGuid, "Progress message nr : " + progressLoop); } return numberOfProgesses; })); } tasks.Add(new Task<int>(() => { timer.Start(); while (!timer.HasAllProgressesBeenSent()) { } return 0; })); foreach (var task in tasks) { task.Start(); } Task.WaitAll(tasks.ToArray()); int totalNumberOfProgressesSent = tasks.Sum(task => task.Result); Assert.IsTrue(numberOfProgressesReceived == totalNumberOfProgressesSent, "Number of progresses sent must be equal to received."); Assert.IsTrue(timer.HasAllProgressesBeenSent(), "All progresses must be sent."); timer.Dispose(); }