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); }
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)); }
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); }
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); }