Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/10 19:58:01 (14 years ago)
Author:
ascheibe
Message:

#1233

  • more tests for the hive slave
  • implemented a better way to write tests for the slave
  • get rid of MessageTypes for core and executor
  • various improvements in core and executor (better communication, bugfixes,...)
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources

    • Property svn:ignore
      •  

        old new  
         1*.suo
        12HeuristicLab.Hive-3.4.suo
        23TestResults
        3 HeuristicLab.Hive 3.4.suo
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockHiveService.cs

    r5106 r5137  
    11using System;
    22using System.Collections.Generic;
     3using System.IO;
    34using System.Linq;
    4 using System.Text;
     5using HeuristicLab.PluginInfrastructure;
     6using HeuristicLab.PluginInfrastructure.Manager;
     7using HeuristicLab.Services.Hive.Common;
     8using HeuristicLab.Services.Hive.Common.DataTransfer;
    59using 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;
    1210
    1311namespace HeuristicLab.Clients.Hive.Slave.Tests {
     
    1513    private static List<Job> jobs;
    1614    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;
    1816    private static List<Plugin> plugins = null;
     17    public List<Job> ResultJobs { get; set; }
     18    public List<JobData> ResultJobDatas { get; set; }
    1919    private static IEnumerable<PluginDescription> pDescs = null;
    2020    private static int cnt = 0;
     
    2828      ServerConfigFilePath = Path.Combine(ServerPluginCachePath, "HeuristicLab 3.3.exe.config");
    2929
    30       byte[] data = PersistenceUtil.Serialize(new MockJob(4000, false));
    3130      if (plugins == null)
    3231        plugins = ReadPluginsFromServerCache();
    3332
    34       jobs = new List<Job>();
     33
     34      //TODO: reuse as fallback?
     35      /*jobs = new List<Job>();
    3536      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Waiting, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 0 });
    3637      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 100, ParentJobId = jobs.First().Id });
    3738      jobs.Add(new Job { Id = Guid.NewGuid(), JobState = JobState.Offline, DateCreated = DateTime.Now, CoresNeeded = 1, MemoryNeeded = 1024, ParentJobId = jobs.First().Id });
    3839      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));
    4041      jobDatas = new List<JobData>();
    4142      foreach (var job in jobs) {
    4243        job.PluginsNeededIds = new List<Guid>();
    4344        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
    4763      hiveExperiments = new List<HeuristicLab.Services.Hive.Common.DataTransfer.HiveExperiment>();
    4864      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>();
    4968    }
    5069
     
    6079        p.Id = Guid.NewGuid();
    6180        plugins.Add(p);
     81
    6282      }
    6383      return plugins;
     
    87107      pd.Data = cf;
    88108      return pd;
     109
    89110    }
    90111
    91112    public Job GetJob(Guid jobId) {
     113      //MockHBM.SendHeartbeat();
    92114      return jobs.Where(j => j.Id == jobId).SingleOrDefault();
    93115    }
     
    106128
    107129    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;
    109133    }
    110134
    111135    public void UpdateJob(Job jobDto, JobData jobDataDto) {
    112136      Console.WriteLine("Update Job called!");
     137      ResultJobDatas.Add(jobDataDto);
     138      ResultJobs.Add(jobDto);
    113139    }
    114140
     
    123149
    124150    #region JobControl Methods
     151    int curJobIdx = 0;
    125152    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!");
    129160    }
    130161
     
    169200    public void GoodBye() {
    170201      // do nothing
    171     }   
    172    
     202    }
     203
    173204    public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
    174205      if (Messages != null && cnt < Messages.Count) {
     
    178209      }
    179210    }
    180      
     211
    181212    #endregion
    182213
    183214    #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
    187226    }
    188227
     
    190229      if (plugins == null)
    191230        plugins = ReadPluginsFromServerCache();
    192       return plugins;             
     231      return plugins;
    193232    }
    194233
     
    207246              pluginDatas.Add(data);
    208247            }
    209           }         
    210         }     
     248          }
     249        }
    211250      }
    212251      return pluginDatas;
Note: See TracChangeset for help on using the changeset viewer.