- Timestamp:
- 06/19/10 09:17:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/DbTestApp.cs
r3220 r3931 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 21 20 22 #endregion 21 23 … … 37 39 using HeuristicLab.Hive.Server.LINQDataAccess; 38 40 using System.Transactions; 41 using System.Threading; 42 using HeuristicLab.Tracing; 39 43 40 44 namespace HeuristicLab.Hive.Server { 41 45 [Application("Hive DB Test App", "Test Application for the Hive DataAccess Layer")] 42 class HiveDbTestApplication : ApplicationBase {46 internal class HiveDbTestApplication : ApplicationBase { 43 47 /*private void TestJobStreaming() { 44 48 ISessionFactory factory = … … 111 115 } */ 112 116 113 ClientDao clientDao = new ClientDao(); 114 ClientGroupDao cgd = new ClientGroupDao(); 115 116 private void TestLINQImplementation() { 117 118 117 private ClientDao clientDao = new ClientDao(); 118 private ClientGroupDao cgd = new ClientGroupDao(); 119 120 private void TestLINQImplementation() { 119 121 ClientDto c1 = new ClientDto(); 120 122 c1.Id = Guid.NewGuid(); … … 143 145 c2 = clientDao.Insert(c2); 144 146 145 //ClientDto info2 = clientDao.FindById(info.Id);146 //Console.WriteLine(info2);147 148 147 ClientGroupDto tg = new ClientGroupDto(); 149 148 tg.Name = "TopGroup"; … … 174 173 175 174 List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients()); 176 175 177 176 cgd.RemoveRessourceFromClientGroup(sg.Id, tg.Id); 178 177 … … 181 180 clientDao.Delete(c1); 182 181 clientDao.Delete(c2); 183 184 182 } 185 183 … … 220 218 sg = cgd.Insert(sg); 221 219 cgd.AddRessourceToClientGroup(sg.Id, mg.Id); 222 populateMainGroup(sg, p-1); 223 } 224 225 226 } 227 220 populateMainGroup(sg, p - 1); 221 } 222 } 228 223 229 224 … … 235 230 //TestJobResultDeserialization(); 236 231 232 //if (ContextFactory.Context.DatabaseExists()) 233 // ContextFactory.Context.DeleteDatabase(); 234 //ContextFactory.Context.CreateDatabase(); 237 235 //TestLINQImplementation(); 236 TestLinqFileHandling(); 238 237 //StressTest(); 239 238 240 239 //SpeedTest(); 241 240 //TestJobBytearrFetching(); 242 TestJobStreamFetching(); 243 244 } 245 246 private void TestJobStreamFetching() { 241 //TestJobStreamFetching(); 242 } 243 244 private void WriteToJobWithByte(object jobid) { 245 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, 246 new TransactionOptions 247 {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE}) 248 ) { 249 Logger.Info("starting bytestuff for job " + jobid); 250 DaoLocator.JobDao.SetBinaryJobFile((Guid)jobid, jobmap[(Guid)jobid]); 251 scope.Complete(); 252 Logger.Info("ended bytestuff for job " + jobid); 253 } 254 } 255 256 private void UpdateJobStatus(object jobid) { 257 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, 258 new TransactionOptions 259 {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE}) 260 ) { 261 Thread.Sleep(1500); 262 Logger.Info("starting now"); 263 JobDto job = DaoLocator.JobDao.FindById((Guid)jobid); 264 job.Percentage = new Random().NextDouble(); 265 DaoLocator.JobDao.Update(job); 266 scope.Complete(); 267 Logger.Info("ended"); 268 } 269 } 270 271 Dictionary<Guid, byte[]> jobmap = new Dictionary<Guid, byte[]>(); 272 273 274 private void TestLinqFileHandling() { 275 List<Thread> jobupdateThreads = new List<Thread>(); 276 List<Thread> jobProgressThreads = new List<Thread>(); 277 278 Random r = new Random(); 279 Stack<JobDto> jobs = new Stack<JobDto>(DaoLocator.JobDao.FindAll()); 280 Logger.Info("Fetched jobs"); 281 for (int x = 0; x < 10 && jobs.Count > 0; x++ ) { 282 Logger.Info("Creating data for Job"); 283 JobDto job = jobs.Pop(); 284 byte[] jobarr = new byte[50*1024*1024]; 285 for (int i = 0; i < jobarr.Length; i++) { 286 jobarr[i] = (byte) r.Next(255); 287 } 288 jobmap.Add(job.Id, jobarr); 289 } 290 Logger.Info("filled"); 291 foreach(KeyValuePair<Guid, byte[]> kvp in jobmap) { 292 Thread tjob = new Thread(new ParameterizedThreadStart(WriteToJobWithByte)); 293 Thread tupdate = new Thread(new ParameterizedThreadStart(UpdateJobStatus)); 294 jobupdateThreads.Add(tupdate); 295 jobProgressThreads.Add(tjob); 296 tupdate.Start(kvp.Key); 297 tjob.Start(kvp.Key); 298 } 299 foreach (Thread t in jobupdateThreads) { 300 t.Join(); 301 } 302 foreach (Thread t in jobProgressThreads) { 303 t.Join(); 304 } 305 } 306 307 308 private 309 void TestJobStreamFetching() { 247 310 //using (TransactionScope scope = new TransactionScope()) { 311 248 312 HiveDataContext context = ContextFactory.Context; 249 313 250 ContextFactory.Context.Connection.Open(); 251 ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction(); 252 314 ContextFactory.Context.Connection.Open 315 (); 316 ContextFactory.Context.Transaction 317 = 318 ContextFactory.Context.Connection.BeginTransaction 319 (); 320 321 253 322 ClientFacade facade = new ClientFacade(); 323 254 324 Stream stream = facade.SendStreamedJob(new Guid("F5CFB334-66A0-417C-A585-71711BA21D3F")); 255 325 326 256 327 byte[] buffer = new byte[3024]; 328 257 329 int read = 0; 258 259 while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {} 260 261 stream.Close(); 330 331 while (( 332 read 333 = 334 stream.Read 335 ( 336 buffer 337 , 0, 338 buffer.Length 339 )) > 0) {} 340 341 stream.Close 342 (); 262 343 263 344 //Stream stream = DaoLocator.JobDao.GetSerializedJobStream(new Guid("bbb51f87-4e2f-4499-a9b6-884e589c78b6")); … … 265 346 } 266 347 267 private void TestJobBytearrFetching() { 348 private 349 void TestJobBytearrFetching() { 268 350 byte[] arr = DaoLocator.JobDao.GetBinaryJobFile(new Guid("A3386907-2B3C-4976-BE07-04D660D40A5B")); 269 Console.WriteLine(arr); 270 } 271 272 private void SpeedTest() { 351 Console.WriteLine 352 ( 353 arr 354 ); 355 } 356 357 private 358 void SpeedTest() { 273 359 DateTime start = new DateTime(); 360 274 361 List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients()); 362 275 363 DateTime end = new DateTime(); 364 276 365 TimeSpan used = end - start; 277 Console.WriteLine(used.TotalMilliseconds); 278 } 279 280 366 Console.WriteLine 367 ( 368 used.TotalMilliseconds 369 ); 370 } 281 371 } 282 372 }
Note: See TracChangeset
for help on using the changeset viewer.