public async Task TestSchedulerFactoryObjectWithApplicationContext()
        {
            TestObject tb = new TestObject("tb", 99);
            StaticApplicationContext ac = new StaticApplicationContext();

            IScheduler       scheduler        = A.Fake <IScheduler>();
            SchedulerContext schedulerContext = new SchedulerContext();

            A.CallTo(() => scheduler.Context).Returns(schedulerContext).NumberOfTimes(4);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = null;
            IDictionary schedulerContextMap = new Hashtable();

            schedulerContextMap.Add("testObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = schedulerContextMap;
            schedulerFactoryObject.ApplicationContext    = ac;
            schedulerFactoryObject.ApplicationContextSchedulerContextKey = "appCtx";
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                await schedulerFactoryObject.Start();

                IScheduler returnedScheduler = (IScheduler)schedulerFactoryObject.GetObject();
                Assert.AreEqual(tb, returnedScheduler.Context["testObject"]);
                Assert.AreEqual(ac, returnedScheduler.Context["appCtx"]);
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }
        }
        public void TestSchedulerFactoryObjectWithApplicationContext()
        {
            TestObject tb = new TestObject("tb", 99);
            StaticApplicationContext ac = new StaticApplicationContext();

            IScheduler       scheduler        = MockRepository.GenerateMock <IScheduler>();
            SchedulerContext schedulerContext = new SchedulerContext();

            scheduler.Stub(x => x.Context).Return(schedulerContext).Repeat.Times(4);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContextMap = new Hashtable();

            schedulerContextMap.Add("testObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContextMap);
            schedulerFactoryObject.ApplicationContext    = (ac);
            schedulerFactoryObject.ApplicationContextSchedulerContextKey = ("appCtx");
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
                IScheduler returnedScheduler = (IScheduler)schedulerFactoryObject.GetObject();
                Assert.AreEqual(tb, returnedScheduler.Context["testObject"]);
                Assert.AreEqual(ac, returnedScheduler.Context["appCtx"]);
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }
        }
Beispiel #3
0
        public void TestSchedulerFactoryObjectWithListeners()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            IScheduler scheduler = (IScheduler)mockery.CreateMock(typeof(IScheduler));

            ISchedulerListener schedulerListener     = new TestSchedulerListener();
            IJobListener       globalJobListener     = new TestJobListener();
            IJobListener       jobListener           = new TestJobListener();
            ITriggerListener   globalTriggerListener = new TestTriggerListener();
            ITriggerListener   triggerListener       = new TestTriggerListener();

            Expect.Call(scheduler.JobFactory = (jobFactory));
            scheduler.AddSchedulerListener(schedulerListener);
            scheduler.AddGlobalJobListener(globalJobListener);
            scheduler.AddJobListener(jobListener);
            scheduler.AddGlobalTriggerListener(globalTriggerListener);
            scheduler.AddTriggerListener(triggerListener);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory             = (jobFactory);
            schedulerFactoryObject.SchedulerListeners     = (new ISchedulerListener[] { schedulerListener });
            schedulerFactoryObject.GlobalJobListeners     = (new IJobListener[] { globalJobListener });
            schedulerFactoryObject.JobListeners           = (new IJobListener[] { jobListener });
            schedulerFactoryObject.GlobalTriggerListeners = (new ITriggerListener[] { globalTriggerListener });
            schedulerFactoryObject.TriggerListeners       = (new ITriggerListener[] { triggerListener });
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
Beispiel #4
0
        public void TestSchedulerFactoryObjectWithApplicationContext()
        {
            TestObject tb = new TestObject("tb", 99);
            StaticApplicationContext ac = new StaticApplicationContext();

            IScheduler       scheduler        = (IScheduler)mockery.CreateMock(typeof(IScheduler));
            SchedulerContext schedulerContext = new SchedulerContext();

            Expect.Call(scheduler.Context).Return(schedulerContext).Repeat.Times(4);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContextMap = new Hashtable();

            schedulerContextMap.Add("testObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContextMap);
            schedulerFactoryObject.ApplicationContext    = (ac);
            schedulerFactoryObject.ApplicationContextSchedulerContextKey = ("appCtx");
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
                IScheduler returnedScheduler = (IScheduler)schedulerFactoryObject.GetObject();
                Assert.AreEqual(tb, returnedScheduler.Context["testObject"]);
                Assert.AreEqual(ac, returnedScheduler.Context["appCtx"]);
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
        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));
        }
        public void TestSchedulerFactoryObjectWithPlainQuartzObjects()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            TestObject    tb         = new TestObject("tb", 99);
            JobDetailImpl jobDetail0 = new JobDetailImpl();

            jobDetail0.JobType = typeof(IJob);
            jobDetail0.Name    = ("myJob0");
            jobDetail0.Group   = (SchedulerConstants.DefaultGroup);
            jobDetail0.JobDataMap.Add("testObject", tb);
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerImpl trigger0 = new CronTriggerImpl();

            trigger0.Name                 = ("myTrigger0");
            trigger0.Group                = SchedulerConstants.DefaultGroup;
            trigger0.JobName              = "myJob0";
            trigger0.JobGroup             = SchedulerConstants.DefaultGroup;
            trigger0.StartTimeUtc         = (DateTime.UtcNow);
            trigger0.CronExpressionString = ("0/1 * * * * ?");

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.Name         = ("myJob1");
            mijdfb.Group        = (SchedulerConstants.DefaultGroup);
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerImpl trigger1 = new SimpleTriggerImpl();

            trigger1.Name           = "myTrigger1";
            trigger1.Group          = SchedulerConstants.DefaultGroup;
            trigger1.JobName        = "myJob1";
            trigger1.JobGroup       = SchedulerConstants.DefaultGroup;
            trigger1.StartTimeUtc   = (DateTime.UtcNow);
            trigger1.RepeatCount    = (SimpleTriggerImpl.RepeatIndefinitely);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);

            IScheduler scheduler = MockRepository.GenerateMock <IScheduler>();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (jobFactory);
            schedulerFactoryObject.JobDetails = (new IJobDetail[] { jobDetail0, jobDetail1 });
            schedulerFactoryObject.Triggers   = (new ITrigger[] { trigger0, trigger1 });
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.JobFactory = jobFactory);
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true));
            scheduler.AssertWasCalled(x => x.GetJobDetail(new JobKey("myJob0", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetJobDetail(new JobKey("myJob1", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup)));
        }
        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 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));
        }
