- Timestamp:
- 09/08/11 10:38:36 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs
r6463 r6717 24 24 using System.Linq; 25 25 using System.Threading; 26 using HeuristicLab.Services.Hive.Common.DataTransfer;27 using HeuristicLab.Services.Hive.Common.ServiceContracts;28 using HeuristicLab.Services.Hive.DataAccess;29 26 using Microsoft.VisualStudio.TestTools.UnitTesting; 30 using DT = HeuristicLab.Services.Hive. Common.DataTransfer;27 using DT = HeuristicLab.Services.Hive.DataTransfer; 31 28 32 29 namespace HeuristicLab.Services.Hive.Tests { … … 39 36 } 40 37 41 private IHiveService GetLocalService() {42 return new H iveService();38 private HeuristicLab.Services.Hive.ServiceContracts.IHiveService GetLocalService() { 39 return new HeuristicLab.Services.Hive.HiveService(); 43 40 } 44 41 … … 55 52 56 53 DT.Job job1 = new DT.Job(); 57 job1.State = JobState.Offline;58 job1.StateLog.Add(new DT.StateLog { State = JobState.Offline, DateTime = DateTime.Now });59 job1.Command = Command.Pause;54 job1.State = DT.JobState.Offline; 55 job1.StateLog.Add(new DT.StateLog { State = DT.JobState.Offline, DateTime = DateTime.Now }); 56 job1.Command = DT.Command.Pause; 60 57 job1.HiveExperimentId = he.Id; 61 58 job1.IsPrivileged = true; … … 110 107 111 108 // test jobstates 112 job1.StateLog.Add(new DT.StateLog { State = JobState.Transferring, DateTime = DateTime.Now }); Thread.Sleep(10);113 job1.StateLog.Add(new DT.StateLog { State = JobState.Calculating, DateTime = DateTime.Now }); Thread.Sleep(10);114 job1.StateLog.Add(new DT.StateLog { State = JobState.Transferring, DateTime = DateTime.Now }); Thread.Sleep(10);115 job1.StateLog.Add(new DT.StateLog { State = JobState.Finished, DateTime = DateTime.Now }); Thread.Sleep(10);109 job1.StateLog.Add(new DT.StateLog { State = DT.JobState.Transferring, DateTime = DateTime.Now }); Thread.Sleep(10); 110 job1.StateLog.Add(new DT.StateLog { State = DT.JobState.Calculating, DateTime = DateTime.Now }); Thread.Sleep(10); 111 job1.StateLog.Add(new DT.StateLog { State = DT.JobState.Transferring, DateTime = DateTime.Now }); Thread.Sleep(10); 112 job1.StateLog.Add(new DT.StateLog { State = DT.JobState.Finished, DateTime = DateTime.Now }); Thread.Sleep(10); 116 113 dao.UpdateJob(job1); 117 114 … … 226 223 227 224 DT.Job job = new DT.Job(); 228 job.State = JobState.Offline;229 job.StateLog.Add(new DT.StateLog { State = JobState.Offline, DateTime = DateTime.Now });225 job.State = DT.JobState.Offline; 226 job.StateLog.Add(new DT.StateLog { State = DT.JobState.Offline, DateTime = DateTime.Now }); 230 227 job.HiveExperimentId = he.Id; 231 228 job.Id = dao.AddJob(job); … … 235 232 perm.GrantedByUserId = he.OwnerUserId; 236 233 perm.GrantedUserId = Guid.NewGuid(); 237 perm.Permission = Permission.Full;234 perm.Permission = DT.Permission.Full; 238 235 dao.AddHiveExperimentPermission(perm); 239 236 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/HeuristicLab.Services.Hive.Tests-3.3.csproj
r6701 r6717 114 114 <Reference Include="System.Data.Linq" /> 115 115 <Reference Include="System.Drawing" /> 116 <Reference Include="System.Runtime.Serialization" /> 116 117 <Reference Include="System.ServiceModel" /> 117 118 <Reference Include="System.Transactions" /> … … 135 136 <Name>HeuristicLab.Hive-3.3</Name> 136 137 </ProjectReference> 137 <ProjectReference Include="..\HeuristicLab.Services.Hive.Common\3.3\HeuristicLab.Services.Hive.Common-3.3.csproj">138 <Project>{14424A16-48D4-445E-80BF-DDF617548BBB}</Project>139 <Name>HeuristicLab.Services.Hive.Common-3.3</Name>140 </ProjectReference>141 138 <ProjectReference Include="..\HeuristicLab.Services.Hive.DataAccess\3.3\HeuristicLab.Services.Hive.DataAccess-3.3.csproj"> 142 139 <Project>{EC2C8109-6E1E-4C88-9A2B-908CFF2EF4AC}</Project> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/Mocks/MockAuthorizationManager.cs
r6463 r6717 28 28 } 29 29 30 public void AuthorizeForJob(Guid jobId, Common.DataTransfer.Permission requiredPermission) {30 public void AuthorizeForJob(Guid jobId, DataTransfer.Permission requiredPermission) { 31 31 // ok. 32 32 } 33 33 34 public void AuthorizeForExperiment(Guid experimentId, Common.DataTransfer.Permission requiredPermission) {34 public void AuthorizeForExperiment(Guid experimentId, DataTransfer.Permission requiredPermission) { 35 35 // ok. 36 36 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs
r6698 r6717 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Services.Hive.Common; 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 27 using HeuristicLab.Services.Hive.Common.ServiceContracts; 25 using HeuristicLab.Clients.Hive; 28 26 using HeuristicLab.Services.Hive.Tests.Mocks; 29 27 using Microsoft.VisualStudio.TestTools.UnitTesting; 30 using DT = HeuristicLab.Services.Hive. Common.DataTransfer;28 using DT = HeuristicLab.Services.Hive.DataTransfer; 31 29 32 30 namespace HeuristicLab.Services.Hive.Tests { … … 42 40 } 43 41 44 private IHiveService GetLocalService() {45 return new H iveService();42 private HeuristicLab.Services.Hive.ServiceContracts.IHiveService GetLocalService() { 43 return new HeuristicLab.Services.Hive.HiveService(); 46 44 } 47 45 … … 55 53 // create job 56 54 DT.Job job = new DT.Job() { CoresNeeded = 1, MemoryNeeded = 0, Priority = 0 }; 57 job.State = JobState.Offline;58 job.StateLog.Add(new StateLog { State =JobState.Offline, DateTime = DateTime.Now });55 job.State = DT.JobState.Offline; 56 job.StateLog.Add(new DT.StateLog { State = DT.JobState.Offline, DateTime = DateTime.Now }); 59 57 60 58 DT.JobData jobData = new DT.JobData() { … … 80 78 pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 }; 81 79 82 plugin1.Id = service.AddPlugin(plugin1, new List< PluginData> { pluginData1 });80 plugin1.Id = service.AddPlugin(plugin1, new List<DT.PluginData> { pluginData1 }); 83 81 pluginData1.PluginId = plugin1.Id; 84 82 … … 87 85 88 86 // create slave 89 DT.Slave slave = new Slave();87 DT.Slave slave = new DT.Slave(); 90 88 slave.Id = Guid.NewGuid(); 91 89 slave.Name = "TestSlave"; … … 94 92 slave.CpuSpeed = 2800; 95 93 slave.OperatingSystem = "Windows 3.11"; 96 slave.CpuArchitecture = CpuArchitecture.x64;94 slave.CpuArchitecture = DT.CpuArchitecture.x64; 97 95 98 96 // add slave … … 112 110 Assert.AreEqual(job.MemoryNeeded, jobLoaded.MemoryNeeded); 113 111 Assert.AreEqual(job.Priority, jobLoaded.Priority); 114 Assert.AreEqual( JobState.Waiting, jobLoaded.State);112 Assert.AreEqual(DT.JobState.Waiting, jobLoaded.State); 115 113 Assert.IsTrue(job.PluginsNeededIds.SequenceEqual(jobLoaded.PluginsNeededIds)); 116 114 Assert.AreEqual(job.HiveExperimentId, jobLoaded.HiveExperimentId); … … 127 125 128 126 // test assigned ressources 129 var actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() });127 var actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 130 128 Assert.AreEqual(1, actions.Count); 131 129 Assert.AreEqual(MessageContainer.MessageType.CalculateJob, actions[0].Message); … … 136 134 137 135 // slave is responsible for updating state to 'Calculating' 138 service.UpdateJobState(jobLoaded.Id, JobState.Calculating, slave.Id, null, null);136 service.UpdateJobState(jobLoaded.Id, DT.JobState.Calculating, slave.Id, null, null); 139 137 140 138 // send progress 141 139 var progress = new Dictionary<Guid, TimeSpan>(); 142 140 progress.Add(job.Id, new TimeSpan(1, 5, 10, 20, 30)); 143 actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 3, FreeMemory = 1024, JobProgress = progress });141 actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 3, FreeMemory = 1024, JobProgress = progress }); 144 142 Assert.AreEqual(0, actions.Count); 145 143 … … 155 153 156 154 // set it to finished 157 service.UpdateJobState(jobLoaded.Id, JobState.Finished, slave.Id, null, null);155 service.UpdateJobState(jobLoaded.Id, DT.JobState.Finished, slave.Id, null, null); 158 156 159 157 // test if the job is returned for the resource (it should not be) … … 162 160 163 161 // set job waiting again 164 service.UpdateJobState(job.Id, JobState.Waiting, null, null, string.Empty);162 service.UpdateJobState(job.Id, DT.JobState.Waiting, null, null, string.Empty); 165 163 166 164 // get job again 167 actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() });165 actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 168 166 Assert.AreEqual(1, actions.Count); 169 167 Assert.AreEqual(MessageContainer.MessageType.CalculateJob, actions[0].Message); … … 171 169 172 170 // create downtime which should make slave unavailable for calculation 173 Guid downtimeId = service.AddDowntime(new D owntime { ResourceId = slave.Id, StartDate = DateTime.Now - TimeSpan.FromMinutes(1), EndDate = DateTime.Now + TimeSpan.FromMinutes(1), Recurring = false });171 Guid downtimeId = service.AddDowntime(new DT.Downtime { ResourceId = slave.Id, StartDate = DateTime.Now - TimeSpan.FromMinutes(1), EndDate = DateTime.Now + TimeSpan.FromMinutes(1), Recurring = false }); 174 172 175 173 progress.Clear(); 176 174 progress.Add(job.Id, new TimeSpan(1, 5, 10, 20, 30)); 177 actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() });175 actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 178 176 Assert.AreEqual(1, actions.Count); 179 177 Assert.AreEqual(MessageContainer.MessageType.PauseAll, actions[0].Message); … … 189 187 190 188 // send another heartbeat with the deleted job; the server should command the abortion of the job 191 actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 3, FreeMemory = 1024, JobProgress = progress });189 actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 3, FreeMemory = 1024, JobProgress = progress }); 192 190 Assert.AreEqual(1, actions.Count); 193 191 Assert.AreEqual(MessageContainer.MessageType.AbortJob, actions[0].Message); … … 213 211 FinishWhenChildJobsFinished = true 214 212 }; 215 parentJob.State = JobState.Offline;216 parentJob.StateLog.Add(new StateLog { State =JobState.Offline, DateTime = DateTime.Now });213 parentJob.State = DT.JobState.Offline; 214 parentJob.StateLog.Add(new DT.StateLog { State = DT.JobState.Offline, DateTime = DateTime.Now }); 217 215 218 216 DT.JobData parentJobData = new DT.JobData() { Data = new byte[0] }; … … 224 222 Priority = 0 225 223 }; 226 childJob.State = JobState.Offline;227 childJob.StateLog.Add(new StateLog { State =JobState.Offline, DateTime = DateTime.Now });224 childJob.State = DT.JobState.Offline; 225 childJob.StateLog.Add(new DT.StateLog { State = DT.JobState.Offline, DateTime = DateTime.Now }); 228 226 229 227 DT.JobData childJobData = new DT.JobData() { Data = new byte[1000] }; 230 228 231 229 // create slave 232 DT.Slave slave = new Slave();230 DT.Slave slave = new DT.Slave(); 233 231 slave.Id = Guid.NewGuid(); 234 232 slave.Name = "TestSlave"; … … 237 235 slave.CpuSpeed = 2800; 238 236 slave.OperatingSystem = "Windows 3.11"; 239 slave.CpuArchitecture = CpuArchitecture.x64;237 slave.CpuArchitecture = DT.CpuArchitecture.x64; 240 238 241 239 // add slave … … 258 256 Assert.AreEqual(childJob.ParentJobId, childJobLoaded.ParentJobId); 259 257 Assert.AreEqual(childJob.HiveExperimentId, childJobLoaded.HiveExperimentId); 260 Assert.AreEqual( JobState.Waiting, childJobLoaded.State);258 Assert.AreEqual(DT.JobState.Waiting, childJobLoaded.State); 261 259 Assert.AreEqual(false, childJobLoaded.FinishWhenChildJobsFinished); 262 260 Assert.AreEqual(false, childJobLoaded.IsParentJob); … … 270 268 271 269 // test heartbeat 272 var actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() });270 var actions = service.Heartbeat(new DT.Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 273 271 Assert.AreEqual(1, actions.Count); // only the child job should be assigned 274 272 Assert.AreEqual(MessageContainer.MessageType.CalculateJob, actions[0].Message); … … 282 280 283 281 // set child job to finished 284 childJobLoaded = service.UpdateJobState(childJobLoaded.Id, JobState.Finished, slave.Id, null, null);282 childJobLoaded = service.UpdateJobState(childJobLoaded.Id, DT.JobState.Finished, slave.Id, null, null); 285 283 286 284 // lifecycle - let it process one server-heartbeat; this should set the parent job to finished … … 308 306 DT.HiveExperiment e1 = new DT.HiveExperiment() { Name = "TestExperiment", Description = "" }; 309 307 e1.Id = service.AddHiveExperiment(e1); 310 308 311 309 var e1loaded = service.GetHiveExperiment(e1.Id); 312 310 Assert.AreEqual(Permission.Full, e1loaded.Permission); 313 311 var allExp = service.GetHiveExperiments(); 314 312 Assert.AreEqual(1, allExp.Count(x => x.Id == e1.Id)); 315 313 316 314 // change to user2 317 315 mockServiceLocator.SetCurrentUserId(MockUserManager.MockUserId2); … … 319 317 e1loaded = service.GetHiveExperiment(e1.Id); 320 318 Assert.Fail("Access should not be possible"); 321 } catch { /* ok, cool */ } 319 } 320 catch { /* ok, cool */ } 322 321 allExp = service.GetHiveExperiments(); 323 322 Assert.AreEqual(0, allExp.Count(x => x.Id == e1.Id)); … … 325 324 // user2 should not be able to grant permissions 326 325 try { 327 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, Permission.Read);326 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, DT.Permission.Read); 328 327 Assert.Fail("Should not be possible to grant permission due to missing permission for User2"); 329 328 } … … 332 331 // switch back to user1 (owner) and grant user2 permissions 333 332 mockServiceLocator.SetCurrentUserId(MockUserManager.MockUserId1); 334 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, Permission.Read);333 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, DT.Permission.Read); 335 334 336 335 // back to user2 … … 343 342 // user2 should still not be able to grant permissions 344 343 try { 345 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, Permission.Read);344 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, DT.Permission.Read); 346 345 Assert.Fail("Should not be possible to grant permission due to missing permission for User2"); 347 346 } … … 350 349 // back to user1 351 350 mockServiceLocator.SetCurrentUserId(MockUserManager.MockUserId1); 352 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, Permission.Full);351 service.GrantPermission(e1.Id, MockUserManager.MockUserId2, DT.Permission.Full); 353 352 354 353 // back to user2 … … 358 357 allExp = service.GetHiveExperiments(); 359 358 Assert.AreEqual(1, allExp.Count(x => x.Id == e1.Id)); 360 359 361 360 // grant rights to user3, now this should be possible due to full permissions 362 service.GrantPermission(e1.Id, MockUserManager.MockUserId3, Permission.Read);361 service.GrantPermission(e1.Id, MockUserManager.MockUserId3, DT.Permission.Read); 363 362 364 363 // back to user1 and revoke rights for user2
Note: See TracChangeset
for help on using the changeset viewer.