public async Task TestStoreAndRetrieveJobs()
        {
            var store = new RavenJobStore
            {
                Database = "QuartzTest",
                Urls     = "[\"http://localhost:8080\"]"
            };
            await store.Initialize(null, fSignaler);

            // Store jobs.
            for (var i = 0; i < 10; i++)
            {
                var job = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                await store.StoreJob(job, false);
            }

            // Retrieve jobs.
            for (var i = 0; i < 10; i++)
            {
                var jobKey    = JobKey.Create("job" + i);
                var storedJob = await store.RetrieveJob(jobKey);

                Assert.AreEqual(jobKey, storedJob.Key);
            }
        }
        public async Task TestRetrieveTrigger_NoTriggerFound()
        {
            var store = new RavenJobStore
            {
                Database = "QuartzTest",
                Urls     = "[\"http://localhost:8080\"]"
            };
            await store.Initialize(null, fSignaler);

            var trigger = await store.RetrieveTrigger(new TriggerKey("not", "existing"));

            Assert.IsNull(trigger);
        }
        public async Task TestRetrieveJob_NoJobFound()
        {
            var store = new RavenJobStore
            {
                Database = "QuartzTest",
                Urls     = "[\"http://localhost:8080\"]"
            };
            await store.Initialize(null, fSignaler);

            var job = await store.RetrieveJob(new JobKey("not", "existing"));

            Assert.IsNull(job);
        }
        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);
            }
        }
Exemple #5
0
        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);
            }
        }
        private async Task InitJobStore()
        {
            fJobStore = new RavenJobStore
            {
                Database = "QuartzTest",
                Urls     = "[\"http://*****:*****@all_docs"));

            await op.WaitForCompletionAsync();

            await fJobStore.SchedulerStarted();

            fJobDetail = new JobDetailImpl("job1", "jobGroup1", typeof(NoOpJob))
            {
                Durable = true
            };
            await fJobStore.StoreJob(fJobDetail, true);
        }
        public async Task TestStoreAndRetrieveTriggers()
        {
            var store = new RavenJobStore
            {
                Database = "QuartzTest",
                Urls     = "[\"http://localhost:8080\"]"
            };
            await store.Initialize(null, fSignaler);

            await store.SchedulerStarted();

            // Store jobs and triggers.
            for (var i = 0; i < 10; i++)
            {
                var job = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                await store.StoreJob(job, true);

                var schedule = SimpleScheduleBuilder.Create();
                var trigger  = TriggerBuilder.Create().WithIdentity("trigger" + i).WithSchedule(schedule).ForJob(job)
                               .Build();
                await store.StoreTrigger((IOperableTrigger)trigger, true);
            }

            // Retrieve job and trigger.
            for (var i = 0; i < 10; i++)
            {
                var jobKey    = JobKey.Create("job" + i);
                var storedJob = await store.RetrieveJob(jobKey);

                Assert.AreEqual(jobKey, storedJob.Key);

                var      triggerKey    = new TriggerKey("trigger" + i);
                ITrigger storedTrigger = await store.RetrieveTrigger(triggerKey);

                Assert.AreEqual(triggerKey, storedTrigger.Key);
            }
        }