comparison UnitTestsSources/ServerIndexTests.cpp @ 1159:8f9d49192815 db-changes

speeding up db schema
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Sep 2014 10:25:41 +0200
parents ba9fd42284d0
children 1ea4094d077c
comparison
equal deleted inserted replaced
1158:badc14fee61f 1159:8f9d49192815
56 56
57 class ServerIndexListener : public IServerIndexListener 57 class ServerIndexListener : public IServerIndexListener
58 { 58 {
59 public: 59 public:
60 std::vector<std::string> deletedFiles_; 60 std::vector<std::string> deletedFiles_;
61 std::vector<std::string> deletedResources_;
61 std::string ancestorId_; 62 std::string ancestorId_;
62 ResourceType ancestorType_; 63 ResourceType ancestorType_;
63 64
64 void Reset() 65 void Reset()
65 { 66 {
77 virtual void SignalFileDeleted(const FileInfo& info) 78 virtual void SignalFileDeleted(const FileInfo& info)
78 { 79 {
79 const std::string fileUuid = info.GetUuid(); 80 const std::string fileUuid = info.GetUuid();
80 deletedFiles_.push_back(fileUuid); 81 deletedFiles_.push_back(fileUuid);
81 LOG(INFO) << "A file must be removed: " << fileUuid; 82 LOG(INFO) << "A file must be removed: " << fileUuid;
82 } 83 }
84
85 virtual void SignalResourceDeleted(ResourceType type,
86 const std::string& publicId)
87 {
88 deletedResources_.push_back(publicId);
89 LOG(INFO) << "A resource was removed: " << publicId;
90 }
91
83 }; 92 };
84 93
85 94
86 class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass> 95 class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass>
87 { 96 {
279 ASSERT_EQ("md5", att.GetCompressedMD5()); 288 ASSERT_EQ("md5", att.GetCompressedMD5());
280 ASSERT_EQ(44u, att.GetUncompressedSize()); 289 ASSERT_EQ(44u, att.GetUncompressedSize());
281 ASSERT_EQ(CompressionType_None, att.GetCompressionType()); 290 ASSERT_EQ(CompressionType_None, att.GetCompressionType());
282 291
283 ASSERT_EQ(0u, listener_->deletedFiles_.size()); 292 ASSERT_EQ(0u, listener_->deletedFiles_.size());
293 ASSERT_EQ(0u, listener_->deletedResources_.size());
284 ASSERT_EQ(7u, index_->GetTableRecordCount("Resources")); 294 ASSERT_EQ(7u, index_->GetTableRecordCount("Resources"));
285 ASSERT_EQ(3u, index_->GetTableRecordCount("AttachedFiles")); 295 ASSERT_EQ(3u, index_->GetTableRecordCount("AttachedFiles"));
286 ASSERT_EQ(1u, index_->GetTableRecordCount("Metadata")); 296 ASSERT_EQ(1u, index_->GetTableRecordCount("Metadata"));
287 ASSERT_EQ(1u, index_->GetTableRecordCount("MainDicomTags")); 297 ASSERT_EQ(1u, index_->GetTableRecordCount("MainDicomTags"));
298
288 index_->DeleteResource(a[0]); 299 index_->DeleteResource(a[0]);
289 300 ASSERT_EQ(5u, listener_->deletedResources_.size());
290 ASSERT_EQ(2u, listener_->deletedFiles_.size()); 301 ASSERT_EQ(2u, listener_->deletedFiles_.size());
291 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), 302 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(),
292 listener_->deletedFiles_.end(), 303 listener_->deletedFiles_.end(),
293 "my json file") == listener_->deletedFiles_.end()); 304 "my json file") == listener_->deletedFiles_.end());
294 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), 305 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(),
298 ASSERT_EQ(2u, index_->GetTableRecordCount("Resources")); 309 ASSERT_EQ(2u, index_->GetTableRecordCount("Resources"));
299 ASSERT_EQ(0u, index_->GetTableRecordCount("Metadata")); 310 ASSERT_EQ(0u, index_->GetTableRecordCount("Metadata"));
300 ASSERT_EQ(1u, index_->GetTableRecordCount("AttachedFiles")); 311 ASSERT_EQ(1u, index_->GetTableRecordCount("AttachedFiles"));
301 ASSERT_EQ(0u, index_->GetTableRecordCount("MainDicomTags")); 312 ASSERT_EQ(0u, index_->GetTableRecordCount("MainDicomTags"));
302 index_->DeleteResource(a[5]); 313 index_->DeleteResource(a[5]);
314 ASSERT_EQ(7u, listener_->deletedResources_.size());
303 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); 315 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources"));
304 ASSERT_EQ(0u, index_->GetTableRecordCount("AttachedFiles")); 316 ASSERT_EQ(0u, index_->GetTableRecordCount("AttachedFiles"));
305 ASSERT_EQ(2u, index_->GetTableRecordCount("GlobalProperties")); 317 ASSERT_EQ(2u, index_->GetTableRecordCount("GlobalProperties"));
306 318
307 ASSERT_EQ(3u, listener_->deletedFiles_.size()); 319 ASSERT_EQ(3u, listener_->deletedFiles_.size());
393 405
394 ASSERT_EQ(10u, index_->GetTableRecordCount("Resources")); 406 ASSERT_EQ(10u, index_->GetTableRecordCount("Resources"));
395 ASSERT_EQ(10u, index_->GetTableRecordCount("PatientRecyclingOrder")); 407 ASSERT_EQ(10u, index_->GetTableRecordCount("PatientRecyclingOrder"));
396 408
397 listener_->Reset(); 409 listener_->Reset();
410 ASSERT_EQ(0u, listener_->deletedResources_.size());
398 411
399 index_->DeleteResource(patients[5]); 412 index_->DeleteResource(patients[5]);
400 index_->DeleteResource(patients[0]); 413 index_->DeleteResource(patients[0]);
414 ASSERT_EQ(2u, listener_->deletedResources_.size());
401 ASSERT_EQ(8u, index_->GetTableRecordCount("Resources")); 415 ASSERT_EQ(8u, index_->GetTableRecordCount("Resources"));
402 ASSERT_EQ(8u, index_->GetTableRecordCount("PatientRecyclingOrder")); 416 ASSERT_EQ(8u, index_->GetTableRecordCount("PatientRecyclingOrder"));
403 417
404 ASSERT_EQ(2u, listener_->deletedFiles_.size()); 418 ASSERT_EQ(2u, listener_->deletedFiles_.size());
405 ASSERT_EQ("Patient 5", listener_->deletedFiles_[0]); 419 ASSERT_EQ("Patient 5", listener_->deletedFiles_[0]);
406 ASSERT_EQ("Patient 0", listener_->deletedFiles_[1]); 420 ASSERT_EQ("Patient 0", listener_->deletedFiles_[1]);
407 421
408 int64_t p; 422 int64_t p;
409 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); 423 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
410 index_->DeleteResource(p); 424 index_->DeleteResource(p);
425 ASSERT_EQ(3u, listener_->deletedResources_.size());
411 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); 426 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
412 index_->DeleteResource(p); 427 index_->DeleteResource(p);
428 ASSERT_EQ(4u, listener_->deletedResources_.size());
413 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); 429 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
414 index_->DeleteResource(p); 430 index_->DeleteResource(p);
431 ASSERT_EQ(5u, listener_->deletedResources_.size());
415 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); 432 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
416 index_->DeleteResource(p); 433 index_->DeleteResource(p);
434 ASSERT_EQ(6u, listener_->deletedResources_.size());
417 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]); 435 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]);
418 index_->DeleteResource(p); 436 index_->DeleteResource(p);
419 index_->DeleteResource(patients[8]); 437 index_->DeleteResource(patients[8]);
438 ASSERT_EQ(8u, listener_->deletedResources_.size());
420 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]); 439 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]);
421 index_->DeleteResource(p); 440 index_->DeleteResource(p);
441 ASSERT_EQ(9u, listener_->deletedResources_.size());
422 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]); 442 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]);
423 index_->DeleteResource(p); 443 index_->DeleteResource(p);
424 ASSERT_FALSE(index_->SelectPatientToRecycle(p)); 444 ASSERT_FALSE(index_->SelectPatientToRecycle(p));
445 ASSERT_EQ(10u, listener_->deletedResources_.size());
425 446
426 ASSERT_EQ(10u, listener_->deletedFiles_.size()); 447 ASSERT_EQ(10u, listener_->deletedFiles_.size());
427 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); 448 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources"));
428 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder")); 449 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder"));
429 } 450 }
475 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources")); 496 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources"));
476 ASSERT_EQ(0u, listener_->deletedFiles_.size()); 497 ASSERT_EQ(0u, listener_->deletedFiles_.size());
477 498
478 // Unprotecting a patient puts it at the last position in the recycling queue 499 // Unprotecting a patient puts it at the last position in the recycling queue
479 int64_t p; 500 int64_t p;
501 ASSERT_EQ(0u, listener_->deletedResources_.size());
480 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]); 502 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]);
481 index_->DeleteResource(p); 503 index_->DeleteResource(p);
504 ASSERT_EQ(1u, listener_->deletedResources_.size());
482 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]); 505 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]);
483 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); 506 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
484 index_->DeleteResource(p); 507 index_->DeleteResource(p);
508 ASSERT_EQ(2u, listener_->deletedResources_.size());
485 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); 509 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
486 index_->DeleteResource(p); 510 index_->DeleteResource(p);
511 ASSERT_EQ(3u, listener_->deletedResources_.size());
487 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[2])); 512 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[2]));
488 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); 513 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
489 index_->DeleteResource(p); 514 index_->DeleteResource(p);
515 ASSERT_EQ(4u, listener_->deletedResources_.size());
490 // "patients[3]" is still protected 516 // "patients[3]" is still protected
491 ASSERT_FALSE(index_->SelectPatientToRecycle(p)); 517 ASSERT_FALSE(index_->SelectPatientToRecycle(p));
492 518
493 ASSERT_EQ(4u, listener_->deletedFiles_.size()); 519 ASSERT_EQ(4u, listener_->deletedFiles_.size());
494 ASSERT_EQ(1u, index_->GetTableRecordCount("Resources")); 520 ASSERT_EQ(1u, index_->GetTableRecordCount("Resources"));
498 ASSERT_EQ(1u, index_->GetTableRecordCount("PatientRecyclingOrder")); 524 ASSERT_EQ(1u, index_->GetTableRecordCount("PatientRecyclingOrder"));
499 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[3])); 525 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[3]));
500 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[2])); 526 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[2]));
501 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); 527 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
502 index_->DeleteResource(p); 528 index_->DeleteResource(p);
529 ASSERT_EQ(5u, listener_->deletedResources_.size());
503 530
504 ASSERT_EQ(5u, listener_->deletedFiles_.size()); 531 ASSERT_EQ(5u, listener_->deletedFiles_.size());
505 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); 532 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources"));
506 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder")); 533 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder"));
507 } 534 }