Exemplo n.º 1
0
        public void TestJobHistory()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow),
                JobEnabled         = true
            };

            var jobInputs = new List <JobScriptInput>()
            {
                new JobScriptInput()
                {
                    InputId    = "scriptInput1",
                    InputName  = "scriptInput1",
                    InputValue = "scriptValue1"
                },
                new JobScriptInput()
                {
                    InputId    = "scriptInput2",
                    InputName  = "scriptInput2",
                    InputValue = "scriptValue2"
                },
            };
            var result = this.JobScheduleRepository.SaveJobSchedule(jobSchedule, jobInputs);

            this.JobScheduleRepository.StartJob(jobSchedule);
            this.JobScheduleRepository.FinishJob(jobSchedule);
            int count;

            this.JobScheduleRepository.GetJobHistory(jobSchedule, out count);
            Assert.That(count == 1);
        }
Exemplo n.º 2
0
        public void TestCannotActivateRunningJob()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow),
                JobEnabled         = true
            };

            var jobInputs = new List <JobScriptInput>()
            {
                new JobScriptInput()
                {
                    InputId    = "scriptInput1",
                    InputName  = "scriptInput1",
                    InputValue = "scriptValue1"
                },
                new JobScriptInput()
                {
                    InputId    = "scriptInput2",
                    InputName  = "scriptInput2",
                    InputValue = "scriptValue2"
                },
            };
            var result = this.JobScheduleRepository.SaveJobSchedule(jobSchedule, jobInputs);
            var status = this.JobScheduleRepository.StartJob(jobSchedule);

            Assert.That(status == JobActivationStatus.Started);
            var activationStatus = this.JobScheduleRepository.ActivateJob(jobSchedule);

            Assert.That(activationStatus == JobActivationStatus.AlreadyRunning);
        }
Exemplo n.º 3
0
        public void TestSaveJobSchedule()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow),
                JobEnabled         = true
            };

            var jobInputs = new List <JobScriptInput>()
            {
                new JobScriptInput()
                {
                    InputId    = "scriptInput1",
                    InputName  = "scriptInput1",
                    InputValue = "scriptValue1"
                },
                new JobScriptInput()
                {
                    InputId    = "scriptInput2",
                    InputName  = "scriptInput2",
                    InputValue = "scriptValue2"
                },
            };

            var result = this.JobScheduleRepository.SaveJobSchedule(jobSchedule, jobInputs);

            Assert.That(result > 0);
            Assert.That(this.JobScheduleRepository.GetJobInputs(jobSchedule).All(jsi => jsi.JobScheduleId != 0 && jsi.JobScheduleId == jobSchedule.Id));
        }
Exemplo n.º 4
0
        public void TestJobsOutOfBounds()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow.AddMinutes(-3)),
                NextExecutionTime  = DateTime.UtcNow
            };

            var okAsWell = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow.AddMinutes(-3)),
                NextExecutionTime  = DateTime.UtcNow.AddHours(-4)
            };

            var tooEarly = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow.AddMinutes(-3)),
                NextExecutionTime  = DateTime.UtcNow.AddDays(-3)
            };

            var tooLate = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow.AddMinutes(3)),
                NextExecutionTime  = DateTime.UtcNow.AddDays(3)
            };

            jobSchedule.Id = this.JobScheduleRepository.Create(jobSchedule);
            tooLate.Id     = this.JobScheduleRepository.Create(tooLate);
            tooEarly.Id    = this.JobScheduleRepository.Create(tooEarly);
            var jobList = this.JobScheduleRepository.GetJobSchedules(DateTime.UtcNow);
            var ids     = jobList.Select(j => j.Id).ToList();

            Assert.That(ids.Contains(jobSchedule.Id), string.Format("There should be one job (id {0}) in the result", jobSchedule.Id));
            Assert.That(ids.Contains(tooEarly.Id), string.Format("Job id {0} expected but not found (fail on checking for old jobs", tooEarly.Id));
            Assert.That(!ids.Contains(tooLate.Id), string.Format("Did not expect jobs of ids {0}, but found those jobs (too late)", tooLate.Id));
        }
        public void TestSunday()
        {
            var now = DateTime.UtcNow;
            var timeOfDaySeconds = JobSchedule.TimeSeconds(now);
            var execNow          = now.Date.AddDays(6 - (int)now.DayOfWeek).Add(JobSchedule.TimeOfDay(timeOfDaySeconds));

            var jobsSchedule = new JobSchedule()
            {
                ExecutionTime     = timeOfDaySeconds,
                ExecutionSchedule = 1
            };
            var nextExecutionTime = jobsSchedule.GetNextExecution(execNow);
            var expectedResult    = execNow.AddDays(1);

            Assert.That(nextExecutionTime.Equals(expectedResult), string.Format("Expected next execution time of {0}, got {1}", expectedResult, nextExecutionTime));
        }
