/// <summary> /// Creates an in memory job store (<see cref="RAMJobStore" />) /// The thread priority is set to Thread.NORM_PRIORITY /// </summary> /// <param name="maxThreads">The number of threads in the thread pool</param> public virtual void CreateVolatileScheduler(int maxThreads) { IThreadPool threadPool = new DefaultThreadPool(); threadPool.Initialize(); IJobStore jobStore = new RAMJobStore(); CreateScheduler(threadPool, jobStore); }
public void TestStoreAndRetriveTriggers() { RAMJobStore store = new RAMJobStore(); // Store jobs and triggers. for (int i = 0; i < 10; i++) { IJobDetail job = JobBuilder.Create<NoOpJob>().WithIdentity("job" + i).Build(); store.StoreJob(job, true); SimpleScheduleBuilder schedule = SimpleScheduleBuilder.Create(); ITrigger trigger = TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).Build(); store.StoreTrigger((IOperableTrigger) trigger, true); } // Retrieve job and trigger. for (int i = 0; i < 10; i++) { JobKey jobKey = JobKey.Create("job" + i); IJobDetail storedJob = store.RetrieveJob(jobKey); Assert.AreEqual(jobKey, storedJob.Key); TriggerKey triggerKey = new TriggerKey("job" + i); ITrigger storedTrigger = store.RetrieveTrigger(triggerKey); Assert.AreEqual(triggerKey, storedTrigger.Key); } }
public void testStoreAndRetrieveJobs() { RAMJobStore store = new RAMJobStore(); // Store jobs. for (int i = 0; i < 10; i++) { IJobDetail job = JobBuilder.Create<NoOpJob>().WithIdentity("job" + i).Build(); store.StoreJob(job, false); } // Retrieve jobs. for (int i = 0; i < 10; i++) { JobKey jobKey = JobKey.Create("job" + i); IJobDetail storedJob = store.RetrieveJob(jobKey); Assert.AreEqual(jobKey, storedJob.Key); } }
public void TestRetrieveTrigger_NoTriggerFound() { RAMJobStore store = new RAMJobStore(); IOperableTrigger trigger = store.RetrieveTrigger(new TriggerKey("not", "existing")); Assert.IsNull(trigger); }
public void TestRetrieveJob_NoJobFound() { RAMJobStore store = new RAMJobStore(); IJobDetail job = store.RetrieveJob(new JobKey("not", "existing")); Assert.IsNull(job); }
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); } }
/// <summary> /// Creates an in memory job store (<see cref="RAMJobStore" />) /// The thread priority is set to Thread.NORM_PRIORITY /// </summary> /// <param name="maxThreads">The number of threads in the thread pool</param> public virtual void CreateVolatileScheduler(int maxThreads) { SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, ThreadPriority.Normal); threadPool.Initialize(); IJobStore jobStore = new RAMJobStore(); CreateScheduler(threadPool, jobStore); }