Inheritance: AbstractTrigger, ICalendarIntervalTrigger
        public void TestMonthlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 1, 6, 2005);

            var yearlyTrigger = new CalendarIntervalTriggerImpl
            {
                StartTimeUtc = startCalendar,
                RepeatIntervalUnit = IntervalUnit.Month,
                RepeatInterval = 5 // every five months
            };

            DateTimeOffset targetCalendar = startCalendar.AddMonths(25); // jump 25 five months (5 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 6);
            DateTimeOffset sixthTime = fireTimes[5]; // get the sixth fire time

            Assert.AreEqual(targetCalendar, sixthTime, "Month increment result not as expected.");
        }
Ejemplo n.º 2
0
        public void TestDailyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            CalendarIntervalTriggerImpl dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 90; // every ninety days

            DateTimeOffset targetCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            targetCalendar = targetCalendar.AddDays(360); // jump 360 days (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            DateTimeOffset fifthTime = fireTimes[4]; // get the fifth fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Day increment result not as expected.");
        }
        public void TestWeeklyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 1, 6, 2005);

            var yearlyTrigger = new CalendarIntervalTriggerImpl
            {
                StartTimeUtc = startCalendar,
                RepeatIntervalUnit = IntervalUnit.Week,
                RepeatInterval = 6 // every six weeks
            };

            DateTimeOffset targetCalendar = startCalendar.AddDays(7*6*4); // jump 24 weeks (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 7);
            DateTimeOffset fifthTime = fireTimes[4]; // get the fifth fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Week increment result not as expected.");
        }
        public void TestDailyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 1, 6, 2005);

            var dailyTrigger = new CalendarIntervalTriggerImpl
                                                           {
                                                               StartTimeUtc = startCalendar,
                                                               RepeatIntervalUnit = IntervalUnit.Day,
                                                               RepeatInterval = 90  // every ninety days
                                                           };

            DateTimeOffset targetCalendar = startCalendar.AddDays(360); // jump 360 days (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            DateTimeOffset fifthTime = fireTimes[4]; // get the fifth fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Day increment result not as expected.");
        }
        public void TestYearlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 1, 6, 2005);

            var yearlyTrigger = new CalendarIntervalTriggerImpl
            {
                StartTimeUtc = startCalendar,
                RepeatIntervalUnit = IntervalUnit.Year,
                RepeatInterval = 2 // every two years;
            };

            DateTimeOffset targetCalendar = startCalendar.AddYears(4);

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 4);
            DateTimeOffset thirdTime = fireTimes[2]; // get the third fire time

            Assert.AreEqual(targetCalendar, thirdTime, "Year increment result not as expected.");
        }
        public void TestDaylightSavingsTransitions()
        {
            // Pick a day before a daylight savings transition...

            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 12, 3, 2010);

            var dailyTrigger = new CalendarIntervalTriggerImpl
                                                           {
                                                               StartTimeUtc = startCalendar,
                                                               RepeatIntervalUnit = IntervalUnit.Day,
                                                               RepeatInterval = 5   // every 5 days
                                                           };

            DateTimeOffset targetCalendar = startCalendar.AddDays(10); // jump 10 days (2 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            DateTimeOffset testTime = fireTimes[2]; // get the third fire time

            Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over spring daylight savings transition.");

            // Pick a day before a daylight savings transition...

            startCalendar = new DateTimeOffset(2010, 10, 31, 9, 30, 17, TimeSpan.Zero);

            dailyTrigger = new CalendarIntervalTriggerImpl
                               {
                                   StartTimeUtc = startCalendar,
                                   RepeatIntervalUnit = IntervalUnit.Day,
                                   RepeatInterval = 5   // every 5 days
                               };

            targetCalendar = startCalendar.AddDays(15); // jump 15 days (3 intervals)

            fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            testTime = fireTimes[3]; // get the fourth fire time

            Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over fall daylight savings transition.");
        }
        public void TestCrossingDSTBoundry()
        {
            TimeZoneInfo cetTimeZone = TimeZoneUtil.FindTimeZoneById("Central European Standard Time");
            DateTimeOffset startCalendar = TimeZoneUtil.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone);

            CalendarIntervalTriggerImpl dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 1;
            dailyTrigger.TimeZone = cetTimeZone;
            dailyTrigger.PreserveHourOfDayAcrossDaylightSavings = true;

            var fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);

            //none of these should match the previous fire time.
            for (int i = 1; i < fireTimes.Count; i++)
            {
                var previousFire = fireTimes[i - 1];
                var currentFire = fireTimes[i];

                Assert.AreNotEqual(previousFire, currentFire);
            }
        }