Exemplo n.º 6
0
        public void TestCurrentJobsToExecute()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow.AddMinutes(-3)),
                NextExecutionTime  = DateTime.UtcNow
            };

            jobSchedule.Id = this.JobScheduleRepository.Create(jobSchedule);
            var jobList = this.JobScheduleRepository.GetJobSchedules(DateTime.UtcNow);

            Assert.That(jobList.Where(j => j.Id == jobSchedule.Id).Any(), "Expected at least one active job schedule");
        }
Exemplo n.º 7
0
        public void TestCompetingStartup()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow)
            };

            jobSchedule.Id = this.JobScheduleRepository.Create(jobSchedule);
            var status     = this.JobScheduleRepository.StartJob(jobSchedule);
            var nextStatus = this.JobScheduleRepository.StartJob(jobSchedule);

            Assert.That(
                status == JobActivationStatus.Started && nextStatus == JobActivationStatus.AlreadyRunning,
                string.Format("Expected to find job statuses of Started and AlreadyRunning, found {0} and {1}", status.ToString(), nextStatus.ToString()));
        }
        public void TestEverydayExecution()
        {
            var now = DateTime.UtcNow;
            var timeOfDaySeconds = JobSchedule.TimeSeconds(now);
            var execNow          = now.Date.Add(JobSchedule.TimeOfDay(timeOfDaySeconds));

            var jobSchedule = new JobSchedule()
            {
                ExecutionTime = timeOfDaySeconds,

                // 0111 1111 in hex
                ExecutionSchedule = 0x7F
            };

            var nextExecutionTime = jobSchedule.GetNextExecution(execNow);
            var expectedResult    = execNow.AddDays(1);

            Assert.That(nextExecutionTime.Equals(expectedResult), string.Format("Expected next execution time of {0}, got {1}", expectedResult, nextExecutionTime));
        }
Exemplo n.º 9
0
        public void TestJobHistoryPaging()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow),
                JobEnabled         = true
            };

            var jobInputs = new List <JobScriptInput>()
            {
                new JobScriptInput()
                {
                    InputId    = "scriptInput1",
                    InputName  = "scriptInput1",
                    InputValue = "scriptValue1"
                },
                new JobScriptInput()
                {
                    InputId    = "scriptInput2",
                    InputName  = "scriptInput2",
                    InputValue = "scriptValue2"
                },
            };
            var result = this.JobScheduleRepository.SaveJobSchedule(jobSchedule, jobInputs);

            for (int x = 0; x < 50; x++)
            {
                this.JobScheduleRepository.StartJob(jobSchedule);
                this.JobScheduleRepository.FinishJob(jobSchedule);
            }

            int count;
            var page = this.JobScheduleRepository.GetJobHistory(jobSchedule, out count, 0, 10);

            Assert.That(count == 50);
            var nextPage = this.JobScheduleRepository.GetJobHistory(jobSchedule, out count, 1, 10).ToDictionary(jh => jh.Id, jh => true);

            Assert.That(page.All(p => !nextPage.ContainsKey(p.Id)), "Page should be distinct");
        }
Exemplo n.º 10
0
        public void TestJobFinish()
        {
            var jobSchedule = new JobSchedule()
            {
                RelativityScriptId = TEST_SCRIPT_ID,
                WorkspaceId        = TEST_WORKSPACE_ID,
                ExecutionSchedule  = 0x7F,
                ExecutionTime      = JobSchedule.TimeSeconds(DateTime.UtcNow),
                NextExecutionTime  = DateTime.UtcNow
            };

            jobSchedule.Id = this.JobScheduleRepository.Create(jobSchedule);
            this.JobScheduleRepository.StartJob(jobSchedule);
            jobSchedule.CurrentJobHistory.StartTime = jobSchedule.CurrentJobHistory.StartTime.AddSeconds(-3);
            this.JobScheduleRepository.FinishJob(jobSchedule);
            var lastExecution = this.JobScheduleRepository.GetLastJobExecution(jobSchedule);

            Assert.That(lastExecution != null, "Expected a last execution record");
            Assert.That(lastExecution.Runtime > 0, "Expected a non-zero runtime duration");
        }