Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/DbTestApp.cs @ 1463

Last change on this file since 1463 was 1449, checked in by svonolfe, 16 years ago

Refactored DAL (now using GUIDs as IDs instead of longs) (#527)

File size: 6.0 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.PluginInfrastructure;
26using System.Net;
27using HeuristicLab.Hive.Contracts;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Server.DataAccess;
30using HeuristicLab.Hive.Contracts.BusinessObjects;
31using System.Diagnostics;
32using HeuristicLab.DataAccess.Interfaces;
33
34namespace 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      IClientGroupAdapter clientGroupAdapter =
74       ServiceLocator.GetClientGroupAdapter();
75
76      ClientInfo client =
77        new ClientInfo();
78      client.Name = "Stefan";
79      client.Login = DateTime.Now;
80
81      ClientInfo client2 =
82        new ClientInfo();
83      client2.Name = "Martin";
84      client2.Login = DateTime.Now;
85
86      ClientInfo client3 =
87        new ClientInfo();
88      client3.Name = "Heinz";
89      client3.Login = DateTime.Now;
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
102      clientGroupAdapter.Update(group);
103
104      ClientGroup read =
105        clientGroupAdapter.GetById(group.Id);
106
107      ICollection<ClientGroup> clientGroups =
108        clientGroupAdapter.GetAll();
109
110      IClientAdapter clientAdapter =
111        ServiceLocator.GetClientAdapter();
112
113      clientAdapter.Delete(client3);
114
115      read =
116         clientGroupAdapter.GetById(group.Id);
117
118      clientGroupAdapter.Delete(subGroup);
119
120      read =
121         clientGroupAdapter.GetById(group.Id);
122
123      clientGroups =
124        clientGroupAdapter.GetAll();
125
126      clientGroupAdapter.Delete(group);
127
128      clientGroups =
129        clientGroupAdapter.GetAll();
130
131      clientAdapter.Delete(client);
132      clientAdapter.Delete(client2);
133    }
134
135    private void TestJobAdapter() {
136      IJobAdapter jobAdapter =
137        ServiceLocator.GetJobAdapter();
138      IClientAdapter clientAdapter =
139        ServiceLocator.GetClientAdapter();
140
141      Job job = new Job();
142
143      ClientInfo client = new ClientInfo();
144      client.Login = DateTime.Now;
145
146      job.Client = client;
147      jobAdapter.Update(job);
148
149      ICollection<Job> jobs = jobAdapter.GetAll();
150
151      jobAdapter.Delete(job);
152      clientAdapter.Delete(client);
153
154      jobs = jobAdapter.GetAll();
155    }
156
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);
194
195      IJobAdapter jboAdapter =
196        ServiceLocator.GetJobAdapter();
197      jboAdapter.Delete(job);
198      IClientAdapter clientAdapter =
199        ServiceLocator.GetClientAdapter();
200      clientAdapter.Delete(client);
201    }
202
203    public override void Run() {
204      IDBSynchronizer transactionManager =
205        ServiceLocator.GetDBSynchronizer();
206     
207      TestClientAdapter();
208      transactionManager.UpdateDB();
209
210      TestClientGroupAdapter();
211      transactionManager.UpdateDB();   
212
213      TestJobAdapter();
214      transactionManager.UpdateDB(); 
215
216      TestJobResultsAdapter();
217      transactionManager.UpdateDB();     
218    }
219  }
220}
Note: See TracBrowser for help on using the repository browser.