Beispiel #9
0
        public void TestSchedulerFactoryObjectWithPlainQuartzObjects()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            TestObject tb = new TestObject("tb", 99);
            JobDetail jobDetail0 = new JobDetail();
            jobDetail0.JobType = typeof (IJob);
            jobDetail0.Name = ("myJob0");
            jobDetail0.Group = (SchedulerConstants.DefaultGroup);
            jobDetail0.JobDataMap.Add("testObject", tb);
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTrigger trigger0 = new CronTrigger();
            trigger0.Name = ("myTrigger0");
            trigger0.Group = SchedulerConstants.DefaultGroup;
            trigger0.JobName = "myJob0";
            trigger0.JobGroup = SchedulerConstants.DefaultGroup;
            trigger0.StartTimeUtc = (DateTime.UtcNow);
            trigger0.CronExpressionString = ("0/1 * * * * ?");

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            mijdfb.Name = ("myJob1");
            mijdfb.Group = (SchedulerConstants.DefaultGroup);
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTrigger trigger1 = new SimpleTrigger();
            trigger1.Name = "myTrigger1";
            trigger1.Group = SchedulerConstants.DefaultGroup;
            trigger1.JobName = "myJob1";
            trigger1.JobGroup = SchedulerConstants.DefaultGroup;
            trigger1.StartTimeUtc = (DateTime.UtcNow);
            trigger1.RepeatCount = (SimpleTrigger.RepeatIndefinitely);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);

            IScheduler scheduler = (IScheduler) mockery.CreateMock(typeof (IScheduler));
            Expect.Call(scheduler.JobFactory = (jobFactory));
            Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetJobDetail("myJob1", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(null);
            scheduler.AddJob(jobDetail0, true);
            LastCall.IgnoreArguments();
            scheduler.AddJob(jobDetail1, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow);
            Expect.Call(scheduler.ScheduleJob(trigger1)).Return(DateTime.UtcNow);
            scheduler.Start();
            scheduler.Shutdown(false); 

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (jobFactory);
            schedulerFactoryObject.JobDetails = (new JobDetail[] {jobDetail0, jobDetail1});
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1});
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
Beispiel #10
0
        public void TestSchedulerFactoryObjectWithApplicationContext()
        {
            TestObject tb = new TestObject("tb", 99);
            StaticApplicationContext ac = new StaticApplicationContext();

            IScheduler scheduler = MockRepository.GenerateMock<IScheduler>();
            SchedulerContext schedulerContext = new SchedulerContext();
            scheduler.Stub(x => x.Context).Return(schedulerContext).Repeat.Times(4);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);
            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContextMap = new Hashtable();
            schedulerContextMap.Add("testObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContextMap);
            schedulerFactoryObject.ApplicationContext = (ac);
            schedulerFactoryObject.ApplicationContextSchedulerContextKey = ("appCtx");
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
                IScheduler returnedScheduler = (IScheduler) schedulerFactoryObject.GetObject();
                Assert.AreEqual(tb, returnedScheduler.Context["testObject"]);
                Assert.AreEqual(ac, returnedScheduler.Context["appCtx"]);
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }
        }
