Falcon.TaskScheduling/Falcon.TaskSchedulingTests/ConcurrentQueueTaskTests.cs

132 lines
4.6 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Falcon.TaskScheduling;
using System;
using System.Collections.Generic;
using System.Text;
using Falcon.TaskSchedulingTests;
namespace Falcon.TaskScheduling.Tests
{
[TestClass()]
public class ConcurrentQueueTaskTests
{
[TestMethod()]
public void AddFirstQueueTest() {
ConcurrentQueueTask ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableFirstQueue = true,
});
ts.AddFirstQueue(new TaskUnit());
Assert.IsTrue(ts.FirstQueue.Count == 1);
ts.AddFirstQueue(new TaskUnit());
Assert.IsTrue(ts.FirstQueue.Count == 2);
ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableFirstQueue = false,
});
try {
ts.AddFirstQueue(new TaskUnit());
} catch(NotSupportedException ex) {
}
Assert.IsNull(ts.FirstQueue);
}
[TestMethod()]
public void AddIdleQueueTest() {
ConcurrentQueueTask ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableIdleQueue = true,
});
ts.AddIdleQueue(new TaskUnit());
Assert.IsTrue(ts.IdleQueue.Count == 1);
ts.AddIdleQueue(new TaskUnit());
Assert.IsTrue(ts.IdleQueue.Count == 2);
ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableIdleQueue = false,
});
try {
ts.AddIdleQueue(new TaskUnit());
} catch(NotSupportedException ex) {
}
Assert.IsNull(ts.IdleQueue);
}
[TestMethod()]
public void AddSystemQueueTest() {
ConcurrentQueueTask ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableSystemQueue = true,
});
ts.AddSystemQueue(new TaskUnit());
Assert.IsTrue(ts.SystemQueue.Count == 1);
ts.AddSystemQueue(new TaskUnit());
Assert.IsTrue(ts.SystemQueue.Count == 2);
ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableSystemQueue = false,
});
try {
ts.AddSystemQueue(new TaskUnit());
} catch(NotSupportedException ex) {
}
Assert.IsNull(ts.SystemQueue);
}
[TestMethod()]
public void AddQueueTest() {
ConcurrentQueueTask ts = new ConcurrentQueueTask(new TaskSchedulerOption {
QueueDefine = "50,40",
});
Assert.IsTrue(ts.Queue.Count == 2);
Assert.IsTrue(ts.Queue.ToArray()[0].Queue.Count == 0);
Assert.IsTrue(ts.Queue.ToArray()[0].Weight == 50);
Assert.IsTrue(ts.Queue.ToArray()[1].Queue.Count == 0);
Assert.IsTrue(ts.Queue.ToArray()[1].Weight == 40);
}
[TestMethod()]
public void StartTest() {
ConcurrentQueueTask ts = new ConcurrentQueueTask(new TaskSchedulerOption {
EnableFirstQueue = true,
EnableIdleQueue = true,
EnableSystemQueue = true,
QueueDefine = "50,40",
});
var tul = new List<TaskUnit>();
tul.Add(new TaskUnit("1",TaskType.system));
tul.Add(new TaskUnit("2",TaskType.system));
tul.Add(new TaskUnit("3",TaskType.idel));
tul.Add(new TaskUnit("4",TaskType.first));
tul.Add(new TaskUnit("5",TaskType.queue));
tul.Add(new TaskUnit("6",TaskType.queue));
foreach(var t in tul) {
switch(t.Type) {
case TaskType.system:
ts.AddSystemQueue(t);
break;
case TaskType.first:
ts.AddFirstQueue(t);
break;
case TaskType.queue:
ts.AddQueue(50,t);
break;
case TaskType.idel:
ts.AddIdleQueue(t);
break;
default:
break;
}
}
ts.Start();
Assert.IsTrue(tul.Count == TaskUnit.ResultList.Count);
string wl = "";
foreach(var tu in TaskUnit.ResultList) {
Assert.IsTrue(tu.State == tu.Result);
wl += tu.Result;
}
Assert.IsTrue(wl == "124563");
}
}
}