Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests-3.4/Mocks/MockHiveService.cs @ 5062

Last change on this file since 5062 was 5062, checked in by cneumuel, 13 years ago

#1233

  • implemented MockService, MockJob, MockServiceLocator
File size: 5.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Services.Hive.Common.ServiceContracts;
6using HeuristicLab.Services.Hive.Common.DataTransfer;
7using HeuristicLab.Services.Hive.Common;
8
9namespace HeuristicLab.Clients.Hive.Slave.Tests {
10  internal class MockHiveService : IHiveService {
11    private static List<Job> jobs;
12    private static List<JobData> jobDatas;
13    private static List<HiveExperiment> hiveExperiments;
14
15    static MockHiveService() {
16     
17      byte[] data = PersistenceUtil.Serialize(new MockJob(5000));
18
19      jobs = new List<Job>();
20      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Waiting, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 0 });
21      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 100, ParentJobId = jobs.First().Id });
22      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 1024, ParentJobId = jobs.First().Id });
23      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 4096, ParentJobId = jobs.First().Id });
24
25      jobDatas = new List<JobData>();
26      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 });
32    }
33
34    #region Job Methods
35    public Guid AddJob(Job job, JobData jobData) {
36      job.Id = Guid.NewGuid();
37      jobData.JobId = job.Id;
38      jobs.Add(job);
39      jobDatas.Add(jobData);
40      return job.Id;
41    }
42
43    public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
44      job.Id = Guid.NewGuid();
45      job.ParentJobId = parentJobId;
46      jobData.JobId = job.Id;
47      jobs.Add(job);
48      jobDatas.Add(jobData);
49      return job.Id;
50    }
51
52    public Job GetJob(Guid jobId) {
53      return jobs.Where(j => j.Id == jobId).SingleOrDefault();
54    }
55
56    public IEnumerable<Job> GetJobs() {
57      return jobs;
58    }
59
60    public IEnumerable<LightweightJob> GetLightweightJobs(IEnumerable<Guid> jobIds) {
61      return jobs.Select(j => new LightweightJob(j)); // not real
62    }
63
64    public IEnumerable<LightweightJob> GetLightweightChildJobs(Guid? parentJobId, bool recursive, bool includeParent) {
65      return jobs.Where(j => j.ParentJobId.HasValue).Select(j => new LightweightJob(j));
66    }
67
68    public JobData GetJobData(Guid jobId) {
69      return jobDatas.Where(jd => jd.JobId == jobId).SingleOrDefault();
70    }
71
72    public void UpdateJob(Job jobDto, JobData jobDataDto) {
73      // do nothing
74    }
75
76    public void DeleteChildJobs(Guid parentJobId) {
77      // do nothing
78    }
79    #endregion
80
81    #region JobControl Methods
82    public Job AquireJob(Guid slaveId) {
83      var job = jobs.First();
84      job.SlaveId = slaveId;
85      return job;
86    }
87
88    public void StopJob(Guid jobId) {
89      // do nothing
90    }
91
92    public void PauseJob(Guid jobId) {
93      // do nothing
94    }
95    #endregion
96
97    #region HiveExperiment Methods
98    public HiveExperiment GetHiveExperiment(Guid id) {
99      return hiveExperiments.Where(he => he.Id == id).SingleOrDefault();
100    }
101
102    public IEnumerable<HiveExperiment> GetHiveExperiments() {
103      return hiveExperiments;
104    }
105
106    public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) {
107      hiveExperimentDto.Id = Guid.NewGuid();
108      hiveExperiments.Add(hiveExperimentDto);
109      return hiveExperimentDto.Id;
110    }
111
112    public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) {
113      // do nothing
114    }
115
116    public void DeleteHiveExperiment(Guid hiveExperimentId) {
117      // do nothing
118    }
119    #endregion
120
121    #region Login Methods
122    public void Hello(Guid slaveId, string name, int cores, int memory) {
123      // do nothing
124    }
125
126    public void GoodBye() {
127      // do nothing
128    }
129
130    public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
131      // todo
132      return new List<MessageContainer>();
133    }
134    #endregion
135
136    #region Plugin Methods
137    public Guid AddPlugin(Plugin plugin, List<PluginData> pluginData) {
138      // todo
139      return Guid.NewGuid();
140    }
141
142    public IEnumerable<Plugin> GetPlugins() {
143      // todo
144      return new List<Plugin>();
145    }
146
147    public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
148      // todo
149      return new List<PluginData>();
150    }
151    #endregion
152
153    #region Slave Methods
154    public Guid AddSlave(Services.Hive.Common.DataTransfer.Slave slave) {
155      throw new NotImplementedException();
156    }
157
158    public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
159      throw new NotImplementedException();
160    }
161
162    public IEnumerable<Services.Hive.Common.DataTransfer.Slave> GetSlaves() {
163      throw new NotImplementedException();
164    }
165
166    public IEnumerable<SlaveGroup> GetSlaveGroups() {
167      throw new NotImplementedException();
168    }
169
170    public void DeleteSlaveGroup(Guid clientGroupId) {
171      throw new NotImplementedException();
172    }
173
174    public void AddResourceToGroup(Guid slaveGroupId, Resource resource) {
175      throw new NotImplementedException();
176    }
177
178    public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) {
179      throw new NotImplementedException();
180    }
181
182    public void UpdateSlave(Services.Hive.Common.DataTransfer.Slave slave) {
183      throw new NotImplementedException();
184    }
185    #endregion
186  }
187}
Note: See TracBrowser for help on using the repository browser.