Mercurial > hg > orthanc
comparison UnitTestsSources/MultiThreadingTests.cpp @ 1009:26642cecd36d lua-scripting
clearer job interface
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:11:44 +0200 |
parents | 84b6d7bca6db |
children | 6e7e5ed91c2d |
comparison
equal
deleted
inserted
replaced
1008:187ed107a59f | 1009:26642cecd36d |
---|---|
301 //if (a == 84) { printf("BREAK\n"); return false; } | 301 //if (a == 84) { printf("BREAK\n"); return false; } |
302 | 302 |
303 outputs.push_back(boost::lexical_cast<std::string>(b)); | 303 outputs.push_back(boost::lexical_cast<std::string>(b)); |
304 } | 304 } |
305 | 305 |
306 Toolbox::USleep(1000000); | 306 Toolbox::USleep(100000); |
307 | 307 |
308 return true; | 308 return true; |
309 } | 309 } |
310 | |
311 virtual bool SendOutputsToSink() const | |
312 { | |
313 return true; | |
314 } | |
315 }; | 310 }; |
316 | 311 |
317 | 312 |
318 static void Tata(ServerScheduler* s, ServerJob* j, bool* done) | 313 static void Tata(ServerScheduler* s, ServerJob* j, bool* done) |
319 { | 314 { |
320 typedef IServerCommand::ListOfStrings ListOfStrings; | 315 typedef IServerCommand::ListOfStrings ListOfStrings; |
321 | 316 |
322 #if 1 | |
323 while (!(*done)) | 317 while (!(*done)) |
324 { | 318 { |
325 ListOfStrings l; | 319 ListOfStrings l; |
326 s->GetListOfJobs(l); | 320 s->GetListOfJobs(l); |
327 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++) | 321 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++) |
328 printf(">> %s: %0.1f\n", i->c_str(), 100.0f * s->GetProgress(*i)); | 322 printf(">> %s: %0.1f\n", i->c_str(), 100.0f * s->GetProgress(*i)); |
329 Toolbox::USleep(100000); | 323 Toolbox::USleep(10000); |
330 } | 324 } |
331 #else | 325 } |
332 ListOfStrings l; | 326 |
333 s->GetListOfJobs(l); | 327 |
334 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++) | 328 TEST(MultiThreading, ServerScheduler) |
335 printf(">> %s\n", i->c_str()); | |
336 Toolbox::USleep(1500000); | |
337 s->Cancel(*j); | |
338 Toolbox::USleep(1000000); | |
339 s->GetListOfJobs(l); | |
340 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++) | |
341 printf(">> %s\n", i->c_str()); | |
342 #endif | |
343 } | |
344 | |
345 | |
346 TEST(MultiThreading, DISABLED_ServerScheduler) | |
347 { | 329 { |
348 ServerScheduler scheduler(10); | 330 ServerScheduler scheduler(10); |
349 | 331 |
350 ServerJob job; | 332 ServerJob job; |
351 ServerCommandInstance& f2 = job.AddCommand(new Tutu(2)); | 333 ServerCommandInstance& f2 = job.AddCommand(new Tutu(2)); |
353 ServerCommandInstance& f4 = job.AddCommand(new Tutu(4)); | 335 ServerCommandInstance& f4 = job.AddCommand(new Tutu(4)); |
354 ServerCommandInstance& f5 = job.AddCommand(new Tutu(5)); | 336 ServerCommandInstance& f5 = job.AddCommand(new Tutu(5)); |
355 f2.AddInput(boost::lexical_cast<std::string>(42)); | 337 f2.AddInput(boost::lexical_cast<std::string>(42)); |
356 //f3.AddInput(boost::lexical_cast<std::string>(42)); | 338 //f3.AddInput(boost::lexical_cast<std::string>(42)); |
357 //f4.AddInput(boost::lexical_cast<std::string>(42)); | 339 //f4.AddInput(boost::lexical_cast<std::string>(42)); |
358 f2.ConnectNext(f3); | 340 f2.ConnectOutput(f3); |
359 f3.ConnectNext(f4); | 341 f3.ConnectOutput(f4); |
360 f4.ConnectNext(f5); | 342 f4.ConnectOutput(f5); |
343 | |
344 f3.SetConnectedToSink(true); | |
345 f5.SetConnectedToSink(true); | |
361 | 346 |
362 job.SetDescription("tutu"); | 347 job.SetDescription("tutu"); |
363 | 348 |
364 bool done = false; | 349 bool done = false; |
365 boost::thread t(Tata, &scheduler, &job, &done); | 350 boost::thread t(Tata, &scheduler, &job, &done); |
368 //scheduler.Submit(job); | 353 //scheduler.Submit(job); |
369 | 354 |
370 IServerCommand::ListOfStrings l; | 355 IServerCommand::ListOfStrings l; |
371 scheduler.SubmitAndWait(l, job); | 356 scheduler.SubmitAndWait(l, job); |
372 | 357 |
358 ASSERT_EQ(2, l.size()); | |
359 ASSERT_EQ(42 * 2 * 3, boost::lexical_cast<int>(l.front())); | |
360 ASSERT_EQ(42 * 2 * 3 * 4 * 5, boost::lexical_cast<int>(l.back())); | |
361 | |
373 for (IServerCommand::ListOfStrings::iterator i = l.begin(); i != l.end(); i++) | 362 for (IServerCommand::ListOfStrings::iterator i = l.begin(); i != l.end(); i++) |
374 { | 363 { |
375 printf("** %s\n", i->c_str()); | 364 printf("** %s\n", i->c_str()); |
376 } | 365 } |
377 | 366 |