public void TestAddTriggerListener() { string[] listenerNames = new string[] { "X", "A", "B" }; // Verify that a HashSet shuffles order, so we know that order test // below is actually testing something HashSet hashSet = new HashSet(listenerNames); Assert.IsFalse(new ArrayList(listenerNames).Equals(new ArrayList(hashSet))); SimpleTrigger simpleTrigger = new SimpleTrigger(); for (int i = 0; i < listenerNames.Length; i++) { simpleTrigger.AddTriggerListener(listenerNames[i]); } // Make sure order was maintained TestUtil.AssertCollectionEquality(new ArrayList(listenerNames), new ArrayList(simpleTrigger.TriggerListenerNames)); // Make sure uniqueness is enforced for (int i = 0; i < listenerNames.Length; i++) { try { simpleTrigger.AddTriggerListener(listenerNames[i]); Assert.Fail(); } catch (ArgumentException) { } } }
/// <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() { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.Put("A", "B"); SimpleTrigger t = new SimpleTrigger("SimpleTrigger", "SimpleGroup", "JobName", "JobGroup", StartTime, EndTime, 5, TimeSpan.FromSeconds(1)); t.CalendarName = "MyCalendar"; t.Description = "SimpleTriggerDesc"; t.JobDataMap = jobDataMap; t.MisfireInstruction = (MisfireInstruction.SimpleTrigger.RescheduleNextWithRemainingCount); t.Volatile = true; t.AddTriggerListener("L1"); t.AddTriggerListener("L2"); return(t); }
public void TestClone() { SimpleTrigger simpleTrigger = new SimpleTrigger(); // Make sure empty sub-objects are cloned okay Trigger clone = (Trigger)simpleTrigger.Clone(); Assert.AreEqual(0, clone.TriggerListenerNames.Length); Assert.AreEqual(0, clone.JobDataMap.Count); // Make sure non-empty sub-objects are cloned okay simpleTrigger.AddTriggerListener("L1"); simpleTrigger.AddTriggerListener("L2"); simpleTrigger.JobDataMap.Put("K1", "V1"); simpleTrigger.JobDataMap.Put("K2", "V2"); clone = (Trigger)simpleTrigger.Clone(); Assert.AreEqual(2, clone.TriggerListenerNames.Length); TestUtil.AssertCollectionEquality(new ArrayList(new string[] { "L1", "L2" }), new ArrayList(clone.TriggerListenerNames)); Assert.AreEqual(2, clone.JobDataMap.Count); Assert.AreEqual("V1", clone.JobDataMap.Get("K1")); Assert.AreEqual("V2", clone.JobDataMap.Get("K2")); // Make sure sub-object collections have really been cloned by ensuring // their modification does not change the source Trigger clone.RemoveTriggerListener("L2"); Assert.AreEqual(1, clone.TriggerListenerNames.Length); TestUtil.AssertCollectionEquality(new ArrayList(new string[] { "L1" }), new ArrayList(clone.TriggerListenerNames)); clone.JobDataMap.Remove("K1"); Assert.AreEqual(1, clone.JobDataMap.Count); Assert.AreEqual(2, simpleTrigger.TriggerListenerNames.Length); TestUtil.AssertCollectionEquality(new ArrayList(new string[] { "L1", "L2" }), new ArrayList(simpleTrigger.TriggerListenerNames)); Assert.AreEqual(2, simpleTrigger.JobDataMap.Count); Assert.AreEqual("V1", simpleTrigger.JobDataMap.Get("K1")); Assert.AreEqual("V2", simpleTrigger.JobDataMap.Get("K2")); }
private void RunAdoJobStoreTest(string dbProvider, string connectionStringId, NameValueCollection extraProperties) { NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "TestScheduler"; properties["quartz.scheduler.instanceId"] = "instance_one"; properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "10"; properties["quartz.threadPool.threadPriority"] = "Normal"; properties["quartz.jobStore.misfireThreshold"] = "60000"; properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz"; properties["quartz.jobStore.useProperties"] = "false"; properties["quartz.jobStore.dataSource"] = "default"; properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; properties["quartz.jobStore.clustered"] = clustered.ToString(); if (extraProperties != null) { foreach (string key in extraProperties.Keys) { properties[key] = extraProperties[key]; } } if (connectionStringId == "SQLServer" || connectionStringId == "SQLite") { // if running MS SQL Server we need this properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"; } properties["quartz.dataSource.default.connectionString"] = (string)dbConnectionStrings[connectionStringId]; properties["quartz.dataSource.default.provider"] = dbProvider; // First we must get a reference to a scheduler ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); try { if (clearJobs) { CleanUp(sched); } if (scheduleJobs) { ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?"); ICalendar holidayCalendar = new HolidayCalendar(); // QRTZNET-86 Trigger t = sched.GetTrigger("NonExistingTrigger", "NonExistingGroup"); Assert.IsNull(t); AnnualCalendar cal = new AnnualCalendar(); sched.AddCalendar("annualCalendar", cal, false, true); SimpleTrigger calendarsTrigger = new SimpleTrigger("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5)); calendarsTrigger.CalendarName = "annualCalendar"; JobDetail jd = new JobDetail("testJob", "test", typeof(NoOpJob)); sched.ScheduleJob(jd, calendarsTrigger); // QRTZNET-93 sched.AddCalendar("annualCalendar", cal, true, true); sched.AddCalendar("baseCalendar", new BaseCalendar(), false, true); sched.AddCalendar("cronCalendar", cronCalendar, false, true); sched.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true); sched.AddCalendar("holidayCalendar", holidayCalendar, false, true); sched.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true); sched.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true); sched.AddCalendar("cronCalendar", cronCalendar, true, true); sched.AddCalendar("holidayCalendar", holidayCalendar, true, true); Assert.IsNotNull(sched.GetCalendar("annualCalendar")); JobDetail lonelyJob = new JobDetail("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob)); lonelyJob.Durable = true; lonelyJob.RequestsRecovery = true; sched.AddJob(lonelyJob, false); sched.AddJob(lonelyJob, true); sched.AddJobListener(new DummyJobListener()); sched.AddTriggerListener(new DummyTriggerListener()); string schedId = sched.SchedulerInstanceId; int count = 1; JobDetail job = new JobDetail("job_" + count, schedId, typeof(SimpleRecoveryJob)); job.AddJobListener(new DummyJobListener().Name); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; SimpleTrigger trigger = new SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5)); trigger.AddTriggerListener(new DummyTriggerListener().Name); trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L); sched.ScheduleJob(job, trigger); // check that trigger was stored Trigger persisted = sched.GetTrigger("trig_" + count, schedId); Assert.IsNotNull(persisted); Assert.IsTrue(persisted is SimpleTrigger); count++; job = new JobDetail("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 SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5)); trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L)); sched.ScheduleJob(job, trigger); count++; job = new JobDetail("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 SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3)); trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L)); sched.ScheduleJob(job, trigger); count++; job = new JobDetail("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 SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4)); trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L)); sched.ScheduleJob(job, trigger); count++; job = new JobDetail("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 SimpleTrigger("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500)); sched.ScheduleJob(job, trigger); count++; job = new JobDetail("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); CronTrigger ct = new CronTrigger("cron_trig_" + count, schedId, "0/10 * * * * ?"); ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000); sched.ScheduleJob(job, ct); count++; job = new JobDetail("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); NthIncludedDayTrigger nt = new NthIncludedDayTrigger("cron_trig_" + count, schedId); nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000); nt.N = 1; sched.ScheduleJob(job, nt); sched.Start(); sched.PauseAll(); sched.ResumeAll(); sched.PauseJob("job_1", schedId); sched.ResumeJob("job_1", schedId); sched.PauseJobGroup(schedId); Thread.Sleep(1000); sched.ResumeJobGroup(schedId); sched.PauseTrigger("trig_2", schedId); sched.ResumeTrigger("trig_2", schedId); sched.PauseTriggerGroup(schedId); Assert.AreEqual(1, sched.GetPausedTriggerGroups().Count); Thread.Sleep(1000); sched.ResumeTriggerGroup(schedId); Thread.Sleep(TimeSpan.FromSeconds(20)); sched.Standby(); Assert.IsNotEmpty(sched.GetCalendarNames()); Assert.IsNotEmpty(sched.GetJobNames(schedId)); Assert.IsNotEmpty(sched.GetTriggersOfJob("job_2", schedId)); Assert.IsNotNull(sched.GetJobDetail("job_2", schedId)); sched.RemoveJobListener(new DummyJobListener().Name); sched.RemoveTriggerListener(new DummyTriggerListener().Name); sched.DeleteCalendar("cronCalendar"); sched.DeleteCalendar("holidayCalendar"); sched.DeleteJob("lonelyJob", "lonelyGroup"); } } finally { sched.Shutdown(false); } }