Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs @ 5955

Last change on this file since 5955 was 5718, checked in by cneumuel, 14 years ago

#1233

  • fixed statelog when time on server differs from slave or client
  • fixed wrong creation of childjobs in experiment manager
  • made ganttchardview the default view for statelogs
File size: 6.8 KB
RevLine 
[5156]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
[5055]23using System.Collections.Generic;
24using System.Linq;
[5137]25using Microsoft.VisualStudio.TestTools.UnitTesting;
[5055]26
[5599]27namespace HeuristicLab.Clients.Hive.SlaveCore.Tests {
[5055]28  [TestClass]
29  public class SlaveTest {
[5158]30    private static SlaveCommListener listener;
31
[5055]32    // Use ClassInitialize to run code before running the first test in the class
33    [ClassInitialize]
34    public static void MyClassInitialize(TestContext testContext) {
[5137]35      PluginLoader.pluginAssemblies.Any();
[5062]36      ServiceLocator.Instance = new MockServiceLocator();
[5325]37      /* listener = new SlaveCommListener();
38       listener.Open();*/
[5055]39    }
40
[5158]41    [ClassCleanup]
42    public static void MyClassCleanup() {
[5325]43      //listener.Close();
[5158]44    }
45
46
[5137]47    private List<List<MessageContainer>> CreateMsgsForSingleJob() {
[5104]48      List<List<MessageContainer>> allMsgs = new List<List<MessageContainer>>();
49      //get slave to fetch job
50      List<MessageContainer> msg = new List<MessageContainer>();
[5404]51      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
[5104]52      allMsgs.Add(msg);
53
54      //do nothing
55      msg = new List<MessageContainer>();
56      allMsgs.Add(msg);
[5137]57      msg = new List<MessageContainer>();
58      allMsgs.Add(msg);
59      msg = new List<MessageContainer>();
60      allMsgs.Add(msg);
61      msg = new List<MessageContainer>();
62      allMsgs.Add(msg);
[5158]63      msg = new List<MessageContainer>();
64      allMsgs.Add(msg);
[5104]65
66      msg = new List<MessageContainer>();
67      msg.Add(new MessageContainer(MessageContainer.MessageType.ShutdownSlave));
68      allMsgs.Add(msg);
69      return allMsgs;
70    }
71
[5055]72    [TestMethod]
[5137]73    public void TestSingleJob() {
[5511]74      Job testJob = new Job { Id = Guid.NewGuid(), CoresNeeded = 1, MemoryNeeded = 0 };
[5718]75      testJob.State = JobState.Waiting;
[5137]76      List<Job> jobList = new List<Job>();
77      jobList.Add(testJob);
[5158]78      MockJob job = new MockJob(300, false);
[5137]79
[5526]80      ServiceLocator.Instance.CallHiveService(service => {
81        MockHiveService ms = (MockHiveService)service;
82        ((MockHiveService)service).Messages = CreateMsgsForSingleJob();
83        ((MockHiveService)service).updateJobs(jobList, job);
[5137]84
[5599]85        HeuristicLab.Clients.Hive.SlaveCore.Core core = new SlaveCore.Core();
[5137]86        core.Start();
87
88        Assert.AreEqual<int>(1, ms.ResultJobs.Count);
89        Assert.AreEqual<Guid>(testJob.Id, ms.ResultJobs[0].Id);
[5325]90        core.Shutdown();
[5526]91      });
[5055]92    }
[5137]93
94    private List<List<MessageContainer>> CreateMsgsForShutdownSlaveWhileJobRunning() {
95      List<List<MessageContainer>> allMsgs = new List<List<MessageContainer>>();
96      //get slave to fetch job
97      List<MessageContainer> msg = new List<MessageContainer>();
[5404]98      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
[5137]99      allMsgs.Add(msg);
100
101      msg = new List<MessageContainer>();
102      allMsgs.Add(msg);
103
104      msg = new List<MessageContainer>();
105      msg.Add(new MessageContainer(MessageContainer.MessageType.ShutdownSlave));
106      allMsgs.Add(msg);
107      return allMsgs;
108    }
109
110    [TestMethod]
111    public void TestShutdownSlaveWhileJobRunning() {
[5511]112      Job testJob = new Job { Id = Guid.NewGuid(), CoresNeeded = 1, MemoryNeeded = 0 };
[5718]113      testJob.State = JobState.Waiting;
[5137]114      List<Job> jobList = new List<Job>();
115      jobList.Add(testJob);
116      MockJob job = new MockJob(10000, false);
117
[5526]118      ServiceLocator.Instance.CallHiveService(service => {
119        MockHiveService ms = (MockHiveService)service;
120        ((MockHiveService)service).Messages = CreateMsgsForShutdownSlaveWhileJobRunning();
121        ((MockHiveService)service).updateJobs(jobList, job);
[5137]122
123
[5599]124        HeuristicLab.Clients.Hive.SlaveCore.Core core = new SlaveCore.Core();
[5137]125        core.Start();
[5526]126      });
[5137]127    }
128
129
130    private List<List<MessageContainer>> CreateMsgsForTwoJobs() {
131      List<List<MessageContainer>> allMsgs = new List<List<MessageContainer>>();
132
133      //get slave to fetch jobs
134      List<MessageContainer> msg = new List<MessageContainer>();
[5404]135      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
[5137]136      allMsgs.Add(msg);
137
138      msg = new List<MessageContainer>();
139      allMsgs.Add(msg);
140
141      msg = new List<MessageContainer>();
[5404]142      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
[5137]143      allMsgs.Add(msg);
144
145
146      msg = new List<MessageContainer>();
147      allMsgs.Add(msg);
148      msg = new List<MessageContainer>();
149      allMsgs.Add(msg);
150      msg = new List<MessageContainer>();
151      allMsgs.Add(msg);
152      msg = new List<MessageContainer>();
153      allMsgs.Add(msg);
154      msg = new List<MessageContainer>();
155      allMsgs.Add(msg);
156      msg = new List<MessageContainer>();
157      allMsgs.Add(msg);
158      msg = new List<MessageContainer>();
159      allMsgs.Add(msg);
160      msg = new List<MessageContainer>();
161      allMsgs.Add(msg);
162      msg = new List<MessageContainer>();
163      allMsgs.Add(msg);
164
165      msg = new List<MessageContainer>();
166      msg.Add(new MessageContainer(MessageContainer.MessageType.ShutdownSlave));
167      allMsgs.Add(msg);
168      return allMsgs;
169    }
170
171    [TestMethod]
172    public void TestTwoJobs() {
[5511]173      Job testJob1 = new Job { Id = Guid.NewGuid(), CoresNeeded = 1, MemoryNeeded = 0 };
[5718]174      testJob1.State = JobState.Waiting;
[5511]175      Job testJob2 = new Job { Id = Guid.NewGuid(), CoresNeeded = 1, MemoryNeeded = 0 };
[5718]176      testJob2.State = JobState.Waiting;
[5137]177      List<Job> jobList = new List<Job>();
178      jobList.Add(testJob1);
179      jobList.Add(testJob2);
180      MockJob job = new MockJob(2000, false);
181
[5526]182      ServiceLocator.Instance.CallHiveService(service => {
183        MockHiveService ms = (MockHiveService)service;
184        ((MockHiveService)service).Messages = CreateMsgsForTwoJobs();
185        ((MockHiveService)service).updateJobs(jobList, job);
[5137]186
187
[5599]188        HeuristicLab.Clients.Hive.SlaveCore.Core core = new SlaveCore.Core();
[5137]189        core.Start();
190        Assert.AreEqual<int>(2, ms.ResultJobs.Count);
[5325]191        core.Shutdown();
[5526]192      });
[5137]193    }
[5055]194  }
195}
Note: See TracBrowser for help on using the repository browser.