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 |
|
---|
34 | namespace HeuristicLab.Hive.Server {
|
---|
35 | [ClassInfo(Name = "Hive DB Test App",
|
---|
36 | Description = "Test Application for the Hive DataAccess Layer",
|
---|
37 | AutoRestart = true)]
|
---|
38 | class HiveDbTestApplication : ApplicationBase {
|
---|
39 | private void TestClientAdapter() {
|
---|
40 | IClientAdapter clientAdapter =
|
---|
41 | ServiceLocator.GetClientAdapter();
|
---|
42 |
|
---|
43 | ClientInfo client = new ClientInfo();
|
---|
44 | client.Login = DateTime.Now;
|
---|
45 | client.ClientId = Guid.NewGuid();
|
---|
46 | clientAdapter.Update(client);
|
---|
47 |
|
---|
48 | ClientInfo clientRead =
|
---|
49 | clientAdapter.GetById(client.ClientId);
|
---|
50 | Debug.Assert(
|
---|
51 | clientRead != null &&
|
---|
52 | client.ClientId == clientRead.ClientId);
|
---|
53 |
|
---|
54 | client.CpuSpeedPerCore = 2000;
|
---|
55 | clientAdapter.Update(client);
|
---|
56 | clientRead =
|
---|
57 | clientAdapter.GetById(client.ClientId);
|
---|
58 | Debug.Assert(
|
---|
59 | clientRead != null &&
|
---|
60 | client.ClientId == clientRead.ClientId &&
|
---|
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 | IClientGroupAdapter clientGroupAdapter =
|
---|
75 | ServiceLocator.GetClientGroupAdapter();
|
---|
76 |
|
---|
77 | ClientInfo client =
|
---|
78 | new ClientInfo();
|
---|
79 | client.Name = "Stefan";
|
---|
80 | client.ClientId = Guid.NewGuid();
|
---|
81 | client.Login = DateTime.Now;
|
---|
82 |
|
---|
83 | ClientInfo client2 =
|
---|
84 | new ClientInfo();
|
---|
85 | client2.Name = "Martin";
|
---|
86 | client2.ClientId = Guid.NewGuid();
|
---|
87 | client2.Login = DateTime.Now;
|
---|
88 |
|
---|
89 | ClientInfo client3 =
|
---|
90 | new ClientInfo();
|
---|
91 | client3.Name = "Heinz";
|
---|
92 | client3.ClientId = Guid.NewGuid();
|
---|
93 | client3.Login = DateTime.Now;
|
---|
94 |
|
---|
95 | ClientGroup group =
|
---|
96 | new ClientGroup();
|
---|
97 |
|
---|
98 | ClientGroup subGroup =
|
---|
99 | new ClientGroup();
|
---|
100 | subGroup.Resources.Add(client);
|
---|
101 |
|
---|
102 | group.Resources.Add(client3);
|
---|
103 | group.Resources.Add(client2);
|
---|
104 | group.Resources.Add(subGroup);
|
---|
105 |
|
---|
106 | clientGroupAdapter.Update(group);
|
---|
107 |
|
---|
108 | ClientGroup read =
|
---|
109 | clientGroupAdapter.GetById(group.Id);
|
---|
110 |
|
---|
111 | ICollection<ClientGroup> clientGroups =
|
---|
112 | clientGroupAdapter.GetAll();
|
---|
113 |
|
---|
114 | IClientAdapter clientAdapter =
|
---|
115 | ServiceLocator.GetClientAdapter();
|
---|
116 |
|
---|
117 | clientAdapter.Delete(client3);
|
---|
118 |
|
---|
119 | read =
|
---|
120 | clientGroupAdapter.GetById(group.Id);
|
---|
121 |
|
---|
122 | clientGroupAdapter.Delete(subGroup);
|
---|
123 |
|
---|
124 | read =
|
---|
125 | clientGroupAdapter.GetById(group.Id);
|
---|
126 |
|
---|
127 | clientGroups =
|
---|
128 | clientGroupAdapter.GetAll();
|
---|
129 |
|
---|
130 | clientGroupAdapter.Delete(group);
|
---|
131 |
|
---|
132 | clientGroups =
|
---|
133 | clientGroupAdapter.GetAll();
|
---|
134 |
|
---|
135 | clientAdapter.Delete(client);
|
---|
136 | clientAdapter.Delete(client2);
|
---|
137 | }
|
---|
138 |
|
---|
139 | private void TestJobAdapter() {
|
---|
140 | IJobAdapter jobAdapter =
|
---|
141 | ServiceLocator.GetJobAdapter();
|
---|
142 | IClientAdapter clientAdapter =
|
---|
143 | ServiceLocator.GetClientAdapter();
|
---|
144 |
|
---|
145 | Job job = new Job();
|
---|
146 |
|
---|
147 | ClientInfo client = new ClientInfo();
|
---|
148 | client.ClientId = Guid.NewGuid();
|
---|
149 | client.Login = DateTime.Now;
|
---|
150 |
|
---|
151 | job.Client = client;
|
---|
152 | jobAdapter.Update(job);
|
---|
153 |
|
---|
154 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
155 |
|
---|
156 | jobAdapter.Delete(job);
|
---|
157 | clientAdapter.Delete(client);
|
---|
158 |
|
---|
159 | jobs = jobAdapter.GetAll();
|
---|
160 | }
|
---|
161 |
|
---|
162 | private void TestJobResultsAdapter() {
|
---|
163 | Job job = new Job();
|
---|
164 |
|
---|
165 | ClientInfo client = new ClientInfo();
|
---|
166 | client.ClientId = Guid.NewGuid();
|
---|
167 | client.Login = DateTime.Now;
|
---|
168 |
|
---|
169 | job.Client = client;
|
---|
170 |
|
---|
171 | IJobResultsAdapter resultsAdapter =
|
---|
172 | ServiceLocator.GetJobResultsAdapter();
|
---|
173 |
|
---|
174 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
175 |
|
---|
176 | JobResult result = new JobResult();
|
---|
177 | result.Client = client;
|
---|
178 | result.Job = job;
|
---|
179 | result.Result = resultByte;
|
---|
180 |
|
---|
181 | resultsAdapter.Update(result);
|
---|
182 |
|
---|
183 | JobResult read =
|
---|
184 | resultsAdapter.GetById(result.Id);
|
---|
185 | Debug.Assert(
|
---|
186 | read.Id == result.Id &&
|
---|
187 | result.Client.Id == read.Client.Id &&
|
---|
188 | result.Job.Id == read.Job.Id &&
|
---|
189 | result.Result == result.Result);
|
---|
190 |
|
---|
191 | int count =
|
---|
192 | resultsAdapter.GetAll().Count;
|
---|
193 |
|
---|
194 | resultsAdapter.Delete(result);
|
---|
195 |
|
---|
196 | ICollection<JobResult> allResults =
|
---|
197 | resultsAdapter.GetAll();
|
---|
198 |
|
---|
199 | Debug.Assert(allResults.Count == count - 1);
|
---|
200 |
|
---|
201 | IJobAdapter jboAdapter =
|
---|
202 | ServiceLocator.GetJobAdapter();
|
---|
203 | jboAdapter.Delete(job);
|
---|
204 | IClientAdapter clientAdapter =
|
---|
205 | ServiceLocator.GetClientAdapter();
|
---|
206 | clientAdapter.Delete(client);
|
---|
207 | }
|
---|
208 |
|
---|
209 | public override void Run() {
|
---|
210 | IDBSynchronizer transactionManager =
|
---|
211 | ServiceLocator.GetDBSynchronizer();
|
---|
212 |
|
---|
213 | TestClientAdapter();
|
---|
214 | transactionManager.UpdateDB();
|
---|
215 |
|
---|
216 | TestClientGroupAdapter();
|
---|
217 | transactionManager.UpdateDB();
|
---|
218 |
|
---|
219 | TestJobAdapter();
|
---|
220 | transactionManager.UpdateDB();
|
---|
221 |
|
---|
222 | TestJobResultsAdapter();
|
---|
223 | transactionManager.UpdateDB();
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|