Exemplo n.º 1
0
		public static List<JobQueueItem> GenerateFailingJobParamsRequests(int numberOfJobRequests)
		{
			List<JobQueueItem> requestModels = null;

			if (numberOfJobRequests > 0)
			{
				requestModels = new List<JobQueueItem>();

				for (var i = 1; i <= numberOfJobRequests; i++)
				{
					var failingJobParams = new FailingJobParams("Error message " + i);

					var failingJobParamsJson = JsonConvert.SerializeObject(failingJobParams);

					var job = new JobQueueItem
					{
						Name = "Job Name " + i,
						Serialized = failingJobParamsJson,
						Type = "NodeTest.JobHandlers.FailingJobParams",
						CreatedBy = "Test"
					};

					requestModels.Add(job);
				}
			}
			return requestModels;
		}
Exemplo n.º 2
0
		public void Execute(object parameter)
		{
			Task.Factory.StartNew(() =>
			{
				var uri = ManagerUriBuilder.GetAddToJobQueueUri();

				for (var i = 0; i < NumberOfJobs; i++)
				{
					var fastJobParams = new TestJobParams("Fast job Data " + i, TimeSpan.FromSeconds(1));
					var fastJobParamsToJson = JsonConvert.SerializeObject(fastJobParams);

					var job = new JobQueueItem
					{
						Name = "Job Name " + i,
						Serialized = fastJobParamsToJson,
						Type = "NodeTest.JobHandlers.FastJobParams",
						CreatedBy = "test"
					};

					var response = HttpSender.PostAsync(uri, job);
				}
			});
		}
Exemplo n.º 3
0
		public static List<JobQueueItem> GenerateTestJobRequests(int numberOfJobRequests,
		                                                              TimeSpan duration)
		{
			List<JobQueueItem> jobQueueItems = new List<JobQueueItem>();

			if (numberOfJobRequests > 0)
			{
				for (var i = 1; i <= numberOfJobRequests; i++)
				{
					var testJobParams = new TestJobParams("Name " + i, duration);
					var testJobParamsToJson = JsonConvert.SerializeObject(testJobParams);

					var job = new JobQueueItem
					{
						Name = "Job Name " + i,
						Serialized = testJobParamsToJson,
						Type = "NodeTest.JobHandlers.TestJobParams",
						CreatedBy = "test"
					};
					jobQueueItems.Add(job);
				}
			}
			return jobQueueItems;
		}
Exemplo n.º 4
0
		private async Task<string> AddJobAsync(JobQueueItem jobQueueItem)
		{
			var result = HttpSender.PostAsync(MangerUriBuilder.GetAddToJobQueueUri(), jobQueueItem).Result;
			var content = await result.Content.ReadAsStringAsync();
			return content;
		}
Exemplo n.º 5
0
		public Guid AddJob(JobQueueItem jobQueueItem)
		{
			string jobIdString = AddJobAsync(jobQueueItem).Result;
			Guid jobId = new Guid(JsonConvert.DeserializeObject<string>(jobIdString));
			return jobId;
		}
Exemplo n.º 6
0
		public void StartDurationTest()
		{
			CancellationTokenSourceDurationTest = new CancellationTokenSource();

			Task.Factory.StartNew(() =>
			{
				while (true)
				{
					var tasksToDispose = _tasks.Where(task => task.IsCompleted);

					foreach (var task in tasksToDispose)
					{
						task.Dispose();

						_tasks.Remove(task);
					}

					if (CancellationTokenSourceDurationTest.Token.IsCancellationRequested)
					{
						CancellationTokenSourceDurationTest.Token.ThrowIfCancellationRequested();
					}
				}

			}, CancellationTokenSourceDurationTest.Token);

			Task.Factory.StartNew(() =>
			{
				var mangerUriBuilder = new ManagerUriBuilder();
				var addToJobQueueUri = mangerUriBuilder.GetAddToJobQueueUri();

				var httpSender = new HttpSender();				
			
				Random random = new Random();

				for (int i = 0; i < NumberOfMessages; i++)
				{

					if (CancellationTokenSourceDurationTest.Token.IsCancellationRequested)
					{
						CancellationTokenSourceDurationTest.Token.ThrowIfCancellationRequested();
					}

					var i1 = i;
					
					var randomTimeSpan = random.Next(MessageDurationFrom, MessageDurationTo);

					_tasks.Add(new Task<HttpResponseMessage>(() =>
						{
							var testJobTimerParams =
							new TestJobParams("Test job name " + i1, 
													TimeSpan.FromSeconds(randomTimeSpan));

						var jobParamsToJson = 
							JsonConvert.SerializeObject(testJobTimerParams);

							var jobQueueItem = new JobQueueItem
							{
							Name = "Job Name " + i1,
								Serialized = jobParamsToJson,
								Type = "NodeTest.JobHandlers.TestJobParams",
								CreatedBy = "WPF Client"
							};

						return httpSender.PostAsync(addToJobQueueUri, 
													jobQueueItem).Result;

					}, CancellationTokenSourceDurationTest.Token));
				}

				var sendJobEveryDurationTimer=
					new SendJobEveryDurationTimer<HttpResponseMessage>(_tasks,
																	   TimeSpan.FromSeconds(5),
																	   ProgressAction);

				CheckManagerDbTimer.Start();
				sendJobEveryDurationTimer.SendTimer.Start();
			});
		}