Changeset 5137 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks
- Timestamp:
- 12/20/10 19:58:01 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources
- Property svn:ignore
-
old new 1 *.suo 1 2 HeuristicLab.Hive-3.4.suo 2 3 TestResults 3 HeuristicLab.Hive 3.4.suo
-
- Property svn:ignore
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockHiveService.cs
r5106 r5137 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO; 3 4 using System.Linq; 4 using System.Text; 5 using HeuristicLab.PluginInfrastructure; 6 using HeuristicLab.PluginInfrastructure.Manager; 7 using HeuristicLab.Services.Hive.Common; 8 using HeuristicLab.Services.Hive.Common.DataTransfer; 5 9 using HeuristicLab.Services.Hive.Common.ServiceContracts; 6 using HeuristicLab.Services.Hive.Common.DataTransfer;7 using HeuristicLab.Services.Hive.Common;8 using HeuristicLab.PluginInfrastructure.Manager;9 using System.IO;10 using System.Reflection;11 using HeuristicLab.PluginInfrastructure;12 10 13 11 namespace HeuristicLab.Clients.Hive.Slave.Tests { … … 15 13 private static List<Job> jobs; 16 14 private static List<JobData> jobDatas; 17 private static List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment> hiveExperiments; 15 private static List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment> hiveExperiments; 18 16 private static List<Plugin> plugins = null; 17 public List<Job> ResultJobs { get; set; } 18 public List<JobData> ResultJobDatas { get; set; } 19 19 private static IEnumerable<PluginDescription> pDescs = null; 20 20 private static int cnt = 0; … … 28 28 ServerConfigFilePath = Path.Combine(ServerPluginCachePath, "HeuristicLab 3.3.exe.config"); 29 29 30 byte[] data = PersistenceUtil.Serialize(new MockJob(4000, false));31 30 if (plugins == null) 32 31 plugins = ReadPluginsFromServerCache(); 33 32 34 jobs = new List<Job>(); 33 34 //TODO: reuse as fallback? 35 /*jobs = new List<Job>(); 35 36 jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Waiting, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 0 }); 36 37 jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 100, ParentJobId = jobs.First().Id }); 37 38 jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 1024, ParentJobId = jobs.First().Id }); 38 39 jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 4096, ParentJobId = jobs.First().Id }); 39 40 byte[] data = PersistenceUtil.Serialize(new MockJob(400, false)); 40 41 jobDatas = new List<JobData>(); 41 42 foreach (var job in jobs) { 42 43 job.PluginsNeededIds = new List<Guid>(); 43 44 job.PluginsNeededIds.AddRange(plugins.Select(a => a.Id)); 44 jobDatas.Add(new JobData() { JobId = job.Id, Data = data }); 45 } 46 45 jobDatas.Add(new JobData() { JobId = job.Id, Data = data }); 46 } 47 48 hiveExperiments = new List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment>(); 49 hiveExperiments.Add(new HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment() { Id = Guid.NewGuid(), Name = "Hive Exp 1", Description = "", RootJobId = jobs[0].Id });*/ 50 } 51 52 public void updateJobs(List<Job> js, MockJob m) { 53 jobs = js; 54 byte[] data = PersistenceUtil.Serialize(m); 55 56 jobDatas = new List<JobData>(); 57 foreach (var job in jobs) { 58 job.PluginsNeededIds = new List<Guid>(); 59 job.PluginsNeededIds.AddRange(plugins.Select(a => a.Id)); 60 jobDatas.Add(new JobData() { JobId = job.Id, Data = data }); 61 } 62 47 63 hiveExperiments = new List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment>(); 48 64 hiveExperiments.Add(new HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment() { Id = Guid.NewGuid(), Name = "Hive Exp 1", Description = "", RootJobId = jobs[0].Id }); 65 66 ResultJobDatas = new List<JobData>(); 67 ResultJobs = new List<Job>(); 49 68 } 50 69 … … 60 79 p.Id = Guid.NewGuid(); 61 80 plugins.Add(p); 81 62 82 } 63 83 return plugins; … … 87 107 pd.Data = cf; 88 108 return pd; 109 89 110 } 90 111 91 112 public Job GetJob(Guid jobId) { 113 //MockHBM.SendHeartbeat(); 92 114 return jobs.Where(j => j.Id == jobId).SingleOrDefault(); 93 115 } … … 106 128 107 129 public JobData GetJobData(Guid jobId) { 108 return jobDatas.Where(jd => jd.JobId == jobId).SingleOrDefault(); 130 JobData ret = jobDatas.Where(jd => jd.JobId == jobId).SingleOrDefault(); 131 //MockHBM.SendHeartbeat(); 132 return ret; 109 133 } 110 134 111 135 public void UpdateJob(Job jobDto, JobData jobDataDto) { 112 136 Console.WriteLine("Update Job called!"); 137 ResultJobDatas.Add(jobDataDto); 138 ResultJobs.Add(jobDto); 113 139 } 114 140 … … 123 149 124 150 #region JobControl Methods 151 int curJobIdx = 0; 125 152 public Job AquireJob(Guid slaveId) { 126 var job = jobs.First(); 127 job.SlaveId = slaveId; 128 return job; 153 if (curJobIdx < jobs.Count) { 154 var job = jobs[curJobIdx]; 155 job.SlaveId = slaveId; 156 curJobIdx++; 157 return job; 158 } 159 throw new Exception("No Jobs left on MockHiveService!"); 129 160 } 130 161 … … 169 200 public void GoodBye() { 170 201 // do nothing 171 } 172 202 } 203 173 204 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 174 205 if (Messages != null && cnt < Messages.Count) { … … 178 209 } 179 210 } 180 211 181 212 #endregion 182 213 183 214 #region Plugin Methods 184 public Guid AddPlugin(Plugin plugin, List<PluginData> pluginData) { 185 // todo 186 return Guid.NewGuid(); 215 public Guid AddPlugin(Plugin p, List<PluginData> pds) { 216 /*p.Id = Guid.NewGuid(); 217 plugins.Add(p); 218 foreach (var pluginData in pds) { 219 pluginData.PluginId = p.Id; 220 pluginDatas.Add(pluginData); 221 222 } 223 return p.Id;*/ 224 throw new NotImplementedException(); 225 187 226 } 188 227 … … 190 229 if (plugins == null) 191 230 plugins = ReadPluginsFromServerCache(); 192 return plugins; 231 return plugins; 193 232 } 194 233 … … 207 246 pluginDatas.Add(data); 208 247 } 209 } 210 } 248 } 249 } 211 250 } 212 251 return pluginDatas; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockJob.cs
r5106 r5137 114 114 OnJobStopped(); 115 115 } 116 catch (ThreadAbortException) { 117 //this happens when the appdomain is killed (e.g. abort from server) 118 Stop(); 119 } 116 120 catch (Exception e) { 117 121 this.ExecutionState = Core.ExecutionState.Stopped; 118 OnJobFailed( );122 OnJobFailed(e); 119 123 } 120 124 } … … 170 174 171 175 public event EventHandler JobFailed; 172 protected virtual void OnJobFailed( ) {176 protected virtual void OnJobFailed(Exception e) { 173 177 EventHandler handler = JobFailed; 174 if (handler != null) handler(this, EventArgs.Empty); 178 EventArgs<Exception> ev = new EventArgs<Exception>(e); 179 if (handler != null) handler(this, ev); 175 180 } 176 181
Note: See TracChangeset
for help on using the changeset viewer.