[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);
|
---|
| 70 | }
|
---|
[905] | 71 |
|
---|
[965] | 72 | private void TestClientGroupAdapter() {
|
---|
| 73 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 74 | ServiceLocator.GetClientGroupAdapter();
|
---|
| 75 |
|
---|
| 76 | ClientInfo client =
|
---|
| 77 | new ClientInfo();
|
---|
| 78 | client.Name = "Stefan";
|
---|
[971] | 79 | client.Login = DateTime.Now;
|
---|
[965] | 80 |
|
---|
| 81 | ClientInfo client2 =
|
---|
| 82 | new ClientInfo();
|
---|
| 83 | client2.Name = "Martin";
|
---|
[971] | 84 | client2.Login = DateTime.Now;
|
---|
[965] | 85 |
|
---|
| 86 | ClientInfo client3 =
|
---|
| 87 | new ClientInfo();
|
---|
| 88 | client3.Name = "Heinz";
|
---|
[971] | 89 | client3.Login = DateTime.Now;
|
---|
[965] | 90 |
|
---|
| 91 | ClientGroup group =
|
---|
| 92 | new ClientGroup();
|
---|
| 93 |
|
---|
| 94 | ClientGroup subGroup =
|
---|
| 95 | new ClientGroup();
|
---|
| 96 | subGroup.Resources.Add(client);
|
---|
| 97 |
|
---|
| 98 | group.Resources.Add(client3);
|
---|
| 99 | group.Resources.Add(client2);
|
---|
| 100 | group.Resources.Add(subGroup);
|
---|
| 101 |
|
---|
[995] | 102 | clientGroupAdapter.Update(group);
|
---|
[965] | 103 |
|
---|
| 104 | ClientGroup read =
|
---|
[995] | 105 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 106 |
|
---|
| 107 | ICollection<ClientGroup> clientGroups =
|
---|
[995] | 108 | clientGroupAdapter.GetAll();
|
---|
[965] | 109 |
|
---|
| 110 | IClientAdapter clientAdapter =
|
---|
| 111 | ServiceLocator.GetClientAdapter();
|
---|
| 112 |
|
---|
[995] | 113 | clientAdapter.Delete(client3);
|
---|
[965] | 114 |
|
---|
| 115 | read =
|
---|
[995] | 116 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 117 |
|
---|
[995] | 118 | clientGroupAdapter.Delete(subGroup);
|
---|
[965] | 119 |
|
---|
| 120 | read =
|
---|
[995] | 121 | clientGroupAdapter.GetById(group.Id);
|
---|
[965] | 122 |
|
---|
| 123 | clientGroups =
|
---|
[995] | 124 | clientGroupAdapter.GetAll();
|
---|
[965] | 125 |
|
---|
[995] | 126 | clientGroupAdapter.Delete(group);
|
---|
[965] | 127 |
|
---|
| 128 | clientGroups =
|
---|
[995] | 129 | clientGroupAdapter.GetAll();
|
---|
[965] | 130 |
|
---|
[995] | 131 | clientAdapter.Delete(client);
|
---|
| 132 | clientAdapter.Delete(client2);
|
---|
[965] | 133 | }
|
---|
| 134 |
|
---|
[971] | 135 | private void TestJobAdapter() {
|
---|
[1025] | 136 | IJobAdapter jobAdapter =
|
---|
| 137 | ServiceLocator.GetJobAdapter();
|
---|
| 138 | IClientAdapter clientAdapter =
|
---|
| 139 | ServiceLocator.GetClientAdapter();
|
---|
[971] | 140 |
|
---|
| 141 | Job job = new Job();
|
---|
| 142 |
|
---|
| 143 | ClientInfo client = new ClientInfo();
|
---|
| 144 | client.Login = DateTime.Now;
|
---|
| 145 |
|
---|
| 146 | job.Client = client;
|
---|
[995] | 147 | jobAdapter.Update(job);
|
---|
[971] | 148 |
|
---|
[995] | 149 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
[971] | 150 |
|
---|
[995] | 151 | jobAdapter.Delete(job);
|
---|
[1025] | 152 | clientAdapter.Delete(client);
|
---|
[971] | 153 |
|
---|
[995] | 154 | jobs = jobAdapter.GetAll();
|
---|
[971] | 155 | }
|
---|
| 156 |
|
---|
[1005] | 157 | private void TestJobResultsAdapter() {
|
---|
| 158 | Job job = new Job();
|
---|
| 159 |
|
---|
| 160 | ClientInfo client = new ClientInfo();
|
---|
| 161 | client.Login = DateTime.Now;
|
---|
| 162 |
|
---|
| 163 | job.Client = client;
|
---|
| 164 |
|
---|
| 165 | IJobResultsAdapter resultsAdapter =
|
---|
| 166 | ServiceLocator.GetJobResultsAdapter();
|
---|
| 167 |
|
---|
| 168 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
| 169 |
|
---|
| 170 | JobResult result = new JobResult();
|
---|
| 171 | result.Client = client;
|
---|
| 172 | result.Job = job;
|
---|
| 173 | result.Result = resultByte;
|
---|
| 174 |
|
---|
| 175 | resultsAdapter.Update(result);
|
---|
| 176 |
|
---|
| 177 | JobResult read =
|
---|
| 178 | resultsAdapter.GetById(result.Id);
|
---|
| 179 | Debug.Assert(
|
---|
| 180 | read.Id == result.Id &&
|
---|
| 181 | result.Client.Id == read.Client.Id &&
|
---|
| 182 | result.Job.Id == read.Job.Id &&
|
---|
| 183 | result.Result == result.Result);
|
---|
| 184 |
|
---|
| 185 | int count =
|
---|
| 186 | resultsAdapter.GetAll().Count;
|
---|
| 187 |
|
---|
| 188 | resultsAdapter.Delete(result);
|
---|
| 189 |
|
---|
| 190 | ICollection<JobResult> allResults =
|
---|
| 191 | resultsAdapter.GetAll();
|
---|
| 192 |
|
---|
| 193 | Debug.Assert(allResults.Count == count - 1);
|
---|
[1025] | 194 |
|
---|
| 195 | IJobAdapter jboAdapter =
|
---|
| 196 | ServiceLocator.GetJobAdapter();
|
---|
| 197 | jboAdapter.Delete(job);
|
---|
| 198 | IClientAdapter clientAdapter =
|
---|
| 199 | ServiceLocator.GetClientAdapter();
|
---|
| 200 | clientAdapter.Delete(client);
|
---|
[1468] | 201 | } */
|
---|
[1005] | 202 |
|
---|
[905] | 203 | public override void Run() {
|
---|
[1468] | 204 | ISessionFactory factory =
|
---|
| 205 | ServiceLocator.GetSessionFactory();
|
---|
[995] | 206 |
|
---|
[1468] | 207 | ISession session =
|
---|
| 208 | factory.GetSessionForCurrentThread();
|
---|
[995] | 209 |
|
---|
[1468] | 210 | IClientAdapter clientAdapter =
|
---|
| 211 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[1005] | 212 |
|
---|
[1468] | 213 | ITransaction trans =
|
---|
| 214 | session.BeginTransaction();
|
---|
| 215 |
|
---|
| 216 | ClientInfo client = new ClientInfo();
|
---|
| 217 | client.Login = DateTime.Now;
|
---|
| 218 | clientAdapter.Update(client);
|
---|
| 219 |
|
---|
| 220 | trans.Rollback();
|
---|
| 221 |
|
---|
| 222 | session.EndSession();
|
---|
| 223 | }
|
---|
[826] | 224 | }
|
---|
| 225 | }
|
---|