Beispiel #11
0
        public void TestSchedulerFactoryObjectWithListeners()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            IScheduler scheduler = MockRepository.GenerateMock<IScheduler>();

            ISchedulerListener schedulerListener = new TestSchedulerListener();
            IJobListener globalJobListener = new TestJobListener();
            IJobListener jobListener = new TestJobListener();
            ITriggerListener globalTriggerListener = new TestTriggerListener();
            ITriggerListener triggerListener = new TestTriggerListener();

            Expect.Call(scheduler.JobFactory = (jobFactory));
            scheduler.AddSchedulerListener(schedulerListener);
            scheduler.AddGlobalJobListener(globalJobListener);
            scheduler.AddJobListener(jobListener);
            scheduler.AddGlobalTriggerListener(globalTriggerListener);
            scheduler.AddTriggerListener(triggerListener);
            scheduler.Start();
            scheduler.Shutdown(false);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (jobFactory);
            schedulerFactoryObject.SchedulerListeners = (new ISchedulerListener[] {schedulerListener});
            schedulerFactoryObject.GlobalJobListeners = (new IJobListener[] {globalJobListener});
            schedulerFactoryObject.JobListeners = (new IJobListener[] {jobListener});
            schedulerFactoryObject.GlobalTriggerListeners = (new ITriggerListener[] {globalTriggerListener});
            schedulerFactoryObject.TriggerListeners = (new ITriggerListener[] {triggerListener});
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }
        }
Beispiel #12
0
        public void TestSchedulerFactoryObjectWithPlainQuartzObjects()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            TestObject tb         = new TestObject("tb", 99);
            JobDetail  jobDetail0 = new JobDetail();

            jobDetail0.JobType = typeof(IJob);
            jobDetail0.Name    = ("myJob0");
            jobDetail0.Group   = (SchedulerConstants.DefaultGroup);
            jobDetail0.JobDataMap.Add("testObject", tb);
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTrigger trigger0 = new CronTrigger();

            trigger0.Name                 = ("myTrigger0");
            trigger0.Group                = SchedulerConstants.DefaultGroup;
            trigger0.JobName              = "myJob0";
            trigger0.JobGroup             = SchedulerConstants.DefaultGroup;
            trigger0.StartTimeUtc         = (DateTime.UtcNow);
            trigger0.CronExpressionString = ("0/1 * * * * ?");

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.Name         = ("myJob1");
            mijdfb.Group        = (SchedulerConstants.DefaultGroup);
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail)mijdfb.GetObject();

            SimpleTrigger trigger1 = new SimpleTrigger();

            trigger1.Name           = "myTrigger1";
            trigger1.Group          = SchedulerConstants.DefaultGroup;
            trigger1.JobName        = "myJob1";
            trigger1.JobGroup       = SchedulerConstants.DefaultGroup;
            trigger1.StartTimeUtc   = (DateTime.UtcNow);
            trigger1.RepeatCount    = (SimpleTrigger.RepeatIndefinitely);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);

            IScheduler scheduler = (IScheduler)mockery.CreateMock(typeof(IScheduler));

            Expect.Call(scheduler.JobFactory = (jobFactory));
            Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetJobDetail("myJob1", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(null);
            scheduler.AddJob(jobDetail0, true);
            LastCall.IgnoreArguments();
            scheduler.AddJob(jobDetail1, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow);
            Expect.Call(scheduler.ScheduleJob(trigger1)).Return(DateTime.UtcNow);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (jobFactory);
            schedulerFactoryObject.JobDetails = (new JobDetail[] { jobDetail0, jobDetail1 });
            schedulerFactoryObject.Triggers   = (new Trigger[] { trigger0, trigger1 });
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
Beispiel #13
0
        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();
        }
Beispiel #14
0
        public void TestSchedulerFactoryObjectWithApplicationContext()
        {
            TestObject tb = new TestObject("tb", 99);
            StaticApplicationContext ac = new StaticApplicationContext();

            IScheduler scheduler = (IScheduler) mockery.CreateMock(typeof (IScheduler));
            SchedulerContext schedulerContext = new SchedulerContext();
            Expect.Call(scheduler.Context).Return(schedulerContext).Repeat.Times(4);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);
            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContextMap = new Hashtable();
            schedulerContextMap.Add("testObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContextMap);
            schedulerFactoryObject.ApplicationContext = (ac);
            schedulerFactoryObject.ApplicationContextSchedulerContextKey = ("appCtx");
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
                IScheduler returnedScheduler = (IScheduler) schedulerFactoryObject.GetObject();
                Assert.AreEqual(tb, returnedScheduler.Context["testObject"]);
                Assert.AreEqual(ac, returnedScheduler.Context["appCtx"]);
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
        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();
        }