Ejemplo n.º 8
0
        public void TestFinalFireTimes()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2010, 3, 12, 9, 0, 0, TimeSpan.Zero);

            CalendarIntervalTriggerImpl dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 5; // every 5 days

            DateTimeOffset endCalendar = startCalendar;
            endCalendar = endCalendar.AddDays(10); // jump 10 days (2 intervals)
            dailyTrigger.EndTimeUtc = endCalendar;

            DateTimeOffset? testTime = dailyTrigger.FinalFireTimeUtc;

            Assert.AreEqual(endCalendar, testTime, "Final fire time not computed correctly for day interval.");

            startCalendar = new DateTimeOffset(2010, 3, 12, 9, 0, 0, TimeSpan.Zero);

            dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Minute;
            dailyTrigger.RepeatInterval = 5; // every 5 minutes

            endCalendar = startCalendar;
            endCalendar = endCalendar.AddDays(15); // jump 15 days
            endCalendar = endCalendar.AddMinutes(-2); // back up two minutes
            dailyTrigger.EndTimeUtc = endCalendar;

            testTime = dailyTrigger.FinalFireTimeUtc;

            Assert.IsTrue((endCalendar > (testTime)), "Final fire time not computed correctly for minutely interval.");

            endCalendar = endCalendar.AddMinutes(-3); // back up three more minutes

            Assert.IsTrue((endCalendar.Equals(testTime)), "Final fire time not computed correctly for minutely interval.");
        }
        public void TestSecondlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 1, 6, 2005);

            var yearlyTrigger = new CalendarIntervalTriggerImpl
                                                            {
                                                                StartTimeUtc = startCalendar,
                                                                RepeatIntervalUnit = IntervalUnit.Second,
                                                                RepeatInterval = 100    // every 100 seconds
                                                            };

            DateTimeOffset targetCalendar = startCalendar.AddSeconds(400); // jump 400 seconds (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 6);
            DateTimeOffset fifthTime = fireTimes[4]; // get the third fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Seconds increment result not as expected.");
        }
        public void TestMisfireInstructionValidity()
        {
            var trigger = new CalendarIntervalTriggerImpl();

            try
            {
                trigger.MisfireInstruction = MisfireInstruction.IgnoreMisfirePolicy;
                trigger.MisfireInstruction = MisfireInstruction.SmartPolicy;
                trigger.MisfireInstruction = MisfireInstruction.CalendarIntervalTrigger.DoNothing;
                trigger.MisfireInstruction = MisfireInstruction.CalendarIntervalTrigger.FireOnceNow;
            }
            catch (Exception)
            {
                Assert.Fail("Unexpected exception while setting misfire instruction.");
            }

            try
            {
                trigger.MisfireInstruction = MisfireInstruction.CalendarIntervalTrigger.DoNothing + 1;

                Assert.Fail("Expected exception while setting invalid misfire instruction but did not get it.");
            }
            catch (Exception ex)
            {
                if (ex is AssertionException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 11
0
        public void TestYearlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            CalendarIntervalTriggerImpl yearlyTrigger = new CalendarIntervalTriggerImpl();
            yearlyTrigger.StartTimeUtc = startCalendar;
            yearlyTrigger.RepeatIntervalUnit = IntervalUnit.Year;
            yearlyTrigger.RepeatInterval = 2; // every two years;

            DateTimeOffset targetCalendar = new DateTimeOffset(2009, 6, 1, 9, 30, 17, TimeSpan.Zero); // jump 4 years (2 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 4);
            DateTimeOffset secondTime = fireTimes[2]; // get the third fire time

            Assert.AreEqual(targetCalendar, secondTime, "Year increment result not as expected.");
        }
Ejemplo n.º 12
0
        protected override object GetTargetObject()
        {
            JobDataMap jobDataMap = new JobDataMap();
            jobDataMap["A"] =  "B";

            CalendarIntervalTriggerImpl t = new CalendarIntervalTriggerImpl();
            t.Name = "test";
            t.Group = "testGroup";
            t.CalendarName = "MyCalendar";
            t.Description = "CronTriggerDesc";
            t.JobDataMap = jobDataMap;
            t.RepeatInterval = 5;
            t.RepeatIntervalUnit = IntervalUnit.Day;

            return t;
        }
Ejemplo n.º 13
0
        public void TestSecondlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            CalendarIntervalTriggerImpl yearlyTrigger = new CalendarIntervalTriggerImpl();
            yearlyTrigger.StartTimeUtc = startCalendar;
            yearlyTrigger.RepeatIntervalUnit = IntervalUnit.Second;
            yearlyTrigger.RepeatInterval = 100; // every 100 seconds

            DateTimeOffset targetCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            targetCalendar = targetCalendar.AddSeconds(400); // jump 400 seconds (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 6);
            DateTimeOffset fifthTime = fireTimes[4]; // get the third fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Seconds increment result not as expected.");
        }
Ejemplo n.º 14
0
        public void TestWeeklyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            CalendarIntervalTriggerImpl yearlyTrigger = new CalendarIntervalTriggerImpl();
            yearlyTrigger.StartTimeUtc = startCalendar;
            yearlyTrigger.RepeatIntervalUnit = IntervalUnit.Week;
            yearlyTrigger.RepeatInterval = 6; // every six weeks

            DateTimeOffset targetCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            targetCalendar = targetCalendar.AddDays(7 * 6 * 4); // jump 24 weeks (4 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 7);
            DateTimeOffset fifthTime = fireTimes[4]; // get the fifth fire time

            Console.Out.WriteLine("targetCalendar:" + targetCalendar);
            Console.Out.WriteLine("fifthTimee" + fifthTime);

            Assert.AreEqual(targetCalendar, fifthTime, "Week increment result not as expected.");
        }
        public void TestDaylightSavingsTransitions()
        {
            // Pick a day before a spring daylight savings transition...

            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 12, 3, 2010);

            var dailyTrigger = new CalendarIntervalTriggerImpl
            {
                StartTimeUtc = startCalendar,
                RepeatIntervalUnit = IntervalUnit.Day,
                RepeatInterval = 5 // every 5 days
            };

            DateTimeOffset targetCalendar = startCalendar.AddDays(10); // jump 10 days (2 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            DateTimeOffset testTime = fireTimes[2]; // get the third fire time

            Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over spring 2010 daylight savings transition.");

            // And again, Pick a day before a spring daylight savings transition... (QTZ-240)

            startCalendar = new DateTime(2011, 3, 12, 1, 0, 0);

            dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 1; // every day

            targetCalendar = startCalendar.AddDays(2); // jump 2 days (2 intervals)

            fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            testTime = fireTimes[2]; // get the third fire time

            Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over spring 2011 daylight savings transition.");

            // And again, Pick a day before a spring daylight savings transition... (QTZ-240) - and prove time of day is not preserved without setPreserveHourOfDayAcrossDaylightSavings(true)

            var cetTimeZone = TimeZoneUtil.FindTimeZoneById("Central European Standard Time");
            startCalendar = TimeZoneInfo.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone);

            dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 1; // every day

            targetCalendar = TimeZoneUtil.ConvertTime(startCalendar, cetTimeZone);
            targetCalendar = targetCalendar.AddDays(2); // jump 2 days (2 intervals)

            fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);

            testTime = fireTimes[2]; // get the third fire time

            DateTimeOffset testCal = TimeZoneUtil.ConvertTime(testTime, cetTimeZone);

            Assert.AreNotEqual(targetCalendar.Hour, testCal.Hour, "Day increment time-of-day result not as expected over spring 2011 daylight savings transition.");

            // And again, Pick a day before a spring daylight savings transition... (QTZ-240) - and prove time of day is preserved with setPreserveHourOfDayAcrossDaylightSavings(true)

            startCalendar = TimeZoneUtil.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone);

            dailyTrigger = new CalendarIntervalTriggerImpl();
            dailyTrigger.StartTimeUtc = startCalendar;
            dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day;
            dailyTrigger.RepeatInterval = 1; // every day
            dailyTrigger.TimeZone = cetTimeZone;
            dailyTrigger.PreserveHourOfDayAcrossDaylightSavings = true;

            targetCalendar = startCalendar.AddDays(2); // jump 2 days (2 intervals)

            fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);

            testTime = fireTimes[1]; // get the second fire time

            testCal = TimeZoneUtil.ConvertTime(testTime, cetTimeZone);

            Assert.AreEqual(targetCalendar.Hour, testCal.Hour, "Day increment time-of-day result not as expected over spring 2011 daylight savings transition.");

            // Pick a day before a fall daylight savings transition...

            startCalendar = new DateTimeOffset(2010, 10, 31, 9, 30, 17, TimeSpan.Zero);

            dailyTrigger = new CalendarIntervalTriggerImpl
            {
                StartTimeUtc = startCalendar,
                RepeatIntervalUnit = IntervalUnit.Day,
                RepeatInterval = 5 // every 5 days
            };

            targetCalendar = startCalendar.AddDays(15); // jump 15 days (3 intervals)

            fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6);
            testTime = fireTimes[3]; // get the fourth fire time

            Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over fall daylight savings transition.");
        }
        public void ShouldGetScheduleBuilderWithSameSettingsAsTrigger()
        {
            var startTime = DateTimeOffset.UtcNow;
            var endTime = DateTimeOffset.UtcNow.AddDays(1);
            var trigger = new CalendarIntervalTriggerImpl("name", "group", startTime, endTime, IntervalUnit.Hour, 10);
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;
            trigger.SkipDayIfHourDoesNotExist = true;
            trigger.TimeZone = TimeZoneInfo.Utc;
            trigger.MisfireInstruction = MisfireInstruction.CalendarIntervalTrigger.FireOnceNow;
            var scheduleBuilder = trigger.GetScheduleBuilder();

            var cloned = (CalendarIntervalTriggerImpl) scheduleBuilder.Build();
            Assert.That(cloned.PreserveHourOfDayAcrossDaylightSavings, Is.EqualTo(trigger.PreserveHourOfDayAcrossDaylightSavings));
            Assert.That(cloned.SkipDayIfHourDoesNotExist, Is.EqualTo(trigger.SkipDayIfHourDoesNotExist));
            Assert.That(cloned.RepeatInterval, Is.EqualTo(trigger.RepeatInterval));
            Assert.That(cloned.RepeatIntervalUnit, Is.EqualTo(trigger.RepeatIntervalUnit));
            Assert.That(cloned.MisfireInstruction, Is.EqualTo(trigger.MisfireInstruction));
            Assert.That(cloned.TimeZone, Is.EqualTo(trigger.TimeZone));
        }
        public void TestMovingAcrossDSTAvoidsInfiniteLoop()
        {
            TimeZoneInfo est = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");
            DateTimeOffset startDate = new DateTimeOffset(1990, 10, 27, 0, 0, 0, TimeSpan.FromHours(-4));

            CalendarIntervalTriggerImpl t = new CalendarIntervalTriggerImpl();
            t.RepeatInterval = 1;
            t.RepeatIntervalUnit = IntervalUnit.Day;
            t.PreserveHourOfDayAcrossDaylightSavings = true;
            t.SkipDayIfHourDoesNotExist = false;
            t.StartTimeUtc = startDate;
            t.TimeZone = est;

            var fireTimes = TriggerUtils.ComputeFireTimes(t, null, 10);

            var firstFire = fireTimes[0];
            var secondFire = fireTimes[1];
            Assert.AreNotEqual(firstFire, secondFire);

            //try to trigger a shift in month
            startDate = new DateTimeOffset(2012, 6, 1, 0, 0, 0, TimeSpan.FromHours(-4));

            t = new CalendarIntervalTriggerImpl();
            t.RepeatInterval = 1;
            t.RepeatIntervalUnit = IntervalUnit.Month;
            t.PreserveHourOfDayAcrossDaylightSavings = true;
            t.SkipDayIfHourDoesNotExist = false;
            t.StartTimeUtc = startDate;
            t.TimeZone = est;

            fireTimes = TriggerUtils.ComputeFireTimes(t, null, 10);

            Assert.AreNotEqual(firstFire, secondFire);
        }
        public void TestPreserveHourOfDayAcrossDaylightSavingsNotHanging()
        {
            TimeZoneInfo est = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");

            DateTimeOffset startTime = new DateTimeOffset(2013, 3, 1, 4, 0, 0, TimeSpan.FromHours(-5));

            CalendarIntervalTriggerImpl trigger = new CalendarIntervalTriggerImpl();
            trigger.RepeatInterval = 1;
            trigger.RepeatIntervalUnit = IntervalUnit.Day;
            trigger.TimeZone = est;
            trigger.StartTimeUtc = startTime;
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;

            DateTimeOffset? fireTimeAfter = new DateTimeOffset(2013, 3, 10, 4, 0, 0, TimeSpan.FromHours(-4));

            DateTimeOffset? fireTime = trigger.GetFireTimeAfter(fireTimeAfter);

            Assert.AreNotEqual(fireTime, fireTimeAfter);
            Assert.IsTrue(fireTime > fireTimeAfter);
        }
        public void TestTimeZoneTransition()
        {
            TimeZoneInfo timeZone = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");

            CalendarIntervalTriggerImpl trigger = new CalendarIntervalTriggerImpl("trigger", IntervalUnit.Day, 1);
            trigger.TimeZone = timeZone;
            trigger.StartTimeUtc = new DateTimeOffset(2012, 11, 2, 12, 0, 0, TimeSpan.FromHours(-4));

            var fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 6);

            var expected = new DateTimeOffset(2012, 11, 2, 12, 0, 0, TimeSpan.FromHours(-4));
            Assert.AreEqual(expected, fireTimes[0]);

            expected = new DateTimeOffset(2012, 11, 3, 12, 0, 0, TimeSpan.FromHours(-4));
            Assert.AreEqual(expected, fireTimes[1]);

            //this next day should be a new daylight savings change, notice the change in offset
            expected = new DateTimeOffset(2012, 11, 4, 11, 0, 0, TimeSpan.FromHours(-5));
            Assert.AreEqual(expected, fireTimes[2]);

            expected = new DateTimeOffset(2012, 11, 5, 11, 0, 0, TimeSpan.FromHours(-5));
            Assert.AreEqual(expected, fireTimes[3]);
        }
        public void TestStartTimeOnDayInDifferentOffset()
        {
            TimeZoneInfo est = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");
            DateTimeOffset startDate = new DateTimeOffset(2012, 3, 11, 12, 0, 0, TimeSpan.FromHours(-5));

            CalendarIntervalTriggerImpl t = new CalendarIntervalTriggerImpl();
            t.RepeatInterval = 1;
            t.RepeatIntervalUnit = IntervalUnit.Day;
            t.PreserveHourOfDayAcrossDaylightSavings = true;
            t.SkipDayIfHourDoesNotExist = false;
            t.StartTimeUtc = startDate;
            t.TimeZone = est;

            var fireTimes = TriggerUtils.ComputeFireTimes(t, null, 10);

            var firstFire = fireTimes[0];
            var secondFire = fireTimes[1];

            Assert.AreNotEqual(firstFire, secondFire);
        }
        public void TestSkipDayIfItDoesNotExistsIsFalse()
        {
            TimeZoneInfo timeZone = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");

            //March 11, 2012, EST DST starts at 2am and jumps to 3.
            // 3/11/2012 2:00:00 AM is an invalid time

            //expected target will always be the on the next valid time, (3/11/2012 3am) in this case
            DateTimeOffset expectedTarget = new DateTimeOffset(2012, 3, 11, 3, 0, 0, TimeSpan.FromHours(-4));

            //-------------------------------------------------
            // DAILY
            //-------------------------------------------------

            CalendarIntervalTriggerImpl trigger = new CalendarIntervalTriggerImpl();
            trigger.TimeZone = timeZone;
            trigger.RepeatInterval = 1;
            trigger.RepeatIntervalUnit = IntervalUnit.Day;
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;
            trigger.SkipDayIfHourDoesNotExist = false;

            DateTimeOffset startDate = new DateTimeOffset(2012, 3, 10, 2, 0, 0, 0, TimeSpan.FromHours(-5));
            trigger.StartTimeUtc = startDate;

            var fires = TriggerUtils.ComputeFireTimes(trigger, null, 5);

            var targetTime = fires[1]; //get second fire

            Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist.");
            Assert.AreEqual(expectedTarget, targetTime);

            //-------------------------------------------------
            // WEEKLY
            //-------------------------------------------------
            trigger = new CalendarIntervalTriggerImpl();
            trigger.TimeZone = timeZone;
            trigger.RepeatInterval = 1;
            trigger.RepeatIntervalUnit = IntervalUnit.Week;
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;
            trigger.SkipDayIfHourDoesNotExist = false;

            startDate = new DateTimeOffset(2012, 3, 4, 2, 0, 0, 0, TimeSpan.FromHours(-5));
            trigger.StartTimeUtc = startDate;

            fires = TriggerUtils.ComputeFireTimes(trigger, null, 5);

            targetTime = fires[1]; //get second fire

            Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist.");
            Assert.AreEqual(expectedTarget, targetTime);

            //-------------------------------------------------
            // MONTHLY
            //-------------------------------------------------
            trigger = new CalendarIntervalTriggerImpl();
            trigger.TimeZone = timeZone;
            trigger.RepeatInterval = 1;
            trigger.RepeatIntervalUnit = IntervalUnit.Month;
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;
            trigger.SkipDayIfHourDoesNotExist = false;

            startDate = new DateTimeOffset(2012, 2, 11, 2, 0, 0, 0, TimeSpan.FromHours(-5));
            trigger.StartTimeUtc = startDate;

            fires = TriggerUtils.ComputeFireTimes(trigger, null, 5);

            targetTime = fires[1]; //get second fire

            Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist.");
            Assert.AreEqual(expectedTarget, targetTime);

            //-------------------------------------------------
            // YEARLY
            //-------------------------------------------------

            trigger = new CalendarIntervalTriggerImpl();
            trigger.TimeZone = timeZone;
            trigger.RepeatInterval = 1;
            trigger.RepeatIntervalUnit = IntervalUnit.Year;
            trigger.PreserveHourOfDayAcrossDaylightSavings = true;
            trigger.SkipDayIfHourDoesNotExist = false;

            startDate = new DateTimeOffset(2011, 3, 11, 2, 0, 0, 0, TimeSpan.FromHours(-5));
            trigger.StartTimeUtc = startDate;

            fires = TriggerUtils.ComputeFireTimes(trigger, null, 5);

            targetTime = fires[1]; //get second fire

            Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist.");
            Assert.AreEqual(expectedTarget, targetTime);
        }
        protected override object GetTargetObject()
        {
            var jobDataMap = new JobDataMap();
            jobDataMap["A"] =  "B";

            var t = new CalendarIntervalTriggerImpl
                                                {
                                                    Name = "test",
                                                    Group = "testGroup",
                                                    CalendarName = "MyCalendar",
                                                    Description = "CronTriggerDesc",
                                                    JobDataMap = jobDataMap,
                                                    RepeatInterval = 5,
                                                    RepeatIntervalUnit = IntervalUnit.Day
                                                };

            return t;
        }
