예제 #1
0
        public async Task TestSchedulerWithSpringObjectJobFactoryAndQuartzJobObject()
        {
            DummyJobObject.param = 0;
            DummyJobObject.count = 0;

            JobDetailImpl jobDetail = new JobDetailImpl();

            jobDetail.JobType = typeof(DummyJobObject);
            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, DummyJobObject.param);
            Assert.IsTrue(DummyJobObject.count > 0);

            factoryObject.Dispose();
        }
예제 #2
0
        public void AfterPropertiesSet()
        {
            MethodInvokingJobDetailFactoryObject job = new MethodInvokingJobDetailFactoryObject();
            job.TargetObject = new TimerJob(m_viewProvider);
            job.Name = "TimerJob";
            job.TargetMethod = "RunProcess";
            job.Concurrent = false;

            job.AfterPropertiesSet();

            JobDetail jobDetail = (JobDetail)job.GetObject();

            SimpleTriggerObject triggerObject = new SimpleTriggerObject();

            triggerObject.Name = "TimerTrigger";

            triggerObject.JobName = "TimerJob";

            triggerObject.JobDetail = jobDetail;

            triggerObject.RepeatInterval = new TimeSpan(0, 0, 1);

            triggerObject.StartDelay = TimeSpan.Zero;

            triggerObject.AfterPropertiesSet();

            m_schedulerFactory.ScheduleJob(jobDetail, triggerObject);
        }
예제 #3
0
        public async Task TestSchedulerWithTaskExecutor()
        {
            CountingTaskExecutor taskExecutor = new CountingTaskExecutor();

            DummyJob.count = 0;

            JobDetailImpl jobDetail = new JobDetailImpl();

            jobDetail.JobType = typeof(DummyJob);
            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.TaskExecutor = taskExecutor;
            factoryObject.Triggers     = new ITrigger[] { trigger };
            factoryObject.JobDetails   = new IJobDetail[] { jobDetail };
            factoryObject.AfterPropertiesSet();
            await factoryObject.Start();

            await Task.Delay(TimeSpan.FromSeconds(1));

            Assert.IsTrue(DummyJob.count > 0);
            Assert.AreEqual(DummyJob.count, taskExecutor.count);

            factoryObject.Dispose();
        }
예제 #4
0
        public void TestSchedulerWithQuartzJobObject()
        {
            DummyJob.param = 0;
            DummyJob.count = 0;

            JobDetailImpl jobDetail = new JobDetailImpl();

            jobDetail.JobType = typeof(DummyJobObject);
            jobDetail.Name    = "myJob";
            jobDetail.JobDataMap.Put("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.Triggers   = new ITrigger[] { trigger };
            factoryObject.JobDetails = new IJobDetail[] { jobDetail };
            factoryObject.AfterPropertiesSet();
            factoryObject.Start();

            Thread.Sleep(500);
            Assert.AreEqual(10, DummyJobObject.param);
            Assert.IsTrue(DummyJobObject.count > 0);

            factoryObject.Dispose();
        }
예제 #5
0
        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();

            Thread.Sleep(500);
            Assert.IsTrue(DummyRunnable.count > 0);

            factoryObject.Dispose();
        }
예제 #6
0
        public void TestSchedulerWithTaskExecutor()
        {
            CountingTaskExecutor taskExecutor = new CountingTaskExecutor();

            DummyJob.count = 0;

            JobDetailImpl jobDetail = new JobDetailImpl();

            jobDetail.JobType = typeof(DummyJob);
            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.TaskExecutor = (taskExecutor);
            factoryObject.Triggers     = (new ITrigger[] { trigger });
            factoryObject.JobDetails   = (new IJobDetail[] { jobDetail });
            factoryObject.AfterPropertiesSet();
            factoryObject.Start();

            Thread.Sleep(500);
            Assert.IsTrue(DummyJob.count > 0);
            Assert.AreEqual(DummyJob.count, taskExecutor.count);

            factoryObject.Dispose();
        }
예제 #7
0
        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();
        }
예제 #8
0
        public void 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();
            factoryObject.Start();

            Thread.Sleep(500);
            Assert.AreEqual(10, DummyRunnable.param);
            Assert.IsTrue(DummyRunnable.count > 0);

            factoryObject.Dispose();
        }
예제 #9
0
        public void TestSimpleTriggerObjectWithListenerNames()
        {
            SimpleTriggerObject trigger = new SimpleTriggerObject();

            String[] names = new String[] { "test1", "test2" };
            trigger.TriggerListenerNames = (names);
            ArrayList result = new ArrayList(trigger.TriggerListenerNames);

            Assert.AreEqual(names, result);
        }