Beispiel #16
0
        public void TestSchedulerFactoryObjectWithPlainQuartzObjects()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            TestObject tb = new TestObject("tb", 99);
            JobDetail jobDetail0 = new JobDetail();
            jobDetail0.JobType = typeof (IJob);
            jobDetail0.Name = ("myJob0");
            jobDetail0.Group = (SchedulerConstants.DefaultGroup);
            jobDetail0.JobDataMap.Add("testObject", tb);
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTrigger trigger0 = new CronTrigger();
            trigger0.Name = ("myTrigger0");
            trigger0.Group = SchedulerConstants.DefaultGroup;
            trigger0.JobName = "myJob0";
            trigger0.JobGroup = SchedulerConstants.DefaultGroup;
            trigger0.StartTimeUtc = (DateTime.UtcNow);
            trigger0.CronExpressionString = ("0/1 * * * * ?");

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            mijdfb.Name = ("myJob1");
            mijdfb.Group = (SchedulerConstants.DefaultGroup);
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTrigger trigger1 = new SimpleTrigger();
            trigger1.Name = "myTrigger1";
            trigger1.Group = SchedulerConstants.DefaultGroup;
            trigger1.JobName = "myJob1";
            trigger1.JobGroup = SchedulerConstants.DefaultGroup;
            trigger1.StartTimeUtc = (DateTime.UtcNow);
            trigger1.RepeatCount = (SimpleTrigger.RepeatIndefinitely);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);

            IScheduler scheduler = MockRepository.GenerateMock<IScheduler>();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (jobFactory);
            schedulerFactoryObject.JobDetails = (new JobDetail[] {jobDetail0, jobDetail1});
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1});
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.JobFactory = jobFactory);
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true));
            #if QUARTZ_2_0
            scheduler.AssertWasCalled(x => x.GetJobDetail(new JobKey("myJob0", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetJobDetail(new JobKey("myJob1", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup)));
            scheduler.AssertWasCalled(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup)));
            #else
            scheduler.AssertWasCalled(x => x.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup));
            scheduler.AssertWasCalled(x => x.GetJobDetail("myJob1", SchedulerConstants.DefaultGroup));
            scheduler.AssertWasCalled(x => x.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup));
            scheduler.AssertWasCalled(x => x.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup));
            #endif
        }
        public async Task TestSchedulerFactoryObjectWithPlainQuartzObjects()
        {
            IJobFactory jobFactory = new AdaptableJobFactory();

            TestObject    tb         = new TestObject("tb", 99);
            JobDetailImpl jobDetail0 = new JobDetailImpl();

            jobDetail0.JobType = typeof(IJob);
            jobDetail0.Name    = "myJob0";
            jobDetail0.Group   = SchedulerConstants.DefaultGroup;
            jobDetail0.JobDataMap.Add("testObject", tb);
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerImpl trigger0 = new CronTriggerImpl();

            trigger0.Name                 = "myTrigger0";
            trigger0.Group                = SchedulerConstants.DefaultGroup;
            trigger0.JobName              = "myJob0";
            trigger0.JobGroup             = SchedulerConstants.DefaultGroup;
            trigger0.StartTimeUtc         = DateTime.UtcNow;
            trigger0.CronExpressionString = "0/1 * * * * ?";

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.Name         = "myJob1";
            mijdfb.Group        = SchedulerConstants.DefaultGroup;
            mijdfb.TargetObject = task1;
            mijdfb.TargetMethod = "doSomething";
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerImpl trigger1 = new SimpleTriggerImpl();

            trigger1.Name           = "myTrigger1";
            trigger1.Group          = SchedulerConstants.DefaultGroup;
            trigger1.JobName        = "myJob1";
            trigger1.JobGroup       = SchedulerConstants.DefaultGroup;
            trigger1.StartTimeUtc   = DateTime.UtcNow;
            trigger1.RepeatCount    = SimpleTriggerImpl.RepeatIndefinitely;
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);

            IScheduler scheduler = A.Fake <IScheduler>();

            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 = jobFactory;
            schedulerFactoryObject.JobDetails = new IJobDetail[] { jobDetail0, jobDetail1 };
            schedulerFactoryObject.Triggers   = new ITrigger[] { trigger0, trigger1 };
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                await schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            A.CallTo(scheduler)
            .Where(x => x.Method.Name.Equals("set_JobFactory"))
            .WhenArgumentsMatch(x => x.Get <IJobFactory>(0) == jobFactory)
            .MustHaveHappened();

            A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.AddJob(jobDetail1, true, true, A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.GetJobDetail(new JobKey("myJob0", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.GetJobDetail(new JobKey("myJob1", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).MustHaveHappened();
        }
Beispiel #18
0
        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();
        }
Beispiel #20
0
        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();
        }