public void TestSchedulerWithSpringObjectJobFactoryAndRunnable() { DummyRunnable.param = 0; DummyRunnable.count = 0; JobDetail jobDetail = new JobDetailObject(); jobDetail.JobType = typeof(DummyRunnable); jobDetail.Name = ("myJob"); jobDetail.JobDataMap.Add("param", "10"); SimpleTriggerObject trigger = new SimpleTriggerObject(); trigger.Name = ("myTrigger"); trigger.JobDetail = (jobDetail); trigger.StartDelay = TimeSpan.FromMilliseconds(1); trigger.RepeatInterval = TimeSpan.FromMilliseconds(500); trigger.RepeatCount = (1); trigger.AfterPropertiesSet(); SchedulerFactoryObject factoryObject = new SchedulerFactoryObject(); factoryObject.JobFactory = (new SpringObjectJobFactory()); factoryObject.Triggers = (new Trigger[] { trigger }); factoryObject.JobDetails = (new JobDetail[] { jobDetail }); factoryObject.AfterPropertiesSet(); factoryObject.Start(); Thread.Sleep(500); Assert.AreEqual(10, DummyRunnable.param); Assert.IsTrue(DummyRunnable.count > 0); factoryObject.Dispose(); }
public async Task TestSchedulerWithSpringObjectJobFactoryAndRunnable() { DummyRunnable.param = 0; DummyRunnable.count = 0; JobDetailObject jobDetail = new JobDetailObject(); jobDetail.JobType = typeof(DummyRunnable); jobDetail.Name = "myJob"; jobDetail.JobDataMap.Add("param", "10"); SimpleTriggerObject trigger = new SimpleTriggerObject(); trigger.Name = "myTrigger"; trigger.JobDetail = jobDetail; trigger.StartDelay = TimeSpan.FromMilliseconds(1); trigger.RepeatInterval = TimeSpan.FromMilliseconds(500); trigger.RepeatCount = 1; trigger.AfterPropertiesSet(); SchedulerFactoryObject factoryObject = new SchedulerFactoryObject(); factoryObject.JobFactory = new SpringObjectJobFactory(); factoryObject.Triggers = new ITrigger[] { trigger }; factoryObject.JobDetails = new IJobDetail[] { jobDetail }; factoryObject.AfterPropertiesSet(); await factoryObject.Start(); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.AreEqual(10, DummyRunnable.param); Assert.IsTrue(DummyRunnable.count > 0); factoryObject.Dispose(); }
public async Task TestSchedulerWithRunnable() { DummyRunnable.count = 0; JobDetailImpl jobDetail = new JobDetailObject(); jobDetail.JobType = typeof(DummyRunnable); jobDetail.Name = "myJob"; SimpleTriggerObject trigger = new SimpleTriggerObject(); trigger.Name = "myTrigger"; trigger.JobDetail = jobDetail; trigger.StartDelay = TimeSpan.FromMilliseconds(1); trigger.RepeatInterval = TimeSpan.FromMilliseconds(500); trigger.RepeatCount = 1; trigger.AfterPropertiesSet(); SchedulerFactoryObject factoryObject = new SchedulerFactoryObject(); factoryObject.Triggers = new ITrigger[] { trigger }; factoryObject.JobDetails = new IJobDetail[] { jobDetail }; factoryObject.AfterPropertiesSet(); await factoryObject.Start(); DummyRunnable.runEvent.WaitOne(1000); Assert.IsTrue(DummyRunnable.count > 0); factoryObject.Dispose(); }
public void TestJobDetailObjectWithListenerNames() { JobDetailObject jobDetail = new JobDetailObject(); String[] names = new String[] { "test1", "test2" }; jobDetail.JobListenerNames = (names); ArrayList result = new ArrayList(jobDetail.JobListenerNames); Assert.AreEqual(names, result); }
public void TestJobDetailObjectWithApplicationContext() { TestObject tb = new TestObject("tb", 99); StaticApplicationContext ac = new StaticApplicationContext(); JobDetailObject jobDetail = new JobDetailObject(); jobDetail.JobType = typeof(IJob); jobDetail.ObjectName = "myJob0"; IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail.JobDataAsMap = jobData; jobDetail.ApplicationContext = ac; jobDetail.ApplicationContextJobDataKey = "appCtx"; jobDetail.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail.JobDataMap.Get("testObject")); Assert.AreEqual(ac, jobDetail.JobDataMap.Get("appCtx")); }
private async Task DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof(IJob); jobDetail0.ObjectName = "myJob0"; IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = jobData; jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = "myTrigger0"; trigger0.JobDetail = jobDetail0; trigger0.CronExpressionString = "0/1 * * * * ?"; trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = "myJob1"; mijdfb.TargetObject = task1; mijdfb.TargetMethod = "doSomething"; mijdfb.AfterPropertiesSet(); IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = "myTrigger1"; trigger1.JobDetail = jobDetail1; trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = A.Fake <IScheduler>(); A.CallTo(() => scheduler.Context).Returns(new SchedulerContext()); A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <IJobDetail>(null)); A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(null)); A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(new SimpleTriggerImpl())); if (overwrite) { await scheduler.AddJob(jobDetail1, true); A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1, A <CancellationToken> ._)).Returns(DateTime.UtcNow); } A.CallTo(() => scheduler.ScheduleJob(trigger0, A <CancellationToken> ._)).Throws(new ObjectAlreadyExistsException("")); if (overwrite) { A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0, A <CancellationToken> ._)).Returns(DateTime.UtcNow); } await scheduler.Start(); await scheduler.Shutdown(false); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = null; IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = schedulerContext; schedulerFactoryObject.Triggers = new ITrigger[] { trigger0, trigger1 }; if (overwrite) { schedulerFactoryObject.OverwriteExistingJobs = true; } try { schedulerFactoryObject.AfterPropertiesSet(); await schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened(); }
public void SetUp() { jobDetail = new JobDetailObject(); }
private void DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof(IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); if (prototypeJob) { StaticListableObjectFactory objectFactory = new StaticListableObjectFactory(); objectFactory.AddObject("task", task1); mijdfb.TargetObjectName = ("task"); mijdfb.ObjectFactory = objectFactory; } else { mijdfb.TargetObject = (task1); } mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = MockRepository.GenerateMock <IScheduler>(); scheduler.Stub(x => x.Context).Return(new SchedulerContext()); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); if (explicitJobDetail) { schedulerFactoryObject.JobDetails = (new IJobDetail[] { jobDetail0 }); } schedulerFactoryObject.Triggers = (new ITrigger[] { trigger0, trigger1 }); try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } scheduler.AssertWasCalled(x => x.ScheduleJob(trigger0)); scheduler.AssertWasCalled(x => x.ScheduleJob(trigger1)); scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true)); scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true)); scheduler.AssertWasCalled(x => x.Start()); scheduler.AssertWasCalled(x => x.Shutdown(false)); }
private void DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof(IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); mijdfb.TargetObject = (task1); mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = MockRepository.GenerateMock <IScheduler>(); scheduler.Stub(x => x.Context).Return(new SchedulerContext()); scheduler.Stub(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup))).Return(new SimpleTriggerImpl()); if (overwrite) { scheduler.AddJob(jobDetail1, true); scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1)).Return(DateTime.UtcNow); } scheduler.Stub(x => x.ScheduleJob(trigger0)).Throw(new ObjectAlreadyExistsException("")); if (overwrite) { scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0)).Return(DateTime.UtcNow); } scheduler.Start(); scheduler.Shutdown(false); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); schedulerFactoryObject.Triggers = (new ITrigger[] { trigger0, trigger1 }); if (overwrite) { schedulerFactoryObject.OverwriteExistingJobs = (true); } try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true)); }
private void DoTestSchedulerFactoryObjectWithExistingJobs(bool overwrite) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof(IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); mijdfb.TargetObject = (task1); mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); JobDetail jobDetail1 = (JobDetail)mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = (IScheduler)mockery.CreateMock(typeof(IScheduler)); Expect.Call(scheduler.Context).Return(new SchedulerContext()); Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null); Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger()); if (overwrite) { scheduler.AddJob(jobDetail1, true); LastCall.IgnoreArguments(); Expect.Call(scheduler.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return( DateTime.UtcNow); } else { Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null); } scheduler.AddJob(jobDetail0, true); LastCall.IgnoreArguments(); Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow); scheduler.Start(); scheduler.Shutdown(false); mockery.ReplayAll(); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); schedulerFactoryObject.Triggers = (new Trigger[] { trigger0, trigger1 }); if (overwrite) { schedulerFactoryObject.OverwriteExistingJobs = (true); } try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } mockery.VerifyAll(); }
public void TestSchedulerWithSpringObjectJobFactoryAndRunnable() { DummyRunnable.param = 0; DummyRunnable.count = 0; JobDetail jobDetail = new JobDetailObject(); jobDetail.JobType = typeof (DummyRunnable); jobDetail.Name = ("myJob"); jobDetail.JobDataMap.Add("param", "10"); SimpleTriggerObject trigger = new SimpleTriggerObject(); trigger.Name = ("myTrigger"); trigger.JobDetail = (jobDetail); trigger.StartDelay = TimeSpan.FromMilliseconds(1); trigger.RepeatInterval = TimeSpan.FromMilliseconds(500); trigger.RepeatCount = (1); trigger.AfterPropertiesSet(); SchedulerFactoryObject factoryObject = new SchedulerFactoryObject(); factoryObject.JobFactory = (new SpringObjectJobFactory()); factoryObject.Triggers = (new Trigger[] {trigger}); factoryObject.JobDetails = (new JobDetail[] {jobDetail}); factoryObject.AfterPropertiesSet(); factoryObject.Start(); Thread.Sleep(500); Assert.AreEqual(10, DummyRunnable.param); Assert.IsTrue(DummyRunnable.count > 0); factoryObject.Dispose(); }
public void TestSchedulerWithRunnable() { DummyRunnable.count = 0; JobDetail jobDetail = new JobDetailObject(); jobDetail.JobType = typeof (DummyRunnable); jobDetail.Name = "myJob"; SimpleTriggerObject trigger = new SimpleTriggerObject(); trigger.Name = "myTrigger"; trigger.JobDetail = jobDetail; trigger.StartDelay = TimeSpan.FromMilliseconds(1); trigger.RepeatInterval = TimeSpan.FromMilliseconds(500); trigger.RepeatCount = 1; trigger.AfterPropertiesSet(); SchedulerFactoryObject factoryObject = new SchedulerFactoryObject(); factoryObject.Triggers = new Trigger[] {trigger}; factoryObject.JobDetails = new JobDetail[] {jobDetail}; factoryObject.AfterPropertiesSet(); factoryObject.Start(); DummyRunnable.runEvent.WaitOne(500); Assert.IsTrue(DummyRunnable.count > 0); factoryObject.Dispose(); }
public void TestJobDetailObjectWithListenerNames() { JobDetailObject jobDetail = new JobDetailObject(); String[] names = new String[] {"test1", "test2"}; jobDetail.JobListenerNames = (names); ArrayList result = new ArrayList(jobDetail.JobListenerNames); Assert.AreEqual(names, result); }
public void TestJobDetailObjectWithApplicationContext() { TestObject tb = new TestObject("tb", 99); StaticApplicationContext ac = new StaticApplicationContext(); JobDetailObject jobDetail = new JobDetailObject(); jobDetail.JobType = typeof (IJob); jobDetail.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail.JobDataAsMap = (jobData); jobDetail.ApplicationContext = (ac); jobDetail.ApplicationContextJobDataKey = ("appCtx"); jobDetail.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail.JobDataMap.Get("testObject")); Assert.AreEqual(ac, jobDetail.JobDataMap.Get("appCtx")); }
private void DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof (IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); if (prototypeJob) { StaticListableObjectFactory objectFactory = new StaticListableObjectFactory(); objectFactory.AddObject("task", task1); mijdfb.TargetObjectName = ("task"); mijdfb.ObjectFactory = objectFactory; } else { mijdfb.TargetObject = (task1); } mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = MockRepository.GenerateMock<IScheduler>(); scheduler.Stub(x => x.Context).Return(new SchedulerContext()); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); if (explicitJobDetail) { schedulerFactoryObject.JobDetails = (new JobDetail[] {jobDetail0}); } schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1}); try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } scheduler.AssertWasCalled(x => x.ScheduleJob(trigger0)); scheduler.AssertWasCalled(x => x.ScheduleJob(trigger1)); scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true)); scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true)); scheduler.AssertWasCalled(x => x.Start()); scheduler.AssertWasCalled(x => x.Shutdown(false)); }
private async Task DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof(IJob); jobDetail0.ObjectName = "myJob0"; IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = jobData; jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = "myTrigger0"; trigger0.JobDetail = jobDetail0; trigger0.CronExpressionString = "0/1 * * * * ?"; trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = "myJob1"; if (prototypeJob) { StaticListableObjectFactory objectFactory = new StaticListableObjectFactory(); objectFactory.AddObject("task", task1); mijdfb.TargetObjectName = "task"; mijdfb.ObjectFactory = objectFactory; } else { mijdfb.TargetObject = task1; } mijdfb.TargetMethod = "doSomething"; mijdfb.AfterPropertiesSet(); IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = "myTrigger1"; trigger1.JobDetail = jobDetail1; trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = A.Fake <IScheduler>(); A.CallTo(() => scheduler.Context).Returns(new SchedulerContext()); A.CallTo(() => scheduler.GetTrigger(A <TriggerKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(null)); A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <IJobDetail>(null)); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = null; IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = schedulerContext; if (explicitJobDetail) { schedulerFactoryObject.JobDetails = new IJobDetail[] { jobDetail0 }; } schedulerFactoryObject.Triggers = new ITrigger[] { trigger0, trigger1 }; try { schedulerFactoryObject.AfterPropertiesSet(); await schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } A.CallTo(() => scheduler.ScheduleJob(trigger0, A <CancellationToken> ._)).MustHaveHappened(); A.CallTo(() => scheduler.ScheduleJob(trigger1, A <CancellationToken> ._)).MustHaveHappened(); A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened(); A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened(); A.CallTo(() => scheduler.Start(A <CancellationToken> ._)).MustHaveHappened(); A.CallTo(() => scheduler.Shutdown(false, A <CancellationToken> ._)).MustHaveHappened(); }
private void DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof (IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); mijdfb.TargetObject = (task1); mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = MockRepository.GenerateMock<IScheduler>(); scheduler.Stub(x => x.Context).Return(new SchedulerContext()); #if QUARTZ_2_0 scheduler.Stub(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup))).Return(new SimpleTrigger()); #else scheduler.Stub(x => x.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger()); #endif if (overwrite) { scheduler.AddJob(jobDetail1, true); #if QUARTZ_2_0 scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1)).Return(DateTime.UtcNow); #else scheduler.Stub(x => x.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return(DateTime.UtcNow); #endif } scheduler.Stub(x => x.ScheduleJob(trigger0)).Throw(new ObjectAlreadyExistsException("")); if (overwrite) { #if QUARTZ_2_0 scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0)).Return(DateTime.UtcNow); #else scheduler.Stub(x => x.RescheduleJob("myTrigger0", SchedulerConstants.DefaultGroup, trigger0)).Return(DateTime.UtcNow); #endif } scheduler.Start(); scheduler.Shutdown(false); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1}); if (overwrite) { schedulerFactoryObject.OverwriteExistingJobs = (true); } try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true)); }
public void SetUp() { jobDetail = new JobDetailObject(); }
private void DoTestSchedulerFactoryObjectWithExistingJobs(bool overwrite) { TestObject tb = new TestObject("tb", 99); JobDetailObject jobDetail0 = new JobDetailObject(); jobDetail0.JobType = typeof (IJob); jobDetail0.ObjectName = ("myJob0"); IDictionary jobData = new Hashtable(); jobData.Add("testObject", tb); jobDetail0.JobDataAsMap = (jobData); jobDetail0.AfterPropertiesSet(); Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject")); CronTriggerObject trigger0 = new CronTriggerObject(); trigger0.ObjectName = ("myTrigger0"); trigger0.JobDetail = (jobDetail0); trigger0.CronExpressionString = ("0/1 * * * * ?"); trigger0.AfterPropertiesSet(); TestMethodInvokingTask task1 = new TestMethodInvokingTask(); MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject(); mijdfb.ObjectName = ("myJob1"); mijdfb.TargetObject = (task1); mijdfb.TargetMethod = ("doSomething"); mijdfb.AfterPropertiesSet(); JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject(); SimpleTriggerObject trigger1 = new SimpleTriggerObject(); trigger1.ObjectName = ("myTrigger1"); trigger1.JobDetail = (jobDetail1); trigger1.StartDelay = TimeSpan.FromMilliseconds(0); trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20); trigger1.AfterPropertiesSet(); IScheduler scheduler = (IScheduler) mockery.CreateMock(typeof (IScheduler)); Expect.Call(scheduler.Context).Return(new SchedulerContext()); Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null); Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger()); if (overwrite) { scheduler.AddJob(jobDetail1, true); LastCall.IgnoreArguments(); Expect.Call(scheduler.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return( DateTime.UtcNow); } else { Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null); } scheduler.AddJob(jobDetail0, true); LastCall.IgnoreArguments(); Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow); scheduler.Start(); scheduler.Shutdown(false); mockery.ReplayAll(); SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler); schedulerFactoryObject.JobFactory = (null); IDictionary schedulerContext = new Hashtable(); schedulerContext.Add("otherTestObject", tb); schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext); schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1}); if (overwrite) { schedulerFactoryObject.OverwriteExistingJobs = (true); } try { schedulerFactoryObject.AfterPropertiesSet(); schedulerFactoryObject.Start(); } finally { schedulerFactoryObject.Dispose(); } mockery.VerifyAll(); }