예제 #10
0
        public void TestSchedulerWithSpringObjectJobFactoryAndParamMismatchNotIgnored()
        {
            DummyJob.param = 0;
            DummyJob.count = 0;

            JobDetailImpl jobDetail = new JobDetailImpl();

            jobDetail.JobType = typeof(DummyJob);
            jobDetail.Name    = "myJob";
            jobDetail.JobDataMap.Add("para", "10");
            jobDetail.JobDataMap.Add("ignoredParam", "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 bean       = new SchedulerFactoryObject();
            SpringObjectJobFactory jobFactory = new SpringObjectJobFactory();

            jobFactory.IgnoredUnknownProperties = new String[] { "ignoredParam" };
            bean.JobFactory = jobFactory;
            bean.Triggers   = new ITrigger[] { trigger };
            bean.JobDetails = new IJobDetail[] { jobDetail };
            bean.AfterPropertiesSet();

            Thread.Sleep(500);
            Assert.AreEqual(0, DummyJob.param);
            Assert.IsTrue(DummyJob.count == 0);

            bean.Dispose();
        }
예제 #11
0
        private void MethodInvokingConcurrency(bool concurrent)
        {
            // Test the concurrency flag.
            // Method invoking job with two triggers.
            // If the concurrent flag is false, the triggers are NOT allowed
            // to interfere with each other.

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

            // set the concurrency flag!
            mijdfb.Concurrent   = concurrent;
            mijdfb.ObjectName   = "myJob1";
            mijdfb.TargetObject = task1;
            mijdfb.TargetMethod = "doWait";
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger0 = new SimpleTriggerObject();

            trigger0.ObjectName     = "myTrigger1";
            trigger0.JobDetail      = jobDetail1;
            trigger0.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger0.RepeatInterval = TimeSpan.FromMilliseconds(1);
            trigger0.RepeatCount    = 1;
            trigger0.AfterPropertiesSet();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = "myTrigger1";
            trigger1.JobDetail      = jobDetail1;
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(1000L);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(1);
            trigger1.RepeatCount    = 1;
            trigger1.AfterPropertiesSet();

            SchedulerFactoryObject schedulerFactoryObject = new SchedulerFactoryObject();

            schedulerFactoryObject.JobDetails = new IJobDetail[] { jobDetail1 };
            schedulerFactoryObject.Triggers   = new ITrigger[] { trigger1, trigger0 };
            schedulerFactoryObject.AfterPropertiesSet();

            // ok scheduler is set up... let's wait for like 4 seconds
            try
            {
                Thread.Sleep(4000);
            }
            catch (ThreadInterruptedException)
            {
                // fall through
            }

            if (concurrent)
            {
                Assert.AreEqual(2, task1.counter);
                task1.Stop();
                // we're done, both jobs have ran, let's call it a day
                return;
            }
            else
            {
                Assert.AreEqual(1, task1.counter);
                task1.Stop();
                // we need to check whether or not the test succeed with non-concurrent jobs
            }

            try
            {
                Thread.Sleep(4000);
            }
            catch (ThreadInterruptedException)
            {
                // fall through
            }

            task1.Stop();
            Assert.AreEqual(2, task1.counter);

            // Although we're destroying the scheduler, it does seem to keep things in memory:
            // When executing both tests (concurrent and non-concurrent), the second test always
            // fails.
            schedulerFactoryObject.Dispose();
        }
예제 #12
0
        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));
        }
예제 #13
0
 public void SetUp()
 {
     simpleTrigger            = new SimpleTriggerObject();
     simpleTrigger.ObjectName = TRIGGER_NAME;
     Trigger = simpleTrigger;
 }
예제 #14
0
        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();
        }
예제 #15
0
 public void TestSimpleTriggerObjectWithListenerNames()
 {
     SimpleTriggerObject trigger = new SimpleTriggerObject();
     String[] names = new String[] {"test1", "test2"};
     trigger.TriggerListenerNames = (names);
     ArrayList result = new ArrayList(trigger.TriggerListenerNames);
     Assert.AreEqual(names, result);
 }
예제 #16
0
 public void SetUp()
 {
     simpleTrigger = new SimpleTriggerObject();
     simpleTrigger.ObjectName = TRIGGER_NAME;
     Trigger = simpleTrigger;
 }
예제 #17
0
        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();
        }
예제 #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();
            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));
        }
예제 #19
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();
        }