Ejemplo n.º 23
0
        public void Test(IScheduler scheduler, bool clearJobs, bool scheduleJobs)
        {
            try
               {
               if (clearJobs)
               {
                   scheduler.Clear();
               }

               if (scheduleJobs)
               {
                   ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
                   ICalendar holidayCalendar = new HolidayCalendar();

                   // QRTZNET-86
                   ITrigger t = scheduler.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup"));
                   Assert.IsNull(t);

                   AnnualCalendar cal = new AnnualCalendar();
                   scheduler.AddCalendar("annualCalendar", cal, false, true);

                   IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
                   calendarsTrigger.CalendarName = "annualCalendar";

                   JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
                   scheduler.ScheduleJob(jd, calendarsTrigger);

                   // QRTZNET-93
                   scheduler.AddCalendar("annualCalendar", cal, true, true);

                   scheduler.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
                   scheduler.AddCalendar("cronCalendar", cronCalendar, false, true);
                   scheduler.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, false, true);
                   scheduler.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
                   scheduler.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);

                   scheduler.AddCalendar("cronCalendar", cronCalendar, true, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, true, true);

                   Assert.IsNotNull(scheduler.GetCalendar("annualCalendar"));

                   JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
                   lonelyJob.Durable = true;
                   lonelyJob.RequestsRecovery = true;
                   scheduler.AddJob(lonelyJob, false);
                   scheduler.AddJob(lonelyJob, true);

                   string schedId = scheduler.SchedulerInstanceId;

                   int count = 1;

                   JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));

                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = true;
                   IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));
                   trigger.JobDataMap.Add("key", "value");
                   trigger.EndTimeUtc = DateTime.UtcNow.AddYears(10);

                   trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
                   scheduler.ScheduleJob(job, trigger);

                   // check that trigger was stored
                   ITrigger persisted = scheduler.GetTrigger(new TriggerKey("trig_" + count, schedId));
                   Assert.IsNotNull(persisted);
                   Assert.IsTrue(persisted is SimpleTriggerImpl);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   IOperableTrigger ct = new CronTriggerImpl("cron_trig_" + count, schedId, "0/10 * * * * ?");
                   ct.JobDataMap.Add("key", "value");
                   ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, ct);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   DailyTimeIntervalTriggerImpl nt = new DailyTimeIntervalTriggerImpl("nth_trig_" + count, schedId, new TimeOfDay(1, 1, 1), new TimeOfDay(23, 30, 0), IntervalUnit.Hour, 1);
                   nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, nt);

                   DailyTimeIntervalTriggerImpl nt2 = new DailyTimeIntervalTriggerImpl();
                   nt2.Key = new TriggerKey("nth_trig2_" + count, schedId);
                   nt2.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);
                   nt2.JobKey = job.Key;
                   scheduler.ScheduleJob(nt2);

                   // GitHub issue #92
                   scheduler.GetTrigger(nt2.Key);

                   // GitHub issue #98
                   nt2.StartTimeOfDay = new TimeOfDay(1, 2, 3);
                   nt2.EndTimeOfDay = new TimeOfDay(2, 3, 4);

                   scheduler.UnscheduleJob(nt2.Key);
                   scheduler.ScheduleJob(nt2);

                   var triggerFromDb = (IDailyTimeIntervalTrigger) scheduler.GetTrigger(nt2.Key);
                   Assert.That(triggerFromDb.StartTimeOfDay.Hour, Is.EqualTo(1));
                   Assert.That(triggerFromDb.StartTimeOfDay.Minute, Is.EqualTo(2));
                   Assert.That(triggerFromDb.StartTimeOfDay.Second, Is.EqualTo(3));

                   Assert.That(triggerFromDb.EndTimeOfDay.Hour, Is.EqualTo(2));
                   Assert.That(triggerFromDb.EndTimeOfDay.Minute, Is.EqualTo(3));
                   Assert.That(triggerFromDb.EndTimeOfDay.Second, Is.EqualTo(4));

                   job.RequestsRecovery = (true);
                   CalendarIntervalTriggerImpl intervalTrigger = new CalendarIntervalTriggerImpl(
                       "calint_trig_" + count,
                       schedId,
                       DateTime.UtcNow.AddMilliseconds(300),
                       DateTime.UtcNow.AddMinutes(1),
                       IntervalUnit.Second,
                       8);
                   intervalTrigger.JobKey = job.Key;

                   scheduler.ScheduleJob(intervalTrigger);

                   // bulk operations
                   var info = new Dictionary<IJobDetail, Collection.ISet<ITrigger>>();
                   IJobDetail detail = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   ITrigger simple = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   var triggers = new Collection.HashSet<ITrigger>();
                   triggers.Add(simple);
                   info[detail] = triggers;

                   scheduler.ScheduleJobs(info, true);

                   Assert.IsTrue(scheduler.CheckExists(detail.Key));
                   Assert.IsTrue(scheduler.CheckExists(simple.Key));

                   // QRTZNET-243
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("a").DeepClone());

                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("a").DeepClone());

                   scheduler.Start();

                   Thread.Sleep(TimeSpan.FromSeconds(3));

                   scheduler.PauseAll();

                   scheduler.ResumeAll();

                   scheduler.PauseJob(new JobKey("job_1", schedId));

                   scheduler.ResumeJob(new JobKey("job_1", schedId));

                   scheduler.PauseJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   Thread.Sleep(TimeSpan.FromSeconds(1));

                   scheduler.ResumeJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   scheduler.PauseTrigger(new TriggerKey("trig_2", schedId));
                   scheduler.ResumeTrigger(new TriggerKey("trig_2", schedId));

                   scheduler.PauseTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.AreEqual(1, scheduler.GetPausedTriggerGroups().Count);

                   Thread.Sleep(TimeSpan.FromSeconds(3));
                   scheduler.ResumeTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.IsNotNull(scheduler.GetTrigger(new TriggerKey("trig_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_1", schedId)));
                   Assert.IsNotNull(scheduler.GetMetaData());
                   Assert.IsNotNull(scheduler.GetCalendar("weeklyCalendar"));

                   Thread.Sleep(TimeSpan.FromSeconds(20));

                   scheduler.Standby();

                   CollectionAssert.IsNotEmpty(scheduler.GetCalendarNames());
                   CollectionAssert.IsNotEmpty(scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(schedId)));

                   CollectionAssert.IsNotEmpty(scheduler.GetTriggersOfJob(new JobKey("job_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_2", schedId)));

                   scheduler.DeleteCalendar("cronCalendar");
                   scheduler.DeleteCalendar("holidayCalendar");
                   scheduler.DeleteJob(new JobKey("lonelyJob", "lonelyGroup"));
                   scheduler.DeleteJob(job.Key);

                   scheduler.GetJobGroupNames();
                   scheduler.GetCalendarNames();
                   scheduler.GetTriggerGroupNames();
               }
               }
               finally
               {
               scheduler.Shutdown(false);
               }
        }
        public void TestFinalFireTimes()
        {
            DateTimeOffset startCalendar = DateBuilder.DateOf(9, 0, 0, 12, 3, 2010);
            DateTimeOffset endCalendar = startCalendar.AddDays(10); // jump 10 days (2 intervals)

            var dailyTrigger = new CalendarIntervalTriggerImpl
                                                           {
                                                               StartTimeUtc = startCalendar,
                                                               RepeatIntervalUnit = IntervalUnit.Day,
                                                               RepeatInterval = 5,   // every 5 days
                                                               EndTimeUtc = endCalendar
                                                           };

            DateTimeOffset? testTime = dailyTrigger.FinalFireTimeUtc;

            Assert.AreEqual(endCalendar, testTime, "Final fire time not computed correctly for day interval.");

            endCalendar = startCalendar.AddDays(15).AddMinutes(-2); // jump 15 days and back up 2 minutes
            dailyTrigger = new CalendarIntervalTriggerImpl
                               {
                                   StartTimeUtc = startCalendar,
                                   RepeatIntervalUnit = IntervalUnit.Minute,
                                   RepeatInterval = 5,   // every 5 minutes
                                   EndTimeUtc = endCalendar
                               };

            testTime = dailyTrigger.FinalFireTimeUtc;

            Assert.IsTrue((endCalendar > (testTime)), "Final fire time not computed correctly for minutely interval.");

            endCalendar = endCalendar.AddMinutes(-3); // back up three more minutes

            Assert.IsTrue((endCalendar.Equals(testTime)), "Final fire time not computed correctly for minutely interval.");
        }
Ejemplo n.º 25
0
        public void TestMonthlyIntervalGetFireTimeAfter()
        {
            DateTimeOffset startCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            CalendarIntervalTriggerImpl yearlyTrigger = new CalendarIntervalTriggerImpl();
            yearlyTrigger.StartTimeUtc = startCalendar;
            yearlyTrigger.RepeatIntervalUnit = IntervalUnit.Month;
            yearlyTrigger.RepeatInterval = 5; // every five months

            DateTimeOffset targetCalendar = new DateTimeOffset(2005, 6, 1, 9, 30, 17, TimeSpan.Zero);

            targetCalendar = targetCalendar.AddMonths(25); // jump 25 five months (5 intervals)

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(yearlyTrigger, null, 6);
            DateTimeOffset fifthTime = fireTimes[5]; // get the sixth fire time

            Assert.AreEqual(targetCalendar, fifthTime, "Month increment result not as expected.");
        }