1 | using System;
|
---|
2 | using System.Text;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
6 | using HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
7 | using HeuristicLab.Services.Hive.Common.ServiceContracts;
|
---|
8 | using HeuristicLab.Clients.Hive.Slave.Tests;
|
---|
9 | using HeuristicLab.Clients.Hive;
|
---|
10 | using HeuristicLab.Services.Hive.DataAccess;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Services.Hive.Tests {
|
---|
13 | using DA = HeuristicLab.Services.Hive.DataAccess;
|
---|
14 | using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
15 |
|
---|
16 | [TestClass]
|
---|
17 | public class DaoTests {
|
---|
18 |
|
---|
19 | [ClassInitialize]
|
---|
20 | public static void MyClassInitialize(TestContext testContext) {
|
---|
21 | PluginLoader.pluginAssemblies.Any();
|
---|
22 | ServiceLocator.Instance = new MockServiceLocator(ServiceLocator.Instance);
|
---|
23 | }
|
---|
24 |
|
---|
25 | private IHiveService GetLocalService() {
|
---|
26 | return new HiveService();
|
---|
27 | }
|
---|
28 |
|
---|
29 | [TestMethod]
|
---|
30 | public void TestJobDao() {
|
---|
31 | IHiveDao dao = ServiceLocator.Instance.HiveDao;
|
---|
32 |
|
---|
33 | DT.Job job1 = new DT.Job();
|
---|
34 | job1.DateCreated = DateTime.Now;
|
---|
35 |
|
---|
36 | DT.Plugin plugin1 = new DT.Plugin();
|
---|
37 | plugin1.Name = "Tests.MyPlugin";
|
---|
38 | plugin1.Version = new Version("1.0.0.0");
|
---|
39 | plugin1.UserId = Guid.Empty;
|
---|
40 | plugin1.IsLocal = true;
|
---|
41 | plugin1.DateCreated = DateTime.Now;
|
---|
42 |
|
---|
43 | DT.PluginData pluginData1 = new DT.PluginData();
|
---|
44 | pluginData1.PluginId = plugin1.Id;
|
---|
45 | pluginData1.FileName = "Tests.MyPlugin-1.0.dll";
|
---|
46 | pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 };
|
---|
47 |
|
---|
48 | plugin1.Id = dao.AddPlugin(plugin1);
|
---|
49 | pluginData1.PluginId = plugin1.Id;
|
---|
50 | pluginData1.Id = dao.AddPluginData(pluginData1);
|
---|
51 |
|
---|
52 | job1.PluginsNeededIds.Add(plugin1.Id);
|
---|
53 |
|
---|
54 | job1.Id = dao.AddJob(job1);
|
---|
55 |
|
---|
56 | DT.Job job1loaded = dao.GetJob(job1.Id);
|
---|
57 | Assert.AreEqual(job1.Id, job1loaded.Id);
|
---|
58 | Assert.AreEqual(job1.CoresNeeded, job1loaded.CoresNeeded);
|
---|
59 | Assert.AreEqual(null, job1loaded.DateCalculated);
|
---|
60 | Assert.AreEqual(job1.DateCreated.ToString(), job1loaded.DateCreated.ToString());
|
---|
61 | Assert.AreEqual(null, job1loaded.DateFinished);
|
---|
62 | Assert.IsTrue(job1.PluginsNeededIds.SequenceEqual(job1loaded.PluginsNeededIds));
|
---|
63 |
|
---|
64 | dao.DeleteJob(job1.Id);
|
---|
65 |
|
---|
66 | Assert.AreEqual(null, dao.GetJob(job1.Id));
|
---|
67 | }
|
---|
68 |
|
---|
69 | [TestMethod]
|
---|
70 | public void TestSlaveDao() {
|
---|
71 | IHiveDao dao = ServiceLocator.Instance.HiveDao;
|
---|
72 | DT.SlaveGroup slaveGroup = new DT.SlaveGroup() {
|
---|
73 | Name = "Test"
|
---|
74 | };
|
---|
75 | slaveGroup.Id = dao.AddSlaveGroup(slaveGroup);
|
---|
76 |
|
---|
77 | DT.Slave slave = new DT.Slave() {
|
---|
78 | Id = Guid.NewGuid(),
|
---|
79 | Name = "Test",
|
---|
80 | OperatingSystem = null, //"Windows 3.11",
|
---|
81 | Cores = 2,
|
---|
82 | Memory = 1024,
|
---|
83 | FreeMemory = 512
|
---|
84 | };
|
---|
85 |
|
---|
86 | Assert.AreEqual(slave.Id, dao.AddSlave(slave));
|
---|
87 |
|
---|
88 | // update
|
---|
89 | slave.FreeMemory = 255;
|
---|
90 | slave.OperatingSystem = Environment.OSVersion.VersionString;
|
---|
91 | dao.UpdateSlave(slave);
|
---|
92 |
|
---|
93 | DT.Slave slaveLoaded = dao.GetSlave(slave.Id);
|
---|
94 | Assert.AreEqual(slave.FreeMemory, slaveLoaded.FreeMemory);
|
---|
95 |
|
---|
96 | dao.DeleteSlave(slave.Id);
|
---|
97 | dao.DeleteSlaveGroup(slaveGroup.Id);
|
---|
98 | }
|
---|
99 |
|
---|
100 | [TestMethod]
|
---|
101 | public void TestJobDaoWaiting() {
|
---|
102 | IHiveDao dao = ServiceLocator.Instance.HiveDao;
|
---|
103 |
|
---|
104 | DT.Job job = new DT.Job();
|
---|
105 | job.DateCreated = DateTime.Now;
|
---|
106 | job.JobState = JobState.Waiting;
|
---|
107 | job.Id = dao.AddJob(job);
|
---|
108 |
|
---|
109 | // todo
|
---|
110 | }
|
---|
111 |
|
---|
112 | [TestMethod]
|
---|
113 | public void TestPluginDao() {
|
---|
114 | IHiveDao dao = ServiceLocator.Instance.HiveDao;
|
---|
115 |
|
---|
116 | DT.Plugin plugin1 = new DT.Plugin();
|
---|
117 | plugin1.DateCreated = DateTime.Now;
|
---|
118 | plugin1.IsLocal = false;
|
---|
119 | plugin1.Name = "Tests.MyPlugin";
|
---|
120 | plugin1.Version = new Version("1.0.0.0");
|
---|
121 | plugin1.UserId = Guid.Empty;
|
---|
122 |
|
---|
123 | plugin1.Id = dao.AddPlugin(plugin1);
|
---|
124 |
|
---|
125 | DT.Plugin plugin1loaded = dao.GetPlugin(plugin1.Id);
|
---|
126 | Assert.AreEqual(plugin1.Id, plugin1loaded.Id);
|
---|
127 | Assert.AreEqual(plugin1.Name, plugin1loaded.Name);
|
---|
128 | Assert.AreEqual(plugin1.Version, plugin1loaded.Version);
|
---|
129 | Assert.AreEqual(plugin1.UserId, plugin1loaded.UserId);
|
---|
130 | Assert.AreEqual(plugin1.DateCreated.ToString(), plugin1loaded.DateCreated.ToString());
|
---|
131 | Assert.AreEqual(plugin1.IsLocal, plugin1loaded.IsLocal);
|
---|
132 |
|
---|
133 | DT.PluginData pluginData1 = new DT.PluginData();
|
---|
134 | pluginData1.PluginId = plugin1.Id;
|
---|
135 | pluginData1.FileName = "Tests.MyPlugin-1.0.dll";
|
---|
136 | pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 };
|
---|
137 |
|
---|
138 | pluginData1.Id = dao.AddPluginData(pluginData1);
|
---|
139 |
|
---|
140 | DT.PluginData pluginData1loaded = dao.GetPluginData(pluginData1.Id);
|
---|
141 | Assert.AreEqual(pluginData1.Id, pluginData1loaded.Id);
|
---|
142 |
|
---|
143 | Assert.AreEqual(pluginData1.PluginId, pluginData1loaded.PluginId);
|
---|
144 | Assert.AreEqual(pluginData1.FileName, pluginData1loaded.FileName);
|
---|
145 | Assert.IsTrue(pluginData1.Data.SequenceEqual(pluginData1loaded.Data));
|
---|
146 |
|
---|
147 | dao.DeletePluginData(pluginData1.Id);
|
---|
148 | dao.DeletePlugin(plugin1.Id);
|
---|
149 |
|
---|
150 | Assert.AreEqual(null, dao.GetPlugin(plugin1.Id));
|
---|
151 | Assert.AreEqual(null, dao.GetPluginData(pluginData1.Id));
|
---|
152 | }
|
---|
153 |
|
---|
154 | }
|
---|
155 | }
|
---|