Beispiel #1
0
        public async Task TestBasicStorageFunctions()
        {
            IScheduler sched = await CreateScheduler("testBasicStorageFunctions", 2);

            await sched.Clear();

            // test basic storage functions of scheduler...
            IJobDetail job = JobBuilder.Create <TestJob>()
                             .WithIdentity("j1")
                             .StoreDurably()
                             .Build();

            Assert.That(await sched.CheckExists(new JobKey("j1")), Is.False, "Unexpected existence of job named 'j1'.");

            await sched.AddJob(job, false);

            Assert.That(await sched.CheckExists(new JobKey("j1")), "Expected existence of job named 'j1' but checkExists return false.");

            job = await sched.GetJobDetail(new JobKey("j1"));

            Assert.That(job, Is.Not.Null, "Stored job not found!");

            await sched.DeleteJob(new JobKey("j1"));

            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("t1")
                               .ForJob(job)
                               .StartNow()
                               .WithSimpleSchedule(x => x
                                                   .RepeatForever()
                                                   .WithIntervalInSeconds(5))
                               .Build();

            Assert.That(await sched.CheckExists(new TriggerKey("t1")), Is.False, "Unexpected existence of trigger named '11'.");

            await sched.ScheduleJob(job, trigger);

            Assert.That(await sched.CheckExists(new TriggerKey("t1")), "Expected existence of trigger named 't1' but checkExists return false.");

            job = await sched.GetJobDetail(new JobKey("j1"));

            Assert.That(job, Is.Not.Null, "Stored job not found!");

            trigger = await sched.GetTrigger(new TriggerKey("t1"));

            Assert.That(trigger, Is.Not.Null, "Stored trigger not found!");

            job = JobBuilder.Create <TestJob>()
                  .WithIdentity("j2", "g1")
                  .Build();

            trigger = TriggerBuilder.Create()
                      .WithIdentity("t2", "g1")
                      .ForJob(job)
                      .StartNow()
                      .WithSimpleSchedule(x => x
                                          .RepeatForever()
                                          .WithIntervalInSeconds(5))
                      .Build();

            await sched.ScheduleJob(job, trigger);

            job = JobBuilder.Create <TestJob>()
                  .WithIdentity("j3", "g1")
                  .Build();

            trigger = TriggerBuilder.Create()
                      .WithIdentity("t3", "g1")
                      .ForJob(job)
                      .StartNow()
                      .WithSimpleSchedule(x => x
                                          .RepeatForever()
                                          .WithIntervalInSeconds(5))
                      .Build();

            await sched.ScheduleJob(job, trigger);

            var jobGroups = await sched.GetJobGroupNames();

            var triggerGroups = await sched.GetTriggerGroupNames();

            Assert.That(jobGroups.Count, Is.EqualTo(2), "Job group list size expected to be = 2 ");
            Assert.That(triggerGroups.Count, Is.EqualTo(2), "Trigger group list size expected to be = 2 ");

            ISet <JobKey> jobKeys = await sched.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(JobKey.DefaultGroup));

            ISet <TriggerKey> triggerKeys = await sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals(TriggerKey.DefaultGroup));

            Assert.That(jobKeys.Count, Is.EqualTo(1), "Number of jobs expected in default group was 1 ");
            Assert.That(triggerKeys.Count, Is.EqualTo(1), "Number of triggers expected in default group was 1 ");

            jobKeys = await sched.GetJobKeys(GroupMatcher <JobKey> .GroupEquals("g1"));

            triggerKeys = await sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals("g1"));

            Assert.That(jobKeys.Count, Is.EqualTo(2), "Number of jobs expected in 'g1' group was 2 ");
            Assert.That(triggerKeys.Count, Is.EqualTo(2), "Number of triggers expected in 'g1' group was 2 ");

            TriggerState s = await sched.GetTriggerState(new TriggerKey("t2", "g1"));

            Assert.That(s.Equals(TriggerState.Normal), "State of trigger t2 expected to be NORMAL ");

            await sched.PauseTrigger(new TriggerKey("t2", "g1"));

            s = await sched.GetTriggerState(new TriggerKey("t2", "g1"));

            Assert.That(s.Equals(TriggerState.Paused), "State of trigger t2 expected to be PAUSED ");

            await sched.ResumeTrigger(new TriggerKey("t2", "g1"));

            s = await sched.GetTriggerState(new TriggerKey("t2", "g1"));

            Assert.That(s.Equals(TriggerState.Normal), "State of trigger t2 expected to be NORMAL ");

            ISet <string> pausedGroups = await sched.GetPausedTriggerGroups();

            Assert.That(pausedGroups, Is.Empty, "Size of paused trigger groups list expected to be 0 ");

            await sched.PauseTriggers(GroupMatcher <TriggerKey> .GroupEquals("g1"));

            // test that adding a trigger to a paused group causes the new trigger to be paused also...
            job = JobBuilder.Create <TestJob>()
                  .WithIdentity("j4", "g1")
                  .Build();

            trigger = TriggerBuilder.Create()
                      .WithIdentity("t4", "g1")
                      .ForJob(job)
                      .StartNow()
                      .WithSimpleSchedule(x => x.RepeatForever().WithIntervalInSeconds(5))
                      .Build();

            await sched.ScheduleJob(job, trigger);

            pausedGroups = await sched.GetPausedTriggerGroups();

            Assert.That(pausedGroups.Count, Is.EqualTo(1), "Size of paused trigger groups list expected to be 1 ");

            s = await sched.GetTriggerState(new TriggerKey("t2", "g1"));

            Assert.That(s.Equals(TriggerState.Paused), "State of trigger t2 expected to be PAUSED ");

            s = await sched.GetTriggerState(new TriggerKey("t4", "g1"));

            Assert.That(s.Equals(TriggerState.Paused), "State of trigger t4 expected to be PAUSED ");

            await sched.ResumeTriggers(GroupMatcher <TriggerKey> .GroupEquals("g1"));

            s = await sched.GetTriggerState(new TriggerKey("t2", "g1"));

            Assert.That(s.Equals(TriggerState.Normal), "State of trigger t2 expected to be NORMAL ");
            s = await sched.GetTriggerState(new TriggerKey("t4", "g1"));

            Assert.That(s.Equals(TriggerState.Normal), "State of trigger t4 expected to be NORMAL ");
            pausedGroups = await sched.GetPausedTriggerGroups();

            Assert.That(pausedGroups, Is.Empty, "Size of paused trigger groups list expected to be 0 ");

            Assert.That(await sched.UnscheduleJob(new TriggerKey("foasldfksajdflk")), Is.False, "Scheduler should have returned 'false' from attempt to unschedule non-existing trigger. ");

            Assert.That(await sched.UnscheduleJob(new TriggerKey("t3", "g1")), "Scheduler should have returned 'true' from attempt to unschedule existing trigger. ");

            jobKeys = await sched.GetJobKeys(GroupMatcher <JobKey> .GroupEquals("g1"));

            triggerKeys = await sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals("g1"));

            Assert.That(jobKeys.Count, Is.EqualTo(2), "Number of jobs expected in 'g1' group was 1 "); // job should have been deleted also, because it is non-durable
            Assert.That(triggerKeys.Count, Is.EqualTo(2), "Number of triggers expected in 'g1' group was 1 ");

            Assert.That(await sched.UnscheduleJob(new TriggerKey("t1")), "Scheduler should have returned 'true' from attempt to unschedule existing trigger. ");

            jobKeys = await sched.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(JobKey.DefaultGroup));

            triggerKeys = await sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals(TriggerKey.DefaultGroup));

            Assert.That(jobKeys.Count, Is.EqualTo(1), "Number of jobs expected in default group was 1 "); // job should have been left in place, because it is non-durable
            Assert.That(triggerKeys, Is.Empty, "Number of triggers expected in default group was 0 ");

            await sched.Shutdown();
        }
Beispiel #2
0
 public bool IsIdle()
 {
     return(CurrentTriggerState.Equals(TriggerState.IDLE));
 }