Changeset 5104
- Timestamp:
- 12/14/10 16:07:42 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockHiveService.cs
r5062 r5104 6 6 using HeuristicLab.Services.Hive.Common.DataTransfer; 7 7 using HeuristicLab.Services.Hive.Common; 8 using HeuristicLab.PluginInfrastructure.Manager; 9 using System.IO; 10 using System.Reflection; 11 using HeuristicLab.PluginInfrastructure; 8 12 9 13 namespace HeuristicLab.Clients.Hive.Slave.Tests { … … 11 15 private static List<Job> jobs; 12 16 private static List<JobData> jobDatas; 13 private static List<HiveExperiment> hiveExperiments; 17 private static List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment> hiveExperiments; 18 private static List<Plugin> plugins = null; 19 private static IEnumerable<PluginDescription> pDescs = null; 20 private static int cnt = 0; 21 22 public List<List<MessageContainer>> Messages { get; set; } 23 public static string ServerPluginCachePath { get; set; } 24 public static string ServerConfigFilePath { get; set; } 14 25 15 26 static MockHiveService() { 16 17 byte[] data = PersistenceUtil.Serialize(new MockJob(5000)); 27 ServerPluginCachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginCacheServer"); 28 ServerConfigFilePath = Path.Combine(ServerPluginCachePath, "HeuristicLab 3.3.exe.config"); 29 30 byte[] data = PersistenceUtil.Serialize(new MockJob(4000)); 31 if (plugins == null) 32 plugins = ReadPluginsFromServerCache(); 18 33 19 34 jobs = new List<Job>(); … … 25 40 jobDatas = new List<JobData>(); 26 41 foreach (var job in jobs) { 27 jobDatas.Add(new JobData() { JobId = job.Id, Data = data }); 28 } 29 30 hiveExperiments = new List<HiveExperiment>(); 31 hiveExperiments.Add(new HiveExperiment() { Id = Guid.NewGuid(), Name = "Hive Exp 1", Description = "", RootJobId = jobs[0].Id }); 42 job.PluginsNeededIds = new List<Guid>(); 43 job.PluginsNeededIds.AddRange(plugins.Select(a => a.Id)); 44 jobDatas.Add(new JobData() { JobId = job.Id, Data = data }); 45 } 46 47 hiveExperiments = new List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment>(); 48 hiveExperiments.Add(new HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment() { Id = Guid.NewGuid(), Name = "Hive Exp 1", Description = "", RootJobId = jobs[0].Id }); 49 } 50 51 private static List<Plugin> ReadPluginsFromServerCache() { 52 PluginManager pm = new PluginManager(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginCacheServer")); 53 pm.DiscoverAndCheckPlugins(); 54 pDescs = pm.Plugins; 55 plugins = new List<Plugin>(); 56 foreach (PluginDescription d in pDescs) { 57 Plugin p = new Plugin(); 58 p.Name = d.Name; 59 p.Version = d.Version; 60 p.Id = Guid.NewGuid(); 61 plugins.Add(p); 62 } 63 return plugins; 32 64 } 33 65 … … 50 82 } 51 83 84 public PluginData GetConfigurationFile() { 85 byte[] cf = File.ReadAllBytes(ServerConfigFilePath); 86 PluginData pd = new PluginData(); 87 pd.Data = cf; 88 return pd; 89 } 90 52 91 public Job GetJob(Guid jobId) { 53 92 return jobs.Where(j => j.Id == jobId).SingleOrDefault(); … … 71 110 72 111 public void UpdateJob(Job jobDto, JobData jobDataDto) { 73 // do nothing112 Console.WriteLine("Update Job called!"); 74 113 } 75 114 … … 96 135 97 136 #region HiveExperiment Methods 98 public H iveExperiment GetHiveExperiment(Guid id) {137 public HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment GetHiveExperiment(Guid id) { 99 138 return hiveExperiments.Where(he => he.Id == id).SingleOrDefault(); 100 139 } 101 140 102 public IEnumerable<H iveExperiment> GetHiveExperiments() {141 public IEnumerable<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment> GetHiveExperiments() { 103 142 return hiveExperiments; 104 143 } 105 144 106 public Guid AddHiveExperiment(H iveExperiment hiveExperimentDto) {145 public Guid AddHiveExperiment(HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment hiveExperimentDto) { 107 146 hiveExperimentDto.Id = Guid.NewGuid(); 108 147 hiveExperiments.Add(hiveExperimentDto); … … 110 149 } 111 150 112 public void UpdateHiveExperiment(H iveExperiment hiveExperimentDto) {151 public void UpdateHiveExperiment(HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment hiveExperimentDto) { 113 152 // do nothing 114 153 } … … 126 165 public void GoodBye() { 127 166 // do nothing 128 } 129 167 } 168 130 169 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 131 // todo 132 return new List<MessageContainer>(); 133 } 170 if (Messages != null && cnt < Messages.Count) { 171 return Messages[cnt++]; 172 } else { 173 return new List<MessageContainer>(); 174 } 175 } 176 134 177 #endregion 135 178 … … 141 184 142 185 public IEnumerable<Plugin> GetPlugins() { 143 // todo 144 return new List<Plugin>(); 186 if (plugins == null) 187 plugins = ReadPluginsFromServerCache(); 188 return plugins; 145 189 } 146 190 147 191 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 148 // todo 149 return new List<PluginData>(); 192 List<PluginData> pluginDatas = new List<PluginData>(); 193 194 foreach (Guid guid in pluginIds) { 195 Plugin plugin = plugins.Find(p => p.Id == guid); 196 if (plugin != null) { 197 PluginDescription desc = pDescs.First(p => p.Name == plugin.Name && p.Version == plugin.Version); 198 if (desc != null) { 199 foreach (IPluginFile file in desc.Files) { 200 PluginData data = new PluginData(); 201 data.PluginId = guid; 202 data.Data = File.ReadAllBytes(file.Name); 203 pluginDatas.Add(data); 204 } 205 } 206 } 207 } 208 return pluginDatas; 150 209 } 151 210 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockJob.cs
r5062 r5104 97 97 this.ExecutionTime = DateTime.Now - start; 98 98 } while (ExecutionTime.TotalMilliseconds < ms); 99 this.ExecutionState = Core.ExecutionState.Stopped; 99 Stop(); 100 OnJobStopped(); 100 101 } 101 102 … … 148 149 if (handler != null) handler(this, EventArgs.Empty); 149 150 } 151 152 public event EventHandler JobFailed; 153 protected virtual void OnJobFailed() { 154 EventHandler handler = JobFailed; 155 if (handler != null) handler(this, EventArgs.Empty); 156 } 157 158 public event EventHandler JobStopped; 159 protected virtual void OnJobStopped() { 160 EventHandler handler = JobStopped; 161 if (handler != null) handler(this, EventArgs.Empty); 162 } 163 150 164 #endregion 151 165 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockServiceLocator.cs
r5062 r5104 9 9 internal class MockServiceLocator : IServiceLocator { 10 10 11 private MockHiveService service; 12 11 13 public Disposable<IHiveService> GetService() { 12 return new Disposable<IHiveService>(new MockHiveService()); 14 if (service == null) 15 service = new MockHiveService(); 16 17 return new Disposable<IHiveService>(service); 13 18 } 14 19 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs
r5062 r5104 4 4 using System.Linq; 5 5 using Microsoft.VisualStudio.TestTools.UnitTesting; 6 using HeuristicLab.Clients.Hive.Salve; 7 using HeuristicLab.Services.Hive.Common; 8 using HeuristicLab.Services.Hive.Common.ServiceContracts; 9 using HeuristicLab.Clients.Common; 6 10 7 11 namespace HeuristicLab.Clients.Hive.Slave.Tests { … … 12 16 [ClassInitialize] 13 17 public static void MyClassInitialize(TestContext testContext) { 14 PluginLoader.pluginAssemblies.Any(); 18 PluginLoader.pluginAssemblies.Any(); 15 19 ServiceLocator.Instance = new MockServiceLocator(); 20 } 21 22 public List<List<MessageContainer>> CreateMsgs() { 23 List<List<MessageContainer>> allMsgs = new List<List<MessageContainer>>(); 24 //get slave to fetch job 25 List<MessageContainer> msg = new List<MessageContainer>(); 26 msg.Add(new MessageContainer(MessageContainer.MessageType.AquireJob)); 27 allMsgs.Add(msg); 28 29 //do nothing 30 msg = new List<MessageContainer>(); 31 allMsgs.Add(msg); 32 33 msg = new List<MessageContainer>(); 34 msg.Add(new MessageContainer(MessageContainer.MessageType.ShutdownSlave)); 35 allMsgs.Add(msg); 36 return allMsgs; 16 37 } 17 38 18 39 [TestMethod] 19 40 public void TestMethod1() { 20 SlaveDummy slave = new SlaveDummy(); 41 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) { 42 ((MockHiveService)service.Obj).Messages = CreateMsgs(); 43 } 21 44 22 slave.SayHello(); 45 HeuristicLab.Clients.Hive.Salve.Core core = new Salve.Core(); 46 core.Start(); 23 47 } 24 48 }
Note: See TracChangeset
for help on using the changeset viewer.