예제 #20
0
        public void TestSchedulerWithSpringObjectJobFactoryAndParamMismatchNotIgnored()
        {
            DummyJob.param = 0;
            DummyJob.count = 0;

            JobDetail jobDetail = new JobDetail();
            jobDetail.JobType = typeof(DummyJob);
            jobDetail.Name = ("myJob");
            jobDetail.JobDataMap.Add("para", "10");
            jobDetail.JobDataMap.Add("ignoredParam", "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 bean = new SchedulerFactoryObject();
            SpringObjectJobFactory jobFactory = new SpringObjectJobFactory();
            jobFactory.IgnoredUnknownProperties = (new String[] {"ignoredParam"});
            bean.JobFactory = (jobFactory);
            bean.Triggers = (new Trigger[] {trigger});
            bean.JobDetails = (new JobDetail[] {jobDetail});
            bean.AfterPropertiesSet();

            Thread.Sleep(500);
            Assert.AreEqual(0, DummyJob.param);
            Assert.IsTrue(DummyJob.count == 0);

            bean.Dispose();
        }
예제 #21
0
        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();
        }
예제 #22
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));
        }
예제 #23
0
        public void TestSchedulerWithTaskExecutor()
        {
            CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
            DummyJob.count = 0;

            JobDetail jobDetail = new JobDetail();
            jobDetail.JobType = typeof (DummyJob);
            ;
            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.TaskExecutor = (taskExecutor);
            factoryObject.Triggers = (new Trigger[] {trigger});
            factoryObject.JobDetails = (new JobDetail[] {jobDetail});
            factoryObject.AfterPropertiesSet();
            factoryObject.Start();

            Thread.Sleep(500);
            Assert.IsTrue(DummyJob.count > 0);
            Assert.AreEqual(DummyJob.count, taskExecutor.count);

            factoryObject.Dispose();
        }
예제 #24
0
        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();
        }
예제 #25
0
        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));
        }
예제 #26
0
        /*public void TestMethodInvocationWithConcurrency()  {
        methodInvokingConcurrency(true);
        }*/
        // We can't test both since Quartz somehow seems to keep things in memory
        // enable both and one of them will fail (order doesn't matter).
        /*public void TestMethodInvocationWithoutConcurrency()  {
        methodInvokingConcurrency(false);
        }*/
        private void methodInvokingConcurrency(bool concurrent)
        {
            // Test the concurrency flag.
            // Method invoking job with two triggers.
            // If the concurrent flag is false, the triggers are NOT allowed
            // to interfere with each other.

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            // set the concurrency flag!
            mijdfb.Concurrent = (concurrent);
            mijdfb.ObjectName = ("myJob1");
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doWait");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTriggerObject trigger0 = new SimpleTriggerObject();
            trigger0.ObjectName = ("myTrigger1");
            trigger0.JobDetail = (jobDetail1);
            trigger0.StartDelay = TimeSpan.FromMilliseconds(0);
            trigger0.RepeatInterval = TimeSpan.FromMilliseconds(1);
            trigger0.RepeatCount = (1);
            trigger0.AfterPropertiesSet();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();
            trigger1.ObjectName = ("myTrigger1");
            trigger1.JobDetail = (jobDetail1);
            trigger1.StartDelay = TimeSpan.FromMilliseconds(1000L);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(1);
            trigger1.RepeatCount = (1);
            trigger1.AfterPropertiesSet();

            SchedulerFactoryObject schedulerFactoryObject = new SchedulerFactoryObject();
            schedulerFactoryObject.JobDetails = (new JobDetail[] {jobDetail1});
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger1, trigger0});
            schedulerFactoryObject.AfterPropertiesSet();

            // ok scheduler is set up... let's wait for like 4 seconds
            try
            {
                Thread.Sleep(4000);
            }
            catch (ThreadInterruptedException)
            {
                // fall through
            }

            if (concurrent)
            {
                Assert.AreEqual(2, task1.counter);
                task1.Stop();
                // we're done, both jobs have ran, let's call it a day
                return;
            }
            else
            {
                Assert.AreEqual(1, task1.counter);
                task1.Stop();
                // we need to check whether or not the test succeed with non-concurrent jobs
            }

            try
            {
                Thread.Sleep(4000);
            }
            catch (ThreadInterruptedException)
            {
                // fall through
            }

            task1.Stop();
            Assert.AreEqual(2, task1.counter);

            // Although we're destroying the scheduler, it does seem to keep things in memory:
            // When executing both tests (concurrent and non-concurrent), the second test always
            // fails.
            schedulerFactoryObject.Dispose();
        }
예제 #27
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();
        }