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 | clientAdapter.Update(client);
|
---|
46 |
|
---|
47 | ClientInfo clientRead =
|
---|
48 | clientAdapter.GetById(client.Id);
|
---|
49 | Debug.Assert(
|
---|
50 | clientRead != null &&
|
---|
51 | client.Id == clientRead.Id);
|
---|
52 |
|
---|
53 | client.CpuSpeedPerCore = 2000;
|
---|
54 | clientAdapter.Update(client);
|
---|
55 | clientRead =
|
---|
56 | clientAdapter.GetById(client.Id);
|
---|
57 | Debug.Assert(
|
---|
58 | clientRead != null &&
|
---|
59 | client.Id == clientRead.Id &&
|
---|
60 | clientRead.CpuSpeedPerCore == 2000);
|
---|
61 |
|
---|
62 | ICollection<ClientInfo> clients =
|
---|
63 | clientAdapter.GetAll();
|
---|
64 | int count = clients.Count;
|
---|
65 |
|
---|
66 | clientAdapter.Delete(client);
|
---|
67 |
|
---|
68 | clients = clientAdapter.GetAll();
|
---|
69 | Debug.Assert(count - 1 == clients.Count);
|
---|
70 | } */
|
---|
71 |
|
---|
72 | private void TestClientGroupAdapter() {
|
---|
73 | ISessionFactory factory =
|
---|
74 | ServiceLocator.GetSessionFactory();
|
---|
75 |
|
---|
76 | ISession session =
|
---|
77 | factory.GetSessionForCurrentThread();
|
---|
78 |
|
---|
79 | ITransaction trans = null;
|
---|
80 |
|
---|
81 | try {
|
---|
82 | IClientGroupAdapter clientGroupAdapter =
|
---|
83 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
84 |
|
---|
85 | trans =
|
---|
86 | session.BeginTransaction();
|
---|
87 |
|
---|
88 | ClientInfo client =
|
---|
89 | new ClientInfo();
|
---|
90 | client.Name = "Stefan";
|
---|
91 | client.Login = DateTime.Now;
|
---|
92 |
|
---|
93 | ClientInfo client2 =
|
---|
94 | new ClientInfo();
|
---|
95 | client2.Name = "Martin";
|
---|
96 | client2.Login = DateTime.Now;
|
---|
97 |
|
---|
98 | ClientInfo client3 =
|
---|
99 | new ClientInfo();
|
---|
100 | client3.Name = "Heinz";
|
---|
101 | client3.Login = DateTime.Now;
|
---|
102 |
|
---|
103 | ClientGroup group =
|
---|
104 | new ClientGroup();
|
---|
105 |
|
---|
106 | ClientGroup subGroup =
|
---|
107 | new ClientGroup();
|
---|
108 | subGroup.Resources.Add(client);
|
---|
109 |
|
---|
110 | group.Resources.Add(client3);
|
---|
111 | group.Resources.Add(client2);
|
---|
112 | group.Resources.Add(subGroup);
|
---|
113 |
|
---|
114 | clientGroupAdapter.Update(group);
|
---|
115 |
|
---|
116 | ClientGroup read =
|
---|
117 | clientGroupAdapter.GetById(group.Id);
|
---|
118 |
|
---|
119 | ICollection<ClientGroup> clientGroups =
|
---|
120 | clientGroupAdapter.GetAll();
|
---|
121 |
|
---|
122 | IClientAdapter clientAdapter =
|
---|
123 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
124 |
|
---|
125 | clientAdapter.Delete(client3);
|
---|
126 |
|
---|
127 | read =
|
---|
128 | clientGroupAdapter.GetById(group.Id);
|
---|
129 |
|
---|
130 | clientGroupAdapter.Delete(subGroup);
|
---|
131 |
|
---|
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 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | /* private void TestJobAdapter() {
|
---|
155 | IJobAdapter jobAdapter =
|
---|
156 | ServiceLocator.GetJobAdapter();
|
---|
157 | IClientAdapter clientAdapter =
|
---|
158 | ServiceLocator.GetClientAdapter();
|
---|
159 |
|
---|
160 | Job job = new Job();
|
---|
161 |
|
---|
162 | ClientInfo client = new ClientInfo();
|
---|
163 | client.Login = DateTime.Now;
|
---|
164 |
|
---|
165 | job.Client = client;
|
---|
166 | jobAdapter.Update(job);
|
---|
167 |
|
---|
168 | ICollection<Job> jobs = jobAdapter.GetAll();
|
---|
169 |
|
---|
170 | jobAdapter.Delete(job);
|
---|
171 | clientAdapter.Delete(client);
|
---|
172 |
|
---|
173 | jobs = jobAdapter.GetAll();
|
---|
174 | }
|
---|
175 |
|
---|
176 | private void TestJobResultsAdapter() {
|
---|
177 | Job job = new Job();
|
---|
178 |
|
---|
179 | ClientInfo client = new ClientInfo();
|
---|
180 | client.Login = DateTime.Now;
|
---|
181 |
|
---|
182 | job.Client = client;
|
---|
183 |
|
---|
184 | IJobResultsAdapter resultsAdapter =
|
---|
185 | ServiceLocator.GetJobResultsAdapter();
|
---|
186 |
|
---|
187 | byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
|
---|
188 |
|
---|
189 | JobResult result = new JobResult();
|
---|
190 | result.Client = client;
|
---|
191 | result.Job = job;
|
---|
192 | result.Result = resultByte;
|
---|
193 |
|
---|
194 | resultsAdapter.Update(result);
|
---|
195 |
|
---|
196 | JobResult read =
|
---|
197 | resultsAdapter.GetById(result.Id);
|
---|
198 | Debug.Assert(
|
---|
199 | read.Id == result.Id &&
|
---|
200 | result.Client.Id == read.Client.Id &&
|
---|
201 | result.Job.Id == read.Job.Id &&
|
---|
202 | result.Result == result.Result);
|
---|
203 |
|
---|
204 | int count =
|
---|
205 | resultsAdapter.GetAll().Count;
|
---|
206 |
|
---|
207 | resultsAdapter.Delete(result);
|
---|
208 |
|
---|
209 | ICollection<JobResult> allResults =
|
---|
210 | resultsAdapter.GetAll();
|
---|
211 |
|
---|
212 | Debug.Assert(allResults.Count == count - 1);
|
---|
213 |
|
---|
214 | IJobAdapter jboAdapter =
|
---|
215 | ServiceLocator.GetJobAdapter();
|
---|
216 | jboAdapter.Delete(job);
|
---|
217 | IClientAdapter clientAdapter =
|
---|
218 | ServiceLocator.GetClientAdapter();
|
---|
219 | clientAdapter.Delete(client);
|
---|
220 | } */
|
---|
221 |
|
---|
222 | private void TestTransaction() {
|
---|
223 | ISessionFactory factory =
|
---|
224 | ServiceLocator.GetSessionFactory();
|
---|
225 |
|
---|
226 | ISession session =
|
---|
227 | factory.GetSessionForCurrentThread();
|
---|
228 |
|
---|
229 | IClientAdapter clientAdapter =
|
---|
230 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
231 |
|
---|
232 | ITransaction trans =
|
---|
233 | session.BeginTransaction();
|
---|
234 |
|
---|
235 | ClientInfo client = new ClientInfo();
|
---|
236 | client.Login = DateTime.Now;
|
---|
237 | clientAdapter.Update(client);
|
---|
238 |
|
---|
239 | trans.Rollback();
|
---|
240 |
|
---|
241 | session.EndSession();
|
---|
242 | }
|
---|
243 |
|
---|
244 | public override void Run() {
|
---|
245 | TestClientGroupAdapter();
|
---|
246 | }
|
---|
247 | }
|
---|
248 | }
|
---|