Ejemplo n.º 1
0
        public void TestResumeCrontab()
        {
            //开始调度
            TimeSpan           timeSpan           = new TimeSpan(0, 0, 2);
            RecurrenceStrategy recurrenceStrategy = new RecurrenceStrategy(timeSpan);
            ShowTimeCrontab    showTimeCrontab    = new ShowTimeCrontab("Hello World !", recurrenceStrategy);

            Assert.IsTrue(showTimeCrontab.Count == 0);

            ScheduleMediator.Schedule(showTimeCrontab, 0);

            //线程睡眠
            Thread.Sleep(5000);

            Assert.IsTrue(showTimeCrontab.Count == 3);

            //暂停
            ScheduleMediator.Pause(showTimeCrontab.Id);

            //线程睡眠
            Thread.Sleep(5000);

            Assert.IsTrue(showTimeCrontab.Count == 3);

            //恢复
            ScheduleMediator.Resume(showTimeCrontab.Id);

            //线程睡眠
            Thread.Sleep(5000);

            Assert.IsTrue(showTimeCrontab.Count > 3);
        }
Ejemplo n.º 2
0
        public void TestException()
        {
            string log = $"{AppDomain.CurrentDomain.BaseDirectory}\\ScheduleLogs\\ExceptionLogs\\{DateTime.Today:yyyyMMdd}.txt";

            //开始调度
            TimeSpan           timeSpan           = new TimeSpan(0, 0, 2);
            RecurrenceStrategy recurrenceStrategy = new RecurrenceStrategy(timeSpan);
            ShowTimeCrontab    showTimeCrontab    = new ShowTimeCrontab("Exception", recurrenceStrategy);

            ScheduleMediator.Schedule(showTimeCrontab, 0);

            //线程睡眠
            Thread.Sleep(5100);

            Assert.IsTrue(File.Exists(log));
        }
Ejemplo n.º 3
0
        public void TestScheduleInspect()
        {
            //开始调度
            TimeSpan         timeSpan         = new TimeSpan(0, 0, 2);
            TimeSpanStrategy timeSpanStrategy = new TimeSpanStrategy(timeSpan);
            ShowTimeCrontab  showTimeCrontab  = new ShowTimeCrontab("Hello World !", timeSpanStrategy);

            Assert.IsTrue(showTimeCrontab.Count == 0);

            ScheduleMediator.Schedule(showTimeCrontab);

            //线程睡眠
            Thread.Sleep(5000);

            Assert.IsTrue(showTimeCrontab.Count == 3);
        }
Ejemplo n.º 4
0
        public void TestFindAllCrontabs()
        {
            TimeSpan               timeSpan               = new TimeSpan(0, 0, 2);
            RecurrenceStrategy     recurrenceStrategy     = new RecurrenceStrategy(timeSpan);
            string                 cronExpression         = DateTime.Now.AddSeconds(2).ToCronExpression();
            CronExpressionStrategy cronExpressionStrategy = new CronExpressionStrategy(cronExpression);

            ShowTimeCrontab showTimeCrontab = new ShowTimeCrontab("Hello World !", recurrenceStrategy);
            AlarmCrontab    alarmCrontab    = new AlarmCrontab("Hello World !", cronExpressionStrategy);

            ScheduleMediator.Schedule(showTimeCrontab, 0);
            ScheduleMediator.Schedule(alarmCrontab, 0);

            IList <ICrontab> crontabs = ScheduleMediator.FindAll();

            Assert.IsTrue(crontabs.Count == 2);
        }