public void TestResumeCrontab() { //开始调度 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); //暂停 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 TimeSpanMappingTest(string input, Type expectedType, Type itemType, string expected) { TimeSpan expectedTimeSpan = TimeSpan.Parse(expected); XmlDocument xmlNode = new XmlDocument(); xmlNode.LoadXml(input); IConfigurationReader configurationParser = Substitute.For <IConfigurationReader>(); IMappingStrategy mappingStrategy = new TimeSpanStrategy(); var actual = mappingStrategy.Map(xmlNode.FirstChild, expectedType, configurationParser); Assert.AreEqual(expectedType, actual.GetType()); Assert.AreEqual(expectedTimeSpan, ((TimeSpan)actual)); }
public void TestException() { string log = $"{AppDomain.CurrentDomain.BaseDirectory}\\ScheduleLogs\\ExceptionLogs\\{DateTime.Today:yyyyMMdd}.txt"; //开始调度 TimeSpan timeSpan = new TimeSpan(0, 0, 2); TimeSpanStrategy timeSpanStrategy = new TimeSpanStrategy(timeSpan); ShowTimeCrontab showTimeCrontab = new ShowTimeCrontab("Exception", timeSpanStrategy); ScheduleMediator.Schedule(showTimeCrontab); //线程睡眠 Thread.Sleep(5100); Assert.IsTrue(File.Exists(log)); }
public void TestFindAllCrontabs() { TimeSpan timeSpan = new TimeSpan(0, 0, 2); TimeSpanStrategy timeSpanStrategy = new TimeSpanStrategy(timeSpan); string cronExpression = DateTime.Now.AddSeconds(2).ToCronExpression(); CronExpressionStrategy cronExpressionStrategy = new CronExpressionStrategy(cronExpression); ShowTimeCrontab showTimeCrontab = new ShowTimeCrontab("Hello World !", timeSpanStrategy); AlarmCrontab alarmCrontab = new AlarmCrontab("Hello World !", cronExpressionStrategy); ScheduleMediator.Schedule(showTimeCrontab); ScheduleMediator.Schedule(alarmCrontab); IList <ICrontab> crontabs = ScheduleMediator.FindAll(); Assert.IsTrue(crontabs.Count == 2); }