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