[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;
|
---|
[1377] | 29 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[826] | 30 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 31 | using System.Diagnostics;
|
---|
[1377] | 32 | using HeuristicLab.DataAccess.Interfaces;
|
---|
[826] | 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 {
|
---|
[1468] | 39 | /* private void TestClientAdapter() {
|
---|
[826] | 40 | IClientAdapter clientAdapter =
|
---|
| 41 | ServiceLocator.GetClientAdapter();
|
---|
| 42 |
|
---|
| 43 | ClientInfo client = new ClientInfo();
|
---|
[845] | 44 | client.Login = DateTime.Now;
|
---|
[995] | 45 | clientAdapter.Update(client);
|
---|
[826] | 46 |
|
---|
[905] | 47 | ClientInfo clientRead =
|
---|
[1449] | 48 | clientAdapter.GetById(client.Id);
|
---|
[826] | 49 | Debug.Assert(
|
---|
| 50 | clientRead != null &&
|
---|
[1449] | 51 | client.Id == clientRead.Id);
|
---|
[826] | 52 |
|
---|
| 53 | client.CpuSpeedPerCore = 2000;
|
---|
[995] | 54 | clientAdapter.Update(client);
|
---|
[826] | 55 | clientRead =
|
---|
[1449] | 56 | clientAdapter.GetById(client.Id);
|
---|
[826] | 57 | Debug.Assert(
|
---|
| 58 | clientRead != null &&
|
---|
[1449] | 59 | client.Id == clientRead.Id &&
|
---|
[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);
|
---|
[1515] | 70 | } */
|
---|
[905] | 71 |
|
---|
[965] | 72 | private void TestClientGroupAdapter() {
|
---|
[1515] | 73 | ISessionFactory factory =
|
---|
| 74 | ServiceLocator.GetSessionFactory();
|
---|
[965] | 75 |
|
---|
[1515] | 76 | ISession session =
|
---|
| 77 | factory.GetSessionForCurrentThread();
|
---|
[965] | 78 |
|
---|
[1515] | 79 | ITransaction trans = null;
|
---|
[965] | 80 |
|
---|
[1515] | 81 | try {
|
---|
| 82 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 83 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
[965] | 84 |
|
---|
[1515] | 85 | trans =
|
---|
| 86 | session.BeginTransaction();
|
---|
[965] | 87 |
|
---|
[1515] | 88 | ClientInfo client =
|
---|
| 89 | new ClientInfo();
|
---|
| 90 | client.Name = "Stefan";
|
---|
| 91 | client.Login = DateTime.Now;
|
---|
[965] | 92 |
|
---|
[1515] | 93 | ClientInfo client2 =
|
---|
| 94 | new ClientInfo();
|
---|
| 95 | client2.Name = "Martin";
|
---|
| 96 | client2.Login = DateTime.Now;
|
---|
[965] | 97 |
|
---|
[1515] | 98 | ClientInfo client3 =
|
---|
| 99 | new ClientInfo();
|
---|
| 100 | client3.Name = "Heinz";
|
---|
| 101 | client3.Login = DateTime.Now;
|
---|
[965] | 102 |
|
---|
[1515] | 103 | ClientGroup group =
|
---|
| 104 | new ClientGroup();
|
---|
[965] | 105 |
|
---|
[1515] | 106 | ClientGroup subGroup =
|
---|
| 107 | new ClientGroup();
|
---|
| 108 | subGroup.Resources.Add(client);
|
---|
[965] | 109 |
|
---|
[1515] | 110 | group.Resources.Add(client3);
|
---|
| 111 | group.Resources.Add(client2);
|
---|
| 112 | group.Resources.Add(subGroup);
|
---|
[965] | 113 |
|
---|
[1515] | 114 | clientGroupAdapter.Update(group);
|
---|
[965] | 115 |
|
---|
[1515] | 116 | ClientGroup read =
|
---|
| 117 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 118 |
|
---|
[1515] | 119 | ICollection<ClientGroup> clientGroups =
|
---|
| 120 | clientGroupAdapter.GetAll();
|
---|
[965] | 121 |
|
---|
[1515] | 122 | IClientAdapter clientAdapter =
|
---|
| 123 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[965] | 124 |
|
---|
[1515] | 125 | clientAdapter.Delete(client3);
|
---|
[965] | 126 |
|
---|
[1515] | 127 | read =
|
---|
| 128 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 129 |
|
---|
[1515] | 130 | clientGroupAdapter.Delete(subGroup);
|
---|
[965] | 131 |
|
---|
[1515] | 132 | read =
|
---|
| 133 | clientGroupAdapter.GetById(group.Id);
|
---|
| 134 |
|
---|
| 135 | clientGroups =
|
---|
| 136 | clientGroupAdapter.GetAll();
|
---|
| 137 |
|
---|
| 138 | clientGroupAdapter.Delete(group);
|
---|
| 139 |
|
---|
| 140 | clientGroups =
|
---|
| 141 | clientGroupAdapter.GetAll();
|
---|
| 142 |
|
---|
| 143 | clientAdapter.Delete(client);
|
---|
| 144 | clientAdapter.Delete(client2);
|
---|
| 145 | }
|
---|
| 146 | finally {
|
---|
| 147 | if (trans != null)
|
---|
| 148 | trans.Rollback();
|
---|
| 149 |
|
---|
| 150 | session.EndSession();
|
---|
| 151 | }
|
---|
[965] | 152 | }
|
---|
| 153 |
|
---|
[1656] | 154 | private void InsertTestClientGroups() {
|
---|
| 155 | ISessionFactory factory =
|
---|
| 156 | ServiceLocator.GetSessionFactory();
|
---|
| 157 |
|
---|
| 158 | ISession session =
|
---|
| 159 | factory.GetSessionForCurrentThread();
|
---|
| 160 |
|
---|
| 161 | ITransaction trans = null;
|
---|
| 162 |
|
---|
| 163 | try {
|
---|
| 164 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 165 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
| 166 |
|
---|
| 167 | trans =
|
---|
| 168 | session.BeginTransaction();
|
---|
| 169 |
|
---|
| 170 | ClientInfo client =
|
---|
| 171 | new ClientInfo();
|
---|
| 172 | client.Name = "Stefan";
|
---|
| 173 | client.Login = DateTime.Now;
|
---|
| 174 |
|
---|
| 175 | ClientInfo client2 =
|
---|
| 176 | new ClientInfo();
|
---|
| 177 | client2.Name = "Martin";
|
---|
| 178 | client2.Login = DateTime.Now;
|
---|
| 179 |
|
---|
| 180 | ClientGroup group =
|
---|
| 181 | new ClientGroup();
|
---|
| 182 | group.Name = "Gruppe1";
|
---|
| 183 |
|
---|
| 184 | ClientGroup subGroup =
|
---|
| 185 | new ClientGroup();
|
---|
| 186 | subGroup.Name = "Untergruppe1";
|
---|
| 187 | subGroup.Resources.Add(client);
|
---|
| 188 |
|
---|
| 189 | group.Resources.Add(client2);
|
---|
| 190 | group.Resources.Add(subGroup);
|
---|
| 191 |
|
---|
| 192 | clientGroupAdapter.Update(group);
|
---|
| 193 |
|
---|
| 194 | trans.Commit();
|
---|
| 195 | }
|
---|
| 196 | finally {
|
---|
| 197 | session.EndSession();
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[1515] | 201 | /* private void TestJobAdapter() {
|
---|
[1025] | 202 | IJobAdapter jobAdapter =
|
---|
| 203 | ServiceLocator.GetJobAdapter();
|
---|
| 204 | IClientAdapter clientAdapter =
|
---|
| 205 | ServiceLocator.GetClientAdapter();
|
---|
[971] | 206 |
|
---|
| 207 | Job job = new Job();
|
---|
| 208 |
|
---|
| 209 | ClientInfo client = new ClientInfo();
|
---|
| 210 | client.Login = DateTime.Now;
|
---|
| 211 |
|
---|
| 212 | job.Client = client;
|
---|
[995] | 213 | jobAdapter.Update(job);
|
---|
[971] | 214 |
|
---|
[995] | 215 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
[971] | 216 |
|
---|
[995] | 217 | jobAdapter.Delete(job);
|
---|
[1025] | 218 | clientAdapter.Delete(client);
|
---|
[971] | 219 |
|
---|
[995] | 220 | jobs = jobAdapter.GetAll();
|
---|
[971] | 221 | }
|
---|
| 222 |
|
---|
[1005] | 223 | private void TestJobResultsAdapter() {
|
---|
| 224 | Job job = new Job();
|
---|
| 225 |
|
---|
| 226 | ClientInfo client = new ClientInfo();
|
---|
| 227 | client.Login = DateTime.Now;
|
---|
| 228 |
|
---|
| 229 | job.Client = client;
|
---|
| 230 |
|
---|
| 231 | IJobResultsAdapter resultsAdapter =
|
---|
| 232 | ServiceLocator.GetJobResultsAdapter();
|
---|
| 233 |
|
---|
| 234 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
| 235 |
|
---|
| 236 | JobResult result = new JobResult();
|
---|
| 237 | result.Client = client;
|
---|
| 238 | result.Job = job;
|
---|
| 239 | result.Result = resultByte;
|
---|
| 240 |
|
---|
| 241 | resultsAdapter.Update(result);
|
---|
| 242 |
|
---|
| 243 | JobResult read =
|
---|
| 244 | resultsAdapter.GetById(result.Id);
|
---|
| 245 | Debug.Assert(
|
---|
| 246 | read.Id == result.Id &&
|
---|
| 247 | result.Client.Id == read.Client.Id &&
|
---|
| 248 | result.Job.Id == read.Job.Id &&
|
---|
| 249 | result.Result == result.Result);
|
---|
| 250 |
|
---|
| 251 | int count =
|
---|
| 252 | resultsAdapter.GetAll().Count;
|
---|
| 253 |
|
---|
| 254 | resultsAdapter.Delete(result);
|
---|
| 255 |
|
---|
| 256 | ICollection<JobResult> allResults =
|
---|
| 257 | resultsAdapter.GetAll();
|
---|
| 258 |
|
---|
| 259 | Debug.Assert(allResults.Count == count - 1);
|
---|
[1025] | 260 |
|
---|
| 261 | IJobAdapter jboAdapter =
|
---|
| 262 | ServiceLocator.GetJobAdapter();
|
---|
| 263 | jboAdapter.Delete(job);
|
---|
| 264 | IClientAdapter clientAdapter =
|
---|
| 265 | ServiceLocator.GetClientAdapter();
|
---|
| 266 | clientAdapter.Delete(client);
|
---|
[1468] | 267 | } */
|
---|
[1005] | 268 |
|
---|
[1515] | 269 | private void TestTransaction() {
|
---|
[1468] | 270 | ISessionFactory factory =
|
---|
| 271 | ServiceLocator.GetSessionFactory();
|
---|
[995] | 272 |
|
---|
[1515] | 273 | ISession session =
|
---|
[1468] | 274 | factory.GetSessionForCurrentThread();
|
---|
[995] | 275 |
|
---|
[1515] | 276 | IClientAdapter clientAdapter =
|
---|
[1468] | 277 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[1005] | 278 |
|
---|
[1515] | 279 | ITransaction trans =
|
---|
| 280 | session.BeginTransaction();
|
---|
[1468] | 281 |
|
---|
| 282 | ClientInfo client = new ClientInfo();
|
---|
| 283 | client.Login = DateTime.Now;
|
---|
| 284 | clientAdapter.Update(client);
|
---|
| 285 |
|
---|
| 286 | trans.Rollback();
|
---|
| 287 |
|
---|
| 288 | session.EndSession();
|
---|
[1515] | 289 | }
|
---|
| 290 |
|
---|
| 291 | public override void Run() {
|
---|
| 292 | TestClientGroupAdapter();
|
---|
[1656] | 293 | //InsertTestClientGroups();
|
---|
[1468] | 294 | }
|
---|
[826] | 295 | }
|
---|
| 296 | }
|
---|