public async Task TestAcquireTriggers() { ISchedulerSignaler schedSignaler = new SampleSignaler(); ITypeLoadHelper loadHelper = new SimpleTypeLoadHelper(); loadHelper.Initialize(); var store = new RavenJobStore { Database = "QuartzTest", Urls = "[\"http://localhost:8080\"]" }; await store.Initialize(loadHelper, schedSignaler); await store.SchedulerStarted(); // Setup: Store jobs and triggers. var startTime0 = DateTime.UtcNow.AddMinutes(1).ToUniversalTime(); // a min from now. for (var i = 0; i < 10; i++) { var startTime = startTime0.AddMinutes(i * 1); // a min apart var job = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build(); var schedule = SimpleScheduleBuilder.RepeatMinutelyForever(2); var trigger = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("trigger" + 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. var fireTime = trigger.ComputeFirstFireTimeUtc(null); Assert.AreEqual(true, fireTime != null); await store.StoreJobAndTrigger(job, trigger); } // Test acquire one trigger at a time for (var i = 0; i < 10; i++) { DateTimeOffset noLaterThan = startTime0.AddMinutes(i); var maxCount = 1; var timeWindow = TimeSpan.Zero; var triggers = (await store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow)).ToList(); Assert.AreEqual(1, triggers.Count); Assert.AreEqual("trigger" + i, triggers[0].Key.Name); // Let's remove the trigger now. await store.RemoveJob(triggers[0].JobKey); } }
public void TestAcquireTriggers() { InitJobStore(); ISchedulerSignaler schedSignaler = new SampleSignaler(); ITypeLoadHelper loadHelper = new SimpleTypeLoadHelper(); loadHelper.Initialize(); var store = new RavenJobStore(); store.Initialize(loadHelper, schedSignaler); store.SchedulerStarted(); // 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("trigger" + 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 one trigger at a time for (int i = 0; i < 10; i++) { DateTimeOffset noLaterThan = startTime0.AddMinutes(i); int maxCount = 1; TimeSpan timeWindow = TimeSpan.Zero; IList <IOperableTrigger> triggers = store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow); Assert.AreEqual(1, triggers.Count); Assert.AreEqual("trigger" + i, triggers[0].Key.Name); // Let's remove the trigger now. store.RemoveJob(triggers[0].JobKey); } }