Beispiel #1
0
        public async Task TestAcquireTriggers()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            RAMJobStore store = new RAMJobStore();
            await store.Initialize(loadHelper, schedSignaler);

            // Setup: Store jobs and triggers.
            DateTime startTime0 = DateTime.UtcNow.AddMinutes(1).ToUniversalTime(); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTime              startTime = startTime0.AddMinutes(i * 1); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                await store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire one trigger at a time
            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset noLaterThan = startTime0.AddMinutes(i);
                int            maxCount    = 1;
                TimeSpan       timeWindow  = TimeSpan.Zero;
                var            triggers    = await store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);

                Assert.AreEqual(1, triggers.Count);
                var trigger = triggers.First();
                Assert.AreEqual("job" + i, trigger.Key.Name);

                // Let's remove the trigger now.
                await store.RemoveJob(trigger.JobKey);
            }
        }
        public void TestAcquireTriggersInBatch()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            RAMJobStore store = new RAMJobStore();

            store.Initialize(loadHelper, schedSignaler);

            // Setup: Store jobs and triggers.
            DateTimeOffset startTime0 = DateTimeOffset.UtcNow.AddMinutes(1); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset        startTime = startTime0.AddMinutes(i); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire batch of triggers at a time
            DateTimeOffset           noLaterThan = startTime0.AddMinutes(10);
            int                      maxCount    = 7;
            TimeSpan                 timeWindow  = TimeSpan.FromMinutes(8);
            IList <IOperableTrigger> triggers    = store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);

            Assert.AreEqual(7, triggers.Count);
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual("job" + i, triggers[i].Key.Name);
            }
        }