[826] | 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.Core.InternalInterfaces.DataAccess;
|
---|
| 30 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 31 | using System.Diagnostics;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Hive.Server {
|
---|
| 34 | [ClassInfo(Name = "Hive DB Test App",
|
---|
| 35 | Description = "Test Application for the Hive DataAccess Layer",
|
---|
| 36 | AutoRestart = true)]
|
---|
| 37 | class HiveDbTestApplication : ApplicationBase {
|
---|
[905] | 38 | private void TestClientAdapter() {
|
---|
[826] | 39 | IClientAdapter clientAdapter =
|
---|
| 40 | ServiceLocator.GetClientAdapter();
|
---|
| 41 |
|
---|
| 42 | ClientInfo client = new ClientInfo();
|
---|
[845] | 43 | client.Login = DateTime.Now;
|
---|
[826] | 44 | client.ClientId = Guid.NewGuid();
|
---|
[995] | 45 | clientAdapter.Update(client);
|
---|
[826] | 46 |
|
---|
[905] | 47 | ClientInfo clientRead =
|
---|
[995] | 48 | clientAdapter.GetById(client.ClientId);
|
---|
[826] | 49 | Debug.Assert(
|
---|
| 50 | clientRead != null &&
|
---|
| 51 | client.ClientId == clientRead.ClientId);
|
---|
| 52 |
|
---|
| 53 | client.CpuSpeedPerCore = 2000;
|
---|
[995] | 54 | clientAdapter.Update(client);
|
---|
[826] | 55 | clientRead =
|
---|
[995] | 56 | clientAdapter.GetById(client.ClientId);
|
---|
[826] | 57 | Debug.Assert(
|
---|
| 58 | clientRead != null &&
|
---|
[905] | 59 | client.ClientId == clientRead.ClientId &&
|
---|
[826] | 60 | clientRead.CpuSpeedPerCore == 2000);
|
---|
| 61 |
|
---|
[995] | 62 | ICollection<ClientInfo> clients =
|
---|
| 63 | clientAdapter.GetAll();
|
---|
[826] | 64 | int count = clients.Count;
|
---|
| 65 |
|
---|
[995] | 66 | clientAdapter.Delete(client);
|
---|
[826] | 67 |
|
---|
[995] | 68 | clients = clientAdapter.GetAll();
|
---|
[826] | 69 | Debug.Assert(count - 1 == clients.Count);
|
---|
| 70 | }
|
---|
[905] | 71 |
|
---|
| 72 | private void TestUserAdapter() {
|
---|
| 73 | IUserAdapter userAdapter =
|
---|
| 74 | ServiceLocator.GetUserAdapter();
|
---|
| 75 |
|
---|
| 76 | User user = new User();
|
---|
[995] | 77 | user.Name = "TestDummy";
|
---|
[905] | 78 |
|
---|
[995] | 79 | userAdapter.Update(user);
|
---|
[905] | 80 |
|
---|
| 81 | User userRead =
|
---|
[995] | 82 | userAdapter.GetById(user.Id);
|
---|
[905] | 83 | Debug.Assert(
|
---|
| 84 | userRead != null &&
|
---|
[995] | 85 | user.Id == userRead.Id);
|
---|
[905] | 86 |
|
---|
| 87 | user.Password = "passme";
|
---|
[995] | 88 | userAdapter.Update(user);
|
---|
[905] | 89 | userRead =
|
---|
[995] | 90 | userAdapter.GetByName(user.Name);
|
---|
[905] | 91 | Debug.Assert(
|
---|
| 92 | userRead != null &&
|
---|
| 93 | userRead.Name == user.Name &&
|
---|
| 94 | userRead.Password == user.Password);
|
---|
| 95 |
|
---|
[995] | 96 | ICollection<User> users =
|
---|
| 97 | userAdapter.GetAll();
|
---|
[905] | 98 | int count = users.Count;
|
---|
| 99 |
|
---|
[995] | 100 | userAdapter.Delete(user);
|
---|
[905] | 101 |
|
---|
[995] | 102 | users = userAdapter.GetAll();
|
---|
[905] | 103 | Debug.Assert(count - 1 == users.Count);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[936] | 106 | private void TestUserGroupAdapter() {
|
---|
| 107 | IUserGroupAdapter userGroupAdapter =
|
---|
| 108 | ServiceLocator.GetUserGroupAdapter();
|
---|
| 109 |
|
---|
| 110 | User user =
|
---|
| 111 | new User();
|
---|
| 112 | user.Name = "Stefan";
|
---|
| 113 |
|
---|
| 114 | User user2 =
|
---|
| 115 | new User();
|
---|
| 116 | user2.Name = "Martin";
|
---|
| 117 |
|
---|
[939] | 118 | User user3 =
|
---|
| 119 | new User();
|
---|
| 120 | user3.Name = "Heinz";
|
---|
| 121 |
|
---|
[936] | 122 | UserGroup group =
|
---|
| 123 | new UserGroup();
|
---|
| 124 |
|
---|
| 125 | UserGroup subGroup =
|
---|
| 126 | new UserGroup();
|
---|
| 127 | subGroup.Members.Add(user);
|
---|
| 128 |
|
---|
[939] | 129 | group.Members.Add(user3);
|
---|
[936] | 130 | group.Members.Add(user2);
|
---|
| 131 | group.Members.Add(subGroup);
|
---|
| 132 |
|
---|
[995] | 133 | userGroupAdapter.Update(group);
|
---|
[936] | 134 |
|
---|
| 135 | UserGroup read =
|
---|
[995] | 136 | userGroupAdapter.GetById(group.Id);
|
---|
[936] | 137 |
|
---|
| 138 | ICollection<UserGroup> userGroups =
|
---|
[995] | 139 | userGroupAdapter.GetAll();
|
---|
[936] | 140 |
|
---|
[939] | 141 | IUserAdapter userAdapter =
|
---|
| 142 | ServiceLocator.GetUserAdapter();
|
---|
| 143 |
|
---|
[995] | 144 | userAdapter.Delete(user3);
|
---|
[939] | 145 |
|
---|
| 146 | read =
|
---|
[995] | 147 | userGroupAdapter.GetById(group.Id);
|
---|
[939] | 148 |
|
---|
[995] | 149 | userGroupAdapter.Delete(subGroup);
|
---|
[936] | 150 |
|
---|
[939] | 151 | read =
|
---|
[995] | 152 | userGroupAdapter.GetById(group.Id);
|
---|
[939] | 153 |
|
---|
[936] | 154 | userGroups =
|
---|
[995] | 155 | userGroupAdapter.GetAll();
|
---|
[936] | 156 |
|
---|
[995] | 157 | userGroupAdapter.Delete(group);
|
---|
[936] | 158 |
|
---|
| 159 | userGroups =
|
---|
[995] | 160 | userGroupAdapter.GetAll();
|
---|
[936] | 161 |
|
---|
[995] | 162 | userAdapter.Delete(user);
|
---|
| 163 | userAdapter.Delete(user2);
|
---|
[936] | 164 | }
|
---|
| 165 |
|
---|
[965] | 166 | private void TestClientGroupAdapter() {
|
---|
| 167 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 168 | ServiceLocator.GetClientGroupAdapter();
|
---|
| 169 |
|
---|
| 170 | ClientInfo client =
|
---|
| 171 | new ClientInfo();
|
---|
| 172 | client.Name = "Stefan";
|
---|
| 173 | client.ClientId = Guid.NewGuid();
|
---|
[971] | 174 | client.Login = DateTime.Now;
|
---|
[965] | 175 |
|
---|
| 176 | ClientInfo client2 =
|
---|
| 177 | new ClientInfo();
|
---|
| 178 | client2.Name = "Martin";
|
---|
| 179 | client2.ClientId = Guid.NewGuid();
|
---|
[971] | 180 | client2.Login = DateTime.Now;
|
---|
[965] | 181 |
|
---|
| 182 | ClientInfo client3 =
|
---|
| 183 | new ClientInfo();
|
---|
| 184 | client3.Name = "Heinz";
|
---|
| 185 | client3.ClientId = Guid.NewGuid();
|
---|
[971] | 186 | client3.Login = DateTime.Now;
|
---|
[965] | 187 |
|
---|
| 188 | ClientGroup group =
|
---|
| 189 | new ClientGroup();
|
---|
| 190 |
|
---|
| 191 | ClientGroup subGroup =
|
---|
| 192 | new ClientGroup();
|
---|
| 193 | subGroup.Resources.Add(client);
|
---|
| 194 |
|
---|
| 195 | group.Resources.Add(client3);
|
---|
| 196 | group.Resources.Add(client2);
|
---|
| 197 | group.Resources.Add(subGroup);
|
---|
| 198 |
|
---|
[995] | 199 | clientGroupAdapter.Update(group);
|
---|
[965] | 200 |
|
---|
| 201 | ClientGroup read =
|
---|
[995] | 202 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 203 |
|
---|
| 204 | ICollection<ClientGroup> clientGroups =
|
---|
[995] | 205 | clientGroupAdapter.GetAll();
|
---|
[965] | 206 |
|
---|
| 207 | IClientAdapter clientAdapter =
|
---|
| 208 | ServiceLocator.GetClientAdapter();
|
---|
| 209 |
|
---|
[995] | 210 | clientAdapter.Delete(client3);
|
---|
[965] | 211 |
|
---|
| 212 | read =
|
---|
[995] | 213 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 214 |
|
---|
[995] | 215 | clientGroupAdapter.Delete(subGroup);
|
---|
[965] | 216 |
|
---|
| 217 | read =
|
---|
[995] | 218 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 219 |
|
---|
| 220 | clientGroups =
|
---|
[995] | 221 | clientGroupAdapter.GetAll();
|
---|
[965] | 222 |
|
---|
[995] | 223 | clientGroupAdapter.Delete(group);
|
---|
[965] | 224 |
|
---|
| 225 | clientGroups =
|
---|
[995] | 226 | clientGroupAdapter.GetAll();
|
---|
[965] | 227 |
|
---|
[995] | 228 | clientAdapter.Delete(client);
|
---|
| 229 | clientAdapter.Delete(client2);
|
---|
[965] | 230 | }
|
---|
| 231 |
|
---|
[971] | 232 | private void TestJobAdapter() {
|
---|
[1025] | 233 | IJobAdapter jobAdapter =
|
---|
| 234 | ServiceLocator.GetJobAdapter();
|
---|
| 235 | IClientAdapter clientAdapter =
|
---|
| 236 | ServiceLocator.GetClientAdapter();
|
---|
[971] | 237 |
|
---|
| 238 | Job job = new Job();
|
---|
| 239 |
|
---|
| 240 | ClientInfo client = new ClientInfo();
|
---|
| 241 | client.ClientId = Guid.NewGuid();
|
---|
| 242 | client.Login = DateTime.Now;
|
---|
| 243 |
|
---|
| 244 | job.Client = client;
|
---|
[995] | 245 | jobAdapter.Update(job);
|
---|
[971] | 246 |
|
---|
[995] | 247 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
[971] | 248 |
|
---|
[995] | 249 | jobAdapter.Delete(job);
|
---|
[1025] | 250 | clientAdapter.Delete(client);
|
---|
[971] | 251 |
|
---|
[995] | 252 | jobs = jobAdapter.GetAll();
|
---|
[971] | 253 | }
|
---|
| 254 |
|
---|
[1005] | 255 | private void TestJobResultsAdapter() {
|
---|
| 256 | Job job = new Job();
|
---|
| 257 |
|
---|
| 258 | ClientInfo client = new ClientInfo();
|
---|
| 259 | client.ClientId = Guid.NewGuid();
|
---|
| 260 | client.Login = DateTime.Now;
|
---|
| 261 |
|
---|
| 262 | job.Client = client;
|
---|
| 263 |
|
---|
| 264 | IJobResultsAdapter resultsAdapter =
|
---|
| 265 | ServiceLocator.GetJobResultsAdapter();
|
---|
| 266 |
|
---|
| 267 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
| 268 |
|
---|
| 269 | JobResult result = new JobResult();
|
---|
| 270 | result.Client = client;
|
---|
| 271 | result.Job = job;
|
---|
| 272 | result.Result = resultByte;
|
---|
| 273 |
|
---|
| 274 | resultsAdapter.Update(result);
|
---|
| 275 |
|
---|
| 276 | JobResult read =
|
---|
| 277 | resultsAdapter.GetById(result.Id);
|
---|
| 278 | Debug.Assert(
|
---|
| 279 | read.Id == result.Id &&
|
---|
| 280 | result.Client.Id == read.Client.Id &&
|
---|
| 281 | result.Job.Id == read.Job.Id &&
|
---|
| 282 | result.Result == result.Result);
|
---|
| 283 |
|
---|
| 284 | int count =
|
---|
| 285 | resultsAdapter.GetAll().Count;
|
---|
| 286 |
|
---|
| 287 | resultsAdapter.Delete(result);
|
---|
| 288 |
|
---|
| 289 | ICollection<JobResult> allResults =
|
---|
| 290 | resultsAdapter.GetAll();
|
---|
| 291 |
|
---|
| 292 | Debug.Assert(allResults.Count == count - 1);
|
---|
[1025] | 293 |
|
---|
| 294 | IJobAdapter jboAdapter =
|
---|
| 295 | ServiceLocator.GetJobAdapter();
|
---|
| 296 | jboAdapter.Delete(job);
|
---|
| 297 | IClientAdapter clientAdapter =
|
---|
| 298 | ServiceLocator.GetClientAdapter();
|
---|
| 299 | clientAdapter.Delete(client);
|
---|
[1005] | 300 | }
|
---|
| 301 |
|
---|
[905] | 302 | public override void Run() {
|
---|
[995] | 303 | ITransactionManager transactionManager =
|
---|
| 304 | ServiceLocator.GetTransactionManager();
|
---|
| 305 |
|
---|
[905] | 306 | TestClientAdapter();
|
---|
[995] | 307 | transactionManager.UpdateDB();
|
---|
| 308 |
|
---|
[905] | 309 | TestUserAdapter();
|
---|
[995] | 310 | transactionManager.UpdateDB();
|
---|
| 311 |
|
---|
[936] | 312 | TestUserGroupAdapter();
|
---|
[995] | 313 | transactionManager.UpdateDB();
|
---|
| 314 |
|
---|
[965] | 315 | TestClientGroupAdapter();
|
---|
[1025] | 316 | transactionManager.UpdateDB();
|
---|
[995] | 317 |
|
---|
[971] | 318 | TestJobAdapter();
|
---|
[1005] | 319 | transactionManager.UpdateDB();
|
---|
| 320 |
|
---|
| 321 | TestJobResultsAdapter();
|
---|
[1025] | 322 | transactionManager.UpdateDB();
|
---|
[905] | 323 | }
|
---|
[826] | 324 | }
|
---|
| 325 | }
|
---|