Inheritance: ApiController
Example #1
0
		public void CancelJobShouldReturnNotFoundWhenNodeIsIdle()
		{
			_workerWrapper = new WorkerWrapper(new ShortRunningInvokeHandlerFake(),
			                                   _nodeConfigurationFake,
			                                   _nodeStartupNotification,
			                                   _pingToManagerFake,
			                                   _sendJobDoneTimer,
			                                   _sendJobCanceledTimer,
			                                   _sendJobFaultedTimer,
			                                   _trySendJobDetailToManagerTimerFake);

			_nodeController = new NodeController(_workerWrapper, _nodeConfigurationFake)
			{
				Request = new HttpRequestMessage()
			};

			IHttpActionResult actionResultCancel = _nodeController.TryCancelJob(_jobQueueItemEntity.JobId);

			Assert.IsTrue(actionResultCancel.ExecuteAsync(new CancellationToken())
							  .Result.StatusCode ==
						  HttpStatusCode.NotFound);
		}
Example #2
0
		public void StartJobShouldReturnOkIfJobIdMatchPrepareJobId()
		{
			_workerWrapper = new WorkerWrapper(new ShortRunningInvokeHandlerFake(),
											   _nodeConfigurationFake,
											   _nodeStartupNotification,
											   _pingToManagerFake,
											   _sendJobDoneTimer,
											   _sendJobCanceledTimer,
											   _sendJobFaultedTimer,
											   _trySendJobDetailToManagerTimerFake);

			_nodeController = new NodeController(_workerWrapper, _nodeConfigurationFake)
			{
				Request = new HttpRequestMessage()
			};

			_nodeController.PrepareToStartJob(_jobQueueItemEntity);
			var actionResult = _nodeController.StartJob(_jobQueueItemEntity.JobId);

			Assert.IsTrue(actionResult.ExecuteAsync(new CancellationToken())
							  .Result.StatusCode ==
						  HttpStatusCode.OK);
		}
Example #3
0
		public void ShouldReturnBadRequestWhenPrepareToStartJobWithNoJob()
		{
			_workerWrapper = new WorkerWrapper(new ShortRunningInvokeHandlerFake(),
			                                   _nodeConfigurationFake,
			                                   _nodeStartupNotification,
			                                   _pingToManagerFake,
			                                   _sendJobDoneTimer,
			                                   _sendJobCanceledTimer,
			                                   _sendJobFaultedTimer,
			                                   _trySendJobDetailToManagerTimerFake);

			_nodeController = new NodeController(_workerWrapper, _nodeConfigurationFake)
			{
				Request = new HttpRequestMessage(),
				Configuration = new HttpConfiguration()
			};


			var actionResult = _nodeController.PrepareToStartJob(null);

			Assert.IsTrue(actionResult.ExecuteAsync(new CancellationToken())
							  .Result.StatusCode ==
						  HttpStatusCode.BadRequest);
		}
Example #4
0
		public void PrepareToStartJobShouldReturnConflictWhenAlreadyProcessingJob()
		{
			_workerWrapper = new WorkerWrapper(new ShortRunningInvokeHandlerFake(),
											   _nodeConfigurationFake,
											   _nodeStartupNotification,
											   _pingToManagerFake,
											   _sendJobDoneTimer,
											   _sendJobCanceledTimer,
											   _sendJobFaultedTimer,
											   _trySendJobDetailToManagerTimerFake);

			_nodeController = new NodeController(_workerWrapper, _nodeConfigurationFake)
			{
				Request = new HttpRequestMessage(),
				Configuration = new HttpConfiguration()
			};

			var parameters = new TestJobParams("Test Job",
			                                   TimeSpan.FromSeconds(1));
			var ser = JsonConvert.SerializeObject(parameters);

			var jobToDo2 = new JobQueueItemEntity
			{
				JobId = Guid.NewGuid(),
				Name = "Another name",
				Serialized = ser,
				Type = "NodeTest.JobHandlers.TestJobParams"
			};

			_nodeController.PrepareToStartJob(_jobQueueItemEntity);

			var actionResult = _nodeController.PrepareToStartJob(jobToDo2);

			Assert.IsTrue(actionResult.ExecuteAsync(new CancellationToken())
							  .Result.StatusCode ==
						  HttpStatusCode.Conflict);
		}
Example #5
0
		public void CancelJobShouldReturnOkWhenSuccessful()
		{
			_workerWrapper = new WorkerWrapper(new LongRunningInvokeHandlerFake(),
			                                   _nodeConfigurationFake,
			                                   _nodeStartupNotification,
			                                   _pingToManagerFake,
			                                   _sendJobDoneTimer,
			                                   _sendJobCanceledTimer,
			                                   _sendJobFaultedTimer,
			                                   _trySendJobDetailToManagerTimerFake);

			_nodeController = new NodeController(_workerWrapper, _nodeConfigurationFake)
			{
				Request = new HttpRequestMessage()
			};

			_nodeController.PrepareToStartJob(_jobQueueItemEntity);
			_nodeController.StartJob(_jobQueueItemEntity.JobId);

			//is this to make sure the job has started before cancelling?
			_trySendJobDetailToManagerTimerFake.WaitHandle.Wait(500);

			var actionResult = _nodeController.TryCancelJob(_jobQueueItemEntity.JobId);

			Assert.IsTrue(actionResult.ExecuteAsync(new CancellationToken())
							  .Result.StatusCode ==
						  HttpStatusCode.OK);
		}