Ejemplo n.º 1
0
		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();
		}
Ejemplo n.º 2
0
		public SendJobDoneTimerFake(NodeConfiguration nodeConfiguration,
									TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
									IHttpSender httpSender,
									double interval = 1000) : base(nodeConfiguration,
																   sendJobDetailToManagerTimer,
																   httpSender,
																   interval)
		{
		}
		public SendJobDoneWithEventTriggerTimerFake(NodeConfiguration nodeConfiguration,
		                                            Uri callbackTemplateUri,
		                                            TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
		                                            IHttpSender httpSender) : base(nodeConfiguration,
		                                                                           callbackTemplateUri,
		                                                                           sendJobDetailToManagerTimer,
		                                                                           httpSender)
		{
		}
		public TrySendJobDoneStatusToManagerTimer(NodeConfiguration nodeConfiguration,
												  TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
												  IHttpSender httpSender,
												  double interval = 500) : base(nodeConfiguration,
		                                                                          nodeConfiguration.GetManagerJobDoneTemplateUri(),
																				  sendJobDetailToManagerTimer,
																				  httpSender,
																				  interval)
		{
		}
		public TrySendJobCanceledToManagerTimer(NodeConfiguration nodeConfiguration,
												TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
												IHttpSender httpSender,
												double interval = 500) : base(nodeConfiguration,
		                                                                        nodeConfiguration.GetManagerJobHasBeenCanceledTemplateUri(),
																				sendJobDetailToManagerTimer,
																				httpSender,
																				interval)
		{
		}
		public void ShouldBeAbleToInstantiateObject()
		{
			var timer =
				new TrySendJobDetailToManagerTimer(_nodeConfiguration,
				                                     _httpSenderFake,
				                                     1000);

			Assert.IsNotNull(timer);

			timer.Dispose();
		}
		public TrySendJobFaultedToManagerTimer(NodeConfiguration nodeConfiguration,
		                                       TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
		                                       IHttpSender httpSender,
		                                       double interval = 500) : base(nodeConfiguration,
		                                                                     nodeConfiguration
			                                                                     .GetManagerJobHasFailedTemplatedUri(),
		                                                                     sendJobDetailToManagerTimer,
		                                                                     httpSender,
		                                                                     interval)
		{
			_httpSender = httpSender;
		}
		public TrySendStatusToManagerTimer(NodeConfiguration nodeConfiguration,
		                                   Uri callbackTemplateUri,
		                                   TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
		                                   IHttpSender httpSender, double interval = 500) : base(interval)
		{
			_cancellationTokenSource = new CancellationTokenSource();
			_whoAmI = nodeConfiguration.CreateWhoIAm(Environment.MachineName);
			_sendJobDetailToManagerTimer = sendJobDetailToManagerTimer;
			_httpSender = httpSender;
			CallbackTemplateUri = callbackTemplateUri;

			Elapsed += OnTimedEvent;
			AutoReset = true;
		}
		public void ShouldHave100JobProgressesWhen100AreAdded()
		{
			var timer =
				new TrySendJobDetailToManagerTimer(_nodeConfiguration,
				                                     _httpSenderFake,
				                                     1000);

			Assert.IsNotNull(timer, "Should be able to instantiate timer.");

			for (var i = 0; i < 100; i++)
			{
				timer.SendProgress(Guid.NewGuid(), "Progress message");
			}

			Assert.IsTrue(timer.TotalNumberOfJobProgresses() == 100,
			              "100 job progresses are expected.");

			timer.Dispose();
		}
		public void ShouldHaveTwoJobProgressesWhenTwoWithSameGuidAreAdded()
		{
			var timer =
				new TrySendJobDetailToManagerTimer(_nodeConfiguration,
				                                     _httpSenderFake,
				                                     1000);

			Assert.IsNotNull(timer);

			var newGuid = Guid.NewGuid();

			timer.SendProgress(newGuid, "Progress message 1.");
			timer.SendProgress(newGuid, "Progress message 2.");

			timer.SendProgress(Guid.NewGuid(), "Progress message 3.");

			Assert.IsTrue(timer.TotalNumberOfJobProgresses(newGuid) == 2,
			              "Two job progresses with same GUID are expected.");

			timer.Dispose();
		}
		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();
		}