Skip to content

Commit

Permalink
start fleshing out actionscheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmeijer committed Apr 15, 2012
1 parent 2b57288 commit 721d110
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
17 changes: 11 additions & 6 deletions ActionScheduler.cs
@@ -1,18 +1,23 @@
using System; using System.Collections.Generic;
using cake; using System.Linq;


namespace bs namespace cake
{ {
public class ActionScheduler public class ActionScheduler
{ {
public void Add(string target, TargetGenerateSettings tgs, string[] dependenciesRequiringRegeneration) private Dictionary<TargetGenerateSettings, List<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, List<string>>();

public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs)
{ {
throw new NotImplementedException(); _scheduledActions.Add(tgs, new List<string>(dependenciesRequiringRegeneration));
} }


public TargetGenerateSettings FindJobToRun() public TargetGenerateSettings FindJobToRun()
{ {
throw new NotImplementedException(); var findJobToRun = _scheduledActions.Where(kvp => kvp.Value.Count == 0).Select(kvp=>kvp.Key).FirstOrDefault();
if (findJobToRun!=null)
_scheduledActions.Remove(findJobToRun);
return findJobToRun;
} }
} }
} }
41 changes: 33 additions & 8 deletions Tests/ActionSchedulerTest.cs
Expand Up @@ -5,23 +5,48 @@
using cake.Tests; using cake.Tests;
using NUnit.Framework; using NUnit.Framework;


namespace bs.Tests namespace cake.Tests
{ {
[TestFixture] [TestFixture]
public class ActionSchedulerTest public class ActionSchedulerTest
{ {
ActionScheduler _scheduler;
private SimpleAction _action;

[SetUp]
public void Setup()
{
_scheduler = new ActionScheduler();
_action = new SimpleAction();
}

[Test] [Test]
[Ignore] public void SingleActionWithoutDependenciesRequiringGenerationCanBeRun()
public void Test()
{ {
var scheduler = new ActionScheduler(); var tgs = new TargetGenerateSettings(_action, new[] {"input"}, "output");
_scheduler.Add(new string[0], tgs);


var action = new SimpleAction(s => { }); Assert.AreEqual(tgs,_scheduler.FindJobToRun());
var tgs = new TargetGenerateSettings(action, new[] {"input"}, "output"); }
scheduler.Add("output", tgs, new string[0]);


var jobToRun = scheduler.FindJobToRun(); [Test]
public void DoesNotProvideSameJobTwice()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
_scheduler.Add(new string[0], tgs);


Assert.AreEqual(tgs, _scheduler.FindJobToRun());
Assert.IsNull(_scheduler.FindJobToRun());
} }

[Test]
public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
_scheduler.Add(new[]{"input"}, tgs);

Assert.IsNull(_scheduler.FindJobToRun());
}

} }
} }
4 changes: 4 additions & 0 deletions Tests/SimpleAction.cs
Expand Up @@ -18,6 +18,10 @@ public SimpleAction(Action<TargetGenerateSettings> invoke, string actionHash)
_actionHash = actionHash; _actionHash = actionHash;
} }


public SimpleAction() : this(s=> { })
{
}

public void Invoke(TargetGenerateSettings settings) public void Invoke(TargetGenerateSettings settings)
{ {
_invoke(settings); _invoke(settings);
Expand Down

0 comments on commit 721d110

Please sign in to comment.