public void DoTheThing(TestJobParams message, CancellationTokenSource cancellationTokenSource, Action<string> progress) { // ----------------------------------------------------------- // Start execution. // ----------------------------------------------------------- var jobProgress = new TestJobProgress { Text = "Starting job: " + message.Name }; progress(jobProgress.Text); jobProgress = new TestJobProgress { Text = "Will execute for : " + message.Duration.TotalSeconds + " seconds." }; progress(jobProgress.Text); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int progressCounter = 0; var sleep = 5; while (stopwatch.Elapsed <= message.Duration) { progressCounter++; if (cancellationTokenSource.IsCancellationRequested) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); } jobProgress = new TestJobProgress { Text = "Progress loop number :" + progressCounter + ". Will sleep a couple of seconds." }; progress(jobProgress.Text); Thread.Sleep(TimeSpan.FromSeconds(sleep)); } // ----------------------------------------------------------- // Finished execution. // ----------------------------------------------------------- jobProgress = new TestJobProgress { Text = "Finished job: " + message.Name }; progress(jobProgress.Text); }
public void Setup() { var parameters = new TestJobParams("Test Job", TimeSpan.FromSeconds(1)); var ser = JsonConvert.SerializeObject(parameters); _jobDefinition = new JobQueueItemEntity { JobId = Guid.NewGuid(), Name = "jobDefinition Name", Serialized = ser, Type = "NodeTest.JobHandlers.TestJobParams" }; _nodeStartupNotification = new NodeStartupNotificationToManagerFake(_nodeConfigurationFake, new FakeHttpSender()); _trySendJobDetailToManagerTimerFake = new TrySendJobDetailToManagerTimerFake(_nodeConfigurationFake, new FakeHttpSender(), 1000); _pingToManagerFake = new PingToManagerFake(); _sendJobDoneTimer = new SendJobDoneTimerFake(_nodeConfigurationFake, _trySendJobDetailToManagerTimerFake, new FakeHttpSender()); _sendJobCanceledTimer = new SendJobCanceledTimerFake(_nodeConfigurationFake, _trySendJobDetailToManagerTimerFake, new FakeHttpSender()); _sendJobFaultedTimer = new SendJobFaultedTimerFake(_nodeConfigurationFake, _trySendJobDetailToManagerTimerFake, new FakeHttpSender()); }
public void DoTheThing(TestJobParams message, CancellationTokenSource cancellationTokenSource, Action <string> progress, ref IEnumerable <object> returnObjects) { // ----------------------------------------------------------- // Start execution. // ----------------------------------------------------------- var jobProgress = new TestJobProgress { Text = "Starting job: " + message.Name }; progress(jobProgress.Text); jobProgress = new TestJobProgress { Text = "Will execute for : " + message.Duration + " seconds." }; progress(jobProgress.Text); var stopwatch = new Stopwatch(); stopwatch.Start(); var progressCounter = 0; while (stopwatch.Elapsed <= TimeSpan.FromSeconds(message.Duration)) { progressCounter++; if (cancellationTokenSource.IsCancellationRequested) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); } jobProgress = new TestJobProgress { Text = "Progress loop number :" + progressCounter }; progress(jobProgress.Text); Thread.Sleep(TimeSpan.FromSeconds(1)); } // ----------------------------------------------------------- // Finished execution. // ----------------------------------------------------------- jobProgress = new TestJobProgress { Text = "Finished job: " + message.Name }; progress(jobProgress.Text); var objects = new List <object>(); objects.Add(new ExitApplication() { ExitCode = 0 }); returnObjects = objects; }
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); }