1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.PluginInfrastructure;
|
---|
26 | using System.Net;
|
---|
27 | using HeuristicLab.Hive.Contracts;
|
---|
28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
29 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
30 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
31 | using System.Diagnostics;
|
---|
32 | using HeuristicLab.DataAccess.Interfaces;
|
---|
33 | using System.IO;
|
---|
34 | using HeuristicLab.Hive.Server.Core;
|
---|
35 | using HeuristicLab.Core;
|
---|
36 | using HeuristicLab.Hive.Server.LINQDataAccess;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.Hive.Server {
|
---|
39 | [Application("Hive DB Test App", "Test Application for the Hive DataAccess Layer")]
|
---|
40 | class HiveDbTestApplication : ApplicationBase {
|
---|
41 | /* private void TestClientAdapter() {
|
---|
42 | IClientAdapter clientAdapter =
|
---|
43 | ServiceLocator.GetClientAdapter();
|
---|
44 |
|
---|
45 | ClientInfo client = new ClientInfo();
|
---|
46 | client.Login = DateTime.Now;
|
---|
47 | clientAdapter.Update(client);
|
---|
48 |
|
---|
49 | ClientInfo clientRead =
|
---|
50 | clientAdapter.GetById(client.Id);
|
---|
51 | Debug.Assert(
|
---|
52 | clientRead != null &&
|
---|
53 | client.Id == clientRead.Id);
|
---|
54 |
|
---|
55 | client.CpuSpeedPerCore = 2000;
|
---|
56 | clientAdapter.Update(client);
|
---|
57 | clientRead =
|
---|
58 | clientAdapter.GetById(client.Id);
|
---|
59 | Debug.Assert(
|
---|
60 | clientRead != null &&
|
---|
61 | client.Id == clientRead.Id &&
|
---|
62 | clientRead.CpuSpeedPerCore == 2000);
|
---|
63 |
|
---|
64 | ICollection<ClientInfo> clients =
|
---|
65 | clientAdapter.GetAll();
|
---|
66 | int count = clients.Count;
|
---|
67 |
|
---|
68 | clientAdapter.Delete(client);
|
---|
69 |
|
---|
70 | clients = clientAdapter.GetAll();
|
---|
71 | Debug.Assert(count - 1 == clients.Count);
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void TestClientGroupAdapter() {
|
---|
75 | ISessionFactory factory =
|
---|
76 | ServiceLocator.GetSessionFactory();
|
---|
77 |
|
---|
78 | ISession session =
|
---|
79 | factory.GetSessionForCurrentThread();
|
---|
80 |
|
---|
81 | ITransaction trans = null;
|
---|
82 |
|
---|
83 | try {
|
---|
84 | IClientGroupAdapter clientGroupAdapter =
|
---|
85 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
86 |
|
---|
87 | trans =
|
---|
88 | session.BeginTransaction();
|
---|
89 |
|
---|
90 | ClientInfo client =
|
---|
91 | new ClientInfo();
|
---|
92 | client.Name = "Stefan";
|
---|
93 | client.Login = DateTime.Now;
|
---|
94 |
|
---|
95 | ClientInfo client2 =
|
---|
96 | new ClientInfo();
|
---|
97 | client2.Name = "Martin";
|
---|
98 | client2.Login = DateTime.Now;
|
---|
99 |
|
---|
100 | ClientInfo client3 =
|
---|
101 | new ClientInfo();
|
---|
102 | client3.Name = "Heinz";
|
---|
103 | client3.Login = DateTime.Now;
|
---|
104 |
|
---|
105 | ClientGroup group =
|
---|
106 | new ClientGroup();
|
---|
107 |
|
---|
108 | ClientGroup subGroup =
|
---|
109 | new ClientGroup();
|
---|
110 | subGroup.Resources.Add(client);
|
---|
111 |
|
---|
112 | group.Resources.Add(client3);
|
---|
113 | group.Resources.Add(client2);
|
---|
114 | group.Resources.Add(subGroup);
|
---|
115 |
|
---|
116 | clientGroupAdapter.Update(group);
|
---|
117 |
|
---|
118 | ClientGroup read =
|
---|
119 | clientGroupAdapter.GetById(group.Id);
|
---|
120 |
|
---|
121 | ICollection<ClientGroup> clientGroups =
|
---|
122 | clientGroupAdapter.GetAll();
|
---|
123 |
|
---|
124 | IClientAdapter clientAdapter =
|
---|
125 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
126 |
|
---|
127 | clientAdapter.Delete(client3);
|
---|
128 |
|
---|
129 | read =
|
---|
130 | clientGroupAdapter.GetById(group.Id);
|
---|
131 |
|
---|
132 | clientGroupAdapter.Delete(subGroup);
|
---|
133 |
|
---|
134 | read =
|
---|
135 | clientGroupAdapter.GetById(group.Id);
|
---|
136 |
|
---|
137 | clientGroups =
|
---|
138 | clientGroupAdapter.GetAll();
|
---|
139 |
|
---|
140 | clientGroupAdapter.Delete(group);
|
---|
141 |
|
---|
142 | clientGroups =
|
---|
143 | clientGroupAdapter.GetAll();
|
---|
144 |
|
---|
145 | clientAdapter.Delete(client);
|
---|
146 | clientAdapter.Delete(client2);
|
---|
147 | }
|
---|
148 | finally {
|
---|
149 | if (trans != null)
|
---|
150 | trans.Rollback();
|
---|
151 |
|
---|
152 | session.EndSession();
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | private void InsertTestClientGroups() {
|
---|
157 | ISessionFactory factory =
|
---|
158 | ServiceLocator.GetSessionFactory();
|
---|
159 |
|
---|
160 | ISession session =
|
---|
161 | factory.GetSessionForCurrentThread();
|
---|
162 |
|
---|
163 | ITransaction trans = null;
|
---|
164 |
|
---|
165 | try {
|
---|
166 | IClientGroupAdapter clientGroupAdapter =
|
---|
167 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
168 |
|
---|
169 | trans =
|
---|
170 | session.BeginTransaction();
|
---|
171 |
|
---|
172 | ClientInfo client =
|
---|
173 | new ClientInfo();
|
---|
174 | client.Name = "Stefan";
|
---|
175 | client.Login = DateTime.Now;
|
---|
176 |
|
---|
177 | ClientInfo client2 =
|
---|
178 | new ClientInfo();
|
---|
179 | client2.Name = "Martin";
|
---|
180 | client2.Login = DateTime.Now;
|
---|
181 |
|
---|
182 | ClientGroup group =
|
---|
183 | new ClientGroup();
|
---|
184 | group.Name = "Gruppe1";
|
---|
185 |
|
---|
186 | ClientGroup subGroup =
|
---|
187 | new ClientGroup();
|
---|
188 | subGroup.Name = "Untergruppe1";
|
---|
189 | subGroup.Resources.Add(client);
|
---|
190 |
|
---|
191 | group.Resources.Add(client2);
|
---|
192 | group.Resources.Add(subGroup);
|
---|
193 |
|
---|
194 | clientGroupAdapter.Update(group);
|
---|
195 |
|
---|
196 | trans.Commit();
|
---|
197 | }
|
---|
198 | finally {
|
---|
199 | session.EndSession();
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | private void TestJobAdapter() {
|
---|
204 | IJobAdapter jobAdapter =
|
---|
205 | ServiceLocator.GetJobAdapter();
|
---|
206 | IClientAdapter clientAdapter =
|
---|
207 | ServiceLocator.GetClientAdapter();
|
---|
208 |
|
---|
209 | Job job = new Job();
|
---|
210 |
|
---|
211 | ClientInfo client = new ClientInfo();
|
---|
212 | client.Login = DateTime.Now;
|
---|
213 |
|
---|
214 | job.Client = client;
|
---|
215 | jobAdapter.Update(job);
|
---|
216 |
|
---|
217 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
218 |
|
---|
219 | jobAdapter.Delete(job);
|
---|
220 | clientAdapter.Delete(client);
|
---|
221 |
|
---|
222 | jobs = jobAdapter.GetAll();
|
---|
223 | }
|
---|
224 |
|
---|
225 | private void TestJobResultsAdapter() {
|
---|
226 | Job job = new Job();
|
---|
227 |
|
---|
228 | ClientInfo client = new ClientInfo();
|
---|
229 | client.Login = DateTime.Now;
|
---|
230 |
|
---|
231 | job.Client = client;
|
---|
232 |
|
---|
233 | IJobResultsAdapter resultsAdapter =
|
---|
234 | ServiceLocator.GetJobResultsAdapter();
|
---|
235 |
|
---|
236 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
237 |
|
---|
238 | JobResult result = new JobResult();
|
---|
239 | result.Client = client;
|
---|
240 | result.Job = job;
|
---|
241 | result.Result = resultByte;
|
---|
242 |
|
---|
243 | resultsAdapter.Update(result);
|
---|
244 |
|
---|
245 | JobResult read =
|
---|
246 | resultsAdapter.GetById(result.Id);
|
---|
247 | Debug.Assert(
|
---|
248 | read.Id == result.Id &&
|
---|
249 | result.Client.Id == read.Client.Id &&
|
---|
250 | result.Job.Id == read.Job.Id &&
|
---|
251 | result.Result == result.Result);
|
---|
252 |
|
---|
253 | int count =
|
---|
254 | resultsAdapter.GetAll().Count;
|
---|
255 |
|
---|
256 | resultsAdapter.Delete(result);
|
---|
257 |
|
---|
258 | ICollection<JobResult> allResults =
|
---|
259 | resultsAdapter.GetAll();
|
---|
260 |
|
---|
261 | Debug.Assert(allResults.Count == count - 1);
|
---|
262 |
|
---|
263 | IJobAdapter jboAdapter =
|
---|
264 | ServiceLocator.GetJobAdapter();
|
---|
265 | jboAdapter.Delete(job);
|
---|
266 | IClientAdapter clientAdapter =
|
---|
267 | ServiceLocator.GetClientAdapter();
|
---|
268 | clientAdapter.Delete(client);
|
---|
269 | }
|
---|
270 |
|
---|
271 | private void TestTransaction() {
|
---|
272 | ISessionFactory factory =
|
---|
273 | ServiceLocator.GetSessionFactory();
|
---|
274 |
|
---|
275 | ISession session =
|
---|
276 | factory.GetSessionForCurrentThread();
|
---|
277 |
|
---|
278 | IClientAdapter clientAdapter =
|
---|
279 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
280 |
|
---|
281 | ITransaction trans =
|
---|
282 | session.BeginTransaction();
|
---|
283 |
|
---|
284 | ClientInfo client = new ClientInfo();
|
---|
285 | client.Login = DateTime.Now;
|
---|
286 | clientAdapter.Update(client);
|
---|
287 |
|
---|
288 | trans.Rollback();
|
---|
289 |
|
---|
290 | session.EndSession();
|
---|
291 | } */
|
---|
292 |
|
---|
293 | private void TestJobStreaming() {
|
---|
294 | ISessionFactory factory =
|
---|
295 | ServiceLocator.GetSessionFactory();
|
---|
296 |
|
---|
297 | ISession session =
|
---|
298 | factory.GetSessionForCurrentThread();
|
---|
299 |
|
---|
300 | IJobAdapter jobAdapter =
|
---|
301 | session.GetDataAdapter<HeuristicLab.Hive.Contracts.BusinessObjects.Job, IJobAdapter>();
|
---|
302 |
|
---|
303 | Stream s = jobAdapter.GetSerializedJobStream(
|
---|
304 | new Guid("1b35f32b-d880-4c76-86af-4b4e283b30e6"), true);
|
---|
305 |
|
---|
306 | int length = 0;
|
---|
307 |
|
---|
308 | FileStream fs =
|
---|
309 | new FileStream(@"W:\\result.gz", FileMode.Create);
|
---|
310 |
|
---|
311 | byte[] buffer = new byte[1024];
|
---|
312 | while ((length = s.Read(buffer, 0, buffer.Length)) > 0) {
|
---|
313 | fs.Write(buffer, 0, length);
|
---|
314 | }
|
---|
315 |
|
---|
316 | fs.Close();
|
---|
317 | s.Close();
|
---|
318 |
|
---|
319 | session.EndSession();
|
---|
320 | }
|
---|
321 |
|
---|
322 | private void TestJobResultStreaming() {
|
---|
323 | ISessionFactory factory =
|
---|
324 | ServiceLocator.GetSessionFactory();
|
---|
325 |
|
---|
326 | ISession session =
|
---|
327 | factory.GetSessionForCurrentThread();
|
---|
328 |
|
---|
329 | IJobResultsAdapter jobResultsAdapter =
|
---|
330 | session.GetDataAdapter<JobResult, IJobResultsAdapter>();
|
---|
331 |
|
---|
332 | Stream s = jobResultsAdapter.GetSerializedJobResultStream(
|
---|
333 | new Guid("c20b11a9-cde1-4d7f-8499-23dedb5a65ed"), true);
|
---|
334 |
|
---|
335 | int length = 0;
|
---|
336 |
|
---|
337 | FileStream fs =
|
---|
338 | new FileStream(@"W:\\result.gz", FileMode.Create);
|
---|
339 |
|
---|
340 | byte[] buffer = new byte[1024];
|
---|
341 | while ((length = s.Read(buffer, 0, buffer.Length)) > 0) {
|
---|
342 | fs.Write(buffer, 0, length);
|
---|
343 | }
|
---|
344 |
|
---|
345 | fs.Close();
|
---|
346 | s.Close();
|
---|
347 |
|
---|
348 | session.EndSession();
|
---|
349 | }
|
---|
350 |
|
---|
351 | private void TestJobResultDeserialization() {
|
---|
352 | ExecutionEngineFacade executionEngineFacade =
|
---|
353 | new ExecutionEngineFacade();
|
---|
354 |
|
---|
355 | ResponseObject<SerializedJobResult> response =
|
---|
356 | executionEngineFacade.GetLastSerializedResult(
|
---|
357 | new Guid("56ce20bc-067b-424d-a7df-67aaace7c850"), false);
|
---|
358 |
|
---|
359 | IStorable restoredJob =
|
---|
360 | PersistenceManager.RestoreFromGZip(response.Obj.SerializedJobResultData);
|
---|
361 | }
|
---|
362 |
|
---|
363 | private void TestLINQImplementation() {
|
---|
364 | ClientDao clientDao = new ClientDao();
|
---|
365 | ClientInfo info = new ClientInfo();
|
---|
366 | info.Id = Guid.NewGuid();
|
---|
367 | info.FreeMemory = 1000;
|
---|
368 | info.Login = DateTime.Now;
|
---|
369 | info.Memory = 1000;
|
---|
370 | info.Name = "jackie";
|
---|
371 | info.NrOfCores = 3;
|
---|
372 | info.NrOfFreeCores = 2;
|
---|
373 | info.CpuSpeedPerCore = 2500;
|
---|
374 | info.State = State.idle;
|
---|
375 | info = clientDao.Insert(info);
|
---|
376 |
|
---|
377 | }
|
---|
378 |
|
---|
379 | public override void Run() {
|
---|
380 | //TestClientGroupAdapter();
|
---|
381 | //InsertTestClientGroups();
|
---|
382 | //TestJobStreaming();
|
---|
383 | //TestJobResultStreaming();
|
---|
384 | //TestJobResultDeserialization();
|
---|
385 |
|
---|
386 | TestLINQImplementation();
|
---|
387 |
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | }
|
---|
392 | }
|
---|