public void TestTriggerFireExclusion() { sched.Start(); TestJob.JobHasFired = false; JobDetailImpl myDesc = new JobDetailImpl("name", "group", typeof(TestJob)); IOperableTrigger trigger = new CronTriggerImpl("trigName", "trigGroup", "0/15 * * * * ?"); AnnualCalendar calendar = new AnnualCalendar(); calendar.SetDayExcluded(DateTime.Now, true); sched.AddCalendar("calendar", calendar, true, true); trigger.CalendarName = "calendar"; sched.ScheduleJob(myDesc, trigger); IOperableTrigger triggerreplace = new CronTriggerImpl("foo", "trigGroup", "name", "group", "0/15 * * * * ?"); triggerreplace.CalendarName = "calendar"; sched.RescheduleJob(new TriggerKey("trigName", "trigGroup"), triggerreplace); Thread.Sleep(1000 * 20); Assert.IsFalse(TestJob.JobHasFired, "task must not be neglected - it is forbidden by the calendar"); calendar.SetDayExcluded(DateTime.Now, false); sched.AddCalendar("calendar", calendar, true, true); Thread.Sleep(1000 * 20); Assert.IsTrue(TestJob.JobHasFired, "task must be neglected - it is permitted by the calendar"); sched.DeleteJob(new JobKey("name", "group")); sched.DeleteCalendar("calendar"); sched.Shutdown(); }
/// <summary> /// Get the object to serialize when generating serialized file for future /// tests, and against which to validate deserialized object. /// </summary> /// <returns></returns> protected override object GetTargetObject() { AnnualCalendar c = new AnnualCalendar(); c.Description = "description"; DateTime date = new DateTime(2005, 1, 20, 10, 5, 15); c.SetDayExcluded(date, true); return c; }
public void TestTriggerFireExclusion() { sched.Start(); TestJob.JobHasFired = false; IJobDetail jobDetail = JobBuilder.Create<TestJob>() .WithIdentity("name", "group") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigName", "trigGroup") .ModifiedByCalendar("calendar") .WithCronSchedule("0/15 * * * * ?") .Build(); AnnualCalendar calendar = new AnnualCalendar(); calendar.SetDayExcluded(DateTime.Now, true); sched.AddCalendar("calendar", calendar, true, true); sched.ScheduleJob(jobDetail, trigger); ITrigger triggerreplace = TriggerBuilder.Create() .WithIdentity("foo", "trigGroup") .ForJob(jobDetail) .ModifiedByCalendar("calendar") .WithCronSchedule("0/15 * * * * ?") .Build(); sched.RescheduleJob(new TriggerKey("trigName", "trigGroup"), triggerreplace); Thread.Sleep(TimeSpan.FromSeconds(20)); Assert.IsFalse(TestJob.JobHasFired, "task must not be neglected - it is forbidden by the calendar"); calendar.SetDayExcluded(DateTime.Now, false); sched.AddCalendar("calendar", calendar, true, true); Thread.Sleep(TimeSpan.FromSeconds(20)); Assert.IsTrue(TestJob.JobHasFired, "task must be neglected - it is permitted by the calendar"); sched.DeleteJob(new JobKey("name", "group")); sched.DeleteCalendar("calendar"); sched.Shutdown(); }
public void TestAnnualCalendarTimeZone() { TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); AnnualCalendar c = new AnnualCalendar(); c.TimeZone = tz; DateTimeOffset excludedDay = new DateTimeOffset(2012, 11, 4, 0, 0, 0, TimeSpan.Zero); c.SetDayExcluded(excludedDay, true); // 11/5/2012 12:00:00 AM -04:00 translate into 11/4/2012 11:00:00 PM -05:00 (EST) DateTimeOffset date = new DateTimeOffset(2012, 11, 5, 0, 0, 0, TimeSpan.FromHours(-4)); Assert.IsFalse(c.IsTimeIncluded(date), "date was expected to not be included."); Assert.IsTrue(c.IsTimeIncluded(date.AddDays(1))); DateTimeOffset expectedNextAvailable = new DateTimeOffset(2012, 11, 5, 0, 0, 0, TimeSpan.FromHours(-5)); DateTimeOffset actualNextAvailable = c.GetNextIncludedTimeUtc(date); Assert.AreEqual(expectedNextAvailable, actualNextAvailable); }
public virtual void Run() { ILog log = LogManager.GetLogger(typeof(CalendarExample)); log.Info("------- Initializing ----------------------"); // First we must get a reference to a scheduler ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sched = sf.GetScheduler(); log.Info("------- Initialization Complete -----------"); log.Info("------- Scheduling Jobs -------------------"); // Add the holiday calendar to the schedule AnnualCalendar holidays = new AnnualCalendar(); // fourth of July (July 4) DateTime fourthOfJuly = new DateTime(DateTime.UtcNow.Year, 7, 4); holidays.SetDayExcluded(fourthOfJuly, true); // halloween (Oct 31) DateTime halloween = new DateTime(DateTime.UtcNow.Year, 10, 31); holidays.SetDayExcluded(halloween, true); // christmas (Dec 25) DateTime christmas = new DateTime(DateTime.UtcNow.Year, 12, 25); holidays.SetDayExcluded(christmas, true); // tell the schedule about our holiday calendar sched.AddCalendar("holidays", holidays, false, false); // schedule a job to run hourly, starting on halloween // at 10 am DateTimeOffset runDate = DateBuilder.DateOf(0, 0, 10, 31, 10); IJobDetail job = JobBuilder.NewJob<SimpleJob>() .WithIdentity("job1", "group1") .Build(); ISimpleTrigger trigger = (ISimpleTrigger) TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartAt(runDate) .WithSchedule(SimpleScheduleBuilder.Create() .WithIntervalInHours(1) .RepeatForever()) .ModifiedByCalendar("holidays") .Build(); // schedule the job and print the first run date DateTimeOffset firstRunTime = sched.ScheduleJob(job, trigger); // print out the first execution date. // Note: Since Halloween (Oct 31) is a holiday, then // we will not run unti the next day! (Nov 1) log.Info(string.Format("{0} will run at: {1} and repeat: {2} times, every {3} seconds", job.Key, firstRunTime.ToString("r"), trigger.RepeatCount, trigger.RepeatInterval.TotalSeconds)); // All of the jobs have been added to the scheduler, but none of the jobs // will run until the scheduler has been started log.Info("------- Starting Scheduler ----------------"); sched.Start(); // wait 30 seconds: // note: nothing will run log.Info("------- Waiting 30 seconds... --------------"); try { // wait 30 seconds to show jobs Thread.Sleep(30 * 1000); // executing... } catch (ThreadInterruptedException) { } // shut down the scheduler log.Info("------- Shutting Down ---------------------"); sched.Shutdown(true); log.Info("------- Shutdown Complete -----------------"); SchedulerMetaData metaData = sched.GetMetaData(); log.Info(string.Format("Executed {0} jobs.", metaData.NumberOfJobsExecuted)); }
public void TestRemoveInTheFuture() { AnnualCalendar annualCalendar = new AnnualCalendar(); DateTime day = new DateTime(2005, 6, 23); annualCalendar.SetDayExcluded(day, true); // Trying to remove the 23th of June day = new DateTime(2008, 6, 23); annualCalendar.SetDayExcluded(day, false); Assert.IsFalse(annualCalendar.IsDayExcluded(day), "The day 23 June is not expected to be excluded but it is"); }
public void TestDaysExcludedOverTime() { AnnualCalendar annualCalendar = new AnnualCalendar(); DateTime day = new DateTime(2005, 6, 23); annualCalendar.SetDayExcluded(day, true); day = new DateTime(2008, 2, 1); annualCalendar.SetDayExcluded(day, true); Assert.IsTrue(annualCalendar.IsDayExcluded(day), "The day 1 February is expected to be excluded but it is not"); }
static void InitializeAnnual(AnnualCalendar annualCalendar, IAnnualCalendar calendar) { annualCalendar.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(Persistent.Base.General.RegistryTimeZoneProvider.GetRegistryKeyNameByTimeZoneId(calendar.TimeZone)); calendar.DatesExcluded.ForEach(time => annualCalendar.SetDayExcluded(time, true)); calendar.DatesIncluded.ForEach(time => annualCalendar.SetDayExcluded(time, false)); }
public void BaseCalendarShouldNotAffectSettingInternalDataStructures() { var dayToExclude = new DateTime(2015, 1, 1); AnnualCalendar a = new AnnualCalendar(); a.SetDayExcluded(dayToExclude, true); AnnualCalendar b = new AnnualCalendar(a); b.SetDayExcluded(dayToExclude, true); b.CalendarBase = null; Assert.That(b.IsDayExcluded(dayToExclude), "day was no longer excluded after base calendar was detached"); }