2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using AutoMoq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 03:55:35 +00:00
|
|
|
|
public class JobProviderTest : TestBase
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2011-04-22 05:46:47 +00:00
|
|
|
|
public void Run_Jobs_Updates_Last_Execution()
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
2011-04-22 05:46:47 +00:00
|
|
|
|
//Act
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
timerProvider.RunScheduled();
|
|
|
|
|
|
2011-04-22 05:46:47 +00:00
|
|
|
|
//Assert
|
|
|
|
|
var settings = timerProvider.All();
|
|
|
|
|
Assert.IsNotEmpty(settings);
|
|
|
|
|
Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution);
|
2011-06-23 06:56:17 +00:00
|
|
|
|
settings[0].Success.Should().BeTrue();
|
2011-04-22 05:46:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Run_Jobs_Updates_Last_Execution_Mark_as_unsuccesful()
|
|
|
|
|
{
|
|
|
|
|
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
|
2011-04-22 05:46:47 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-22 05:46:47 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
timerProvider.RunScheduled();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var settings = timerProvider.All();
|
|
|
|
|
Assert.IsNotEmpty(settings);
|
|
|
|
|
Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution);
|
|
|
|
|
Assert.IsFalse(settings[0].Success);
|
2011-05-19 03:55:35 +00:00
|
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_run_job_again()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
var firstRun = timerProvider.RunScheduled();
|
|
|
|
|
var secondRun = timerProvider.RunScheduled();
|
|
|
|
|
|
2011-06-23 06:56:17 +00:00
|
|
|
|
firstRun.Should().BeTrue();
|
|
|
|
|
secondRun.Should().BeTrue();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_run_async_job_again()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
2011-05-17 07:04:49 +00:00
|
|
|
|
var firstRun = timerProvider.QueueJob(typeof(FakeJob));
|
2011-04-20 07:44:13 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2011-05-17 07:04:49 +00:00
|
|
|
|
var secondRun = timerProvider.QueueJob(typeof(FakeJob));
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
2011-06-23 06:56:17 +00:00
|
|
|
|
firstRun.Should().BeTrue();
|
|
|
|
|
secondRun.Should().BeTrue();
|
2011-07-11 00:03:01 +00:00
|
|
|
|
JobProvider.Queue.Should().BeEmpty();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 06:25:39 +00:00
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void no_concurent_jobs()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new SlowJob() };
|
2011-05-20 06:25:39 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-20 06:25:39 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
2011-07-11 00:03:01 +00:00
|
|
|
|
timerProvider.QueueJob(typeof(SlowJob), 1);
|
|
|
|
|
timerProvider.QueueJob(typeof(SlowJob), 2);
|
|
|
|
|
timerProvider.QueueJob(typeof(SlowJob), 3);
|
2011-05-20 06:25:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(10000);
|
2011-07-11 00:03:01 +00:00
|
|
|
|
JobProvider.Queue.Should().BeEmpty();
|
2011-05-27 02:12:28 +00:00
|
|
|
|
//Asserts are done in ExceptionVerification
|
2011-05-20 06:25:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_run_broken_async_job_again()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
|
2011-04-21 01:26:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-21 01:26:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
2011-05-19 03:55:35 +00:00
|
|
|
|
var firstRun = timerProvider.QueueJob(typeof(BrokenJob));
|
2011-04-21 01:26:13 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2011-05-19 03:55:35 +00:00
|
|
|
|
var secondRun = timerProvider.QueueJob(typeof(BrokenJob));
|
2011-04-21 01:26:13 +00:00
|
|
|
|
|
2011-06-23 06:56:17 +00:00
|
|
|
|
firstRun.Should().BeTrue();
|
|
|
|
|
secondRun.Should().BeTrue();
|
2011-05-19 03:55:35 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2011-07-11 00:03:01 +00:00
|
|
|
|
JobProvider.Queue.Should().BeEmpty();
|
2011-05-19 03:55:35 +00:00
|
|
|
|
ExceptionVerification.ExcpectedErrors(2);
|
2011-04-21 01:26:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_run_two_jobs_at_the_same_time()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new SlowJob() };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
bool firstRun = false;
|
|
|
|
|
bool secondRun = false;
|
|
|
|
|
|
|
|
|
|
var thread1 = new Thread(() => firstRun = timerProvider.RunScheduled());
|
|
|
|
|
thread1.Start();
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
var thread2 = new Thread(() => secondRun = timerProvider.RunScheduled());
|
|
|
|
|
thread2.Start();
|
|
|
|
|
|
|
|
|
|
thread1.Join();
|
|
|
|
|
thread2.Join();
|
|
|
|
|
|
2011-06-23 06:56:17 +00:00
|
|
|
|
firstRun.Should().BeTrue();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
Assert.IsFalse(secondRun);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 07:04:49 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_queue_jobs_at_the_same_time()
|
|
|
|
|
{
|
|
|
|
|
var slowJob = new SlowJob();
|
|
|
|
|
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { slowJob };
|
2011-05-17 07:04:49 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
var thread1 = new Thread(() => timerProvider.QueueJob(typeof(SlowJob)));
|
|
|
|
|
var thread2 = new Thread(() => timerProvider.QueueJob(typeof(SlowJob)));
|
|
|
|
|
|
|
|
|
|
thread1.Start();
|
|
|
|
|
thread2.Start();
|
|
|
|
|
|
|
|
|
|
thread1.Join();
|
|
|
|
|
thread2.Join();
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(1, slowJob.ExexutionCount);
|
2011-07-11 00:03:01 +00:00
|
|
|
|
JobProvider.Queue.Should().BeEmpty();
|
2011-05-17 07:04:49 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Init_Jobs()
|
|
|
|
|
{
|
|
|
|
|
var fakeTimer = new FakeJob();
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
var timers = timerProvider.All();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-02 21:06:46 +00:00
|
|
|
|
|
|
|
|
|
timers.Should().HaveCount(1);
|
2011-06-23 06:56:17 +00:00
|
|
|
|
timers[0].Interval.Should().Be(fakeTimer.DefaultInterval);
|
|
|
|
|
timers[0].Name.Should().Be(fakeTimer.Name);
|
|
|
|
|
timers[0].TypeName.Should().Be(fakeTimer.GetType().ToString());
|
|
|
|
|
timers[0].LastExecution.Should().HaveYear(2000);
|
|
|
|
|
timers[0].Enable.Should().BeTrue();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_Timers_only_registers_once()
|
|
|
|
|
{
|
2011-06-17 19:50:49 +00:00
|
|
|
|
var repo = MockLib.GetEmptyDatabase();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
var fakeTimer = new FakeJob();
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(repo);
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mocker2 = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker2.SetConstant(repo);
|
|
|
|
|
var assertTimerProvider = mocker2.Resolve<JobProvider>();
|
|
|
|
|
|
|
|
|
|
var timers = assertTimerProvider.All();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-02 21:06:46 +00:00
|
|
|
|
timers.Should().HaveCount(1);
|
2011-06-23 06:56:17 +00:00
|
|
|
|
timers[0].Enable.Should().BeTrue();
|
2011-05-11 18:25:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_Timers_sets_interval_0_to_disabled()
|
|
|
|
|
{
|
2011-06-17 19:50:49 +00:00
|
|
|
|
var repo = MockLib.GetEmptyDatabase();
|
2011-05-11 18:25:32 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
var disabledJob = new DisabledJob();
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
|
2011-05-11 18:25:32 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(repo);
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-05-11 18:25:32 +00:00
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mocker2 = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker2.SetConstant(repo);
|
|
|
|
|
var assertTimerProvider = mocker2.Resolve<JobProvider>();
|
|
|
|
|
|
|
|
|
|
var timers = assertTimerProvider.All();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-02 21:06:46 +00:00
|
|
|
|
timers.Should().HaveCount(1);
|
2011-05-11 18:25:32 +00:00
|
|
|
|
Assert.IsFalse(timers[0].Enable);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 04:01:01 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Next_Execution_Time()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-05-17 04:01:01 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-17 07:04:49 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
2011-05-17 04:01:01 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
timerProvider.RunScheduled();
|
|
|
|
|
var next = timerProvider.NextScheduledRun(typeof(FakeJob));
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
2011-05-17 04:01:01 +00:00
|
|
|
|
//Assert
|
|
|
|
|
var settings = timerProvider.All();
|
|
|
|
|
Assert.IsNotEmpty(settings);
|
|
|
|
|
Assert.AreEqual(next, settings[0].LastExecution.AddMinutes(15));
|
|
|
|
|
}
|
2011-05-17 07:16:45 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Disabled_isnt_run_by_scheduler()
|
|
|
|
|
{
|
2011-06-17 19:50:49 +00:00
|
|
|
|
var repo = MockLib.GetEmptyDatabase();
|
2011-05-17 07:16:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var disabledJob = new DisabledJob();
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
|
2011-05-17 07:16:45 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(repo);
|
|
|
|
|
mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
timerProvider.RunScheduled();
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.AreEqual(0, disabledJob.ExexutionCount);
|
|
|
|
|
}
|
2011-05-18 05:29:23 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SingleId_do_not_update_last_execution()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-05-18 05:29:23 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-18 05:29:23 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
timerProvider.QueueJob(typeof(FakeJob), 10);
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var settings = timerProvider.All();
|
2011-06-23 06:56:17 +00:00
|
|
|
|
settings.Should().NotBeEmpty();
|
|
|
|
|
settings[0].LastExecution.Should().HaveYear(2000);
|
2011-07-11 00:03:01 +00:00
|
|
|
|
JobProvider.Queue.Should().BeEmpty();
|
2011-05-18 05:29:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SingleId_do_not_set_success()
|
|
|
|
|
{
|
2011-05-24 04:12:54 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
2011-05-18 05:29:23 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 19:50:49 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-18 05:29:23 +00:00
|
|
|
|
mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var timerProvider = mocker.Resolve<JobProvider>();
|
|
|
|
|
timerProvider.Initialize();
|
|
|
|
|
timerProvider.QueueJob(typeof(FakeJob), 10);
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var settings = timerProvider.All();
|
|
|
|
|
Assert.IsNotEmpty(settings);
|
|
|
|
|
Assert.IsFalse(settings[0].Success);
|
|
|
|
|
}
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FakeJob : IJob
|
|
|
|
|
{
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "FakeJob"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 15; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
2011-04-22 05:46:47 +00:00
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 18:25:32 +00:00
|
|
|
|
public class DisabledJob : IJob
|
|
|
|
|
{
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "DisabledJob"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 07:16:45 +00:00
|
|
|
|
public int ExexutionCount { get; set; }
|
|
|
|
|
|
2011-05-11 18:25:32 +00:00
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
2011-05-17 07:16:45 +00:00
|
|
|
|
ExexutionCount++;
|
2011-05-11 18:25:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
public class BrokenJob : IJob
|
|
|
|
|
{
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "FakeJob"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 15; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
2011-05-17 07:04:49 +00:00
|
|
|
|
throw new ApplicationException("Broken job is broken");
|
2011-04-21 01:26:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
public class SlowJob : IJob
|
|
|
|
|
{
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "FakeJob"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 15; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 07:04:49 +00:00
|
|
|
|
public int ExexutionCount { get; set; }
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
2011-05-20 06:25:39 +00:00
|
|
|
|
Console.WriteLine("Starting Job");
|
2011-05-17 07:04:49 +00:00
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
ExexutionCount++;
|
2011-05-20 06:25:39 +00:00
|
|
|
|
Console.WriteLine("Finishing Job");
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|