| 549 | } |
| 550 | |
| 551 | bool testPolicy(Reference<LocalitySet> servers, |
| 552 | Reference<IReplicationPolicy> const& policy, |
| 553 | std::vector<LocalityEntry> const& including, |
| 554 | bool validate) { |
| 555 | LocalityMap<repTestType>* serverMap = (LocalityMap<repTestType>*)servers.getPtr(); |
| 556 | std::string outputText, includeText; |
| 557 | std::vector<LocalityEntry> entryResults; |
| 558 | std::vector<repTestType*> results; |
| 559 | bool valid, solved; |
| 560 | |
| 561 | if (g_replicationdebug > 1) { |
| 562 | printf("Policy test: include:%4lu policy: %-10s => %s\n", |
| 563 | including.size(), |
| 564 | policy->name().c_str(), |
| 565 | policy->info().c_str()); |
| 566 | } |
| 567 | if (g_replicationdebug > 2) { |
| 568 | for (auto& entry : including) { |
| 569 | printf(" also: %s\n", servers->getEntryInfo(entry).c_str()); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | solved = serverMap->selectReplicas(policy, including, entryResults, results); |
| 574 | |
| 575 | if (g_replicationdebug > 1) { |
| 576 | printf("%-10s solution:%3lu policy: %-10s => %s include:%4lu\n", |
| 577 | ((solved) ? "Solved" : "Unsolved"), |
| 578 | results.size(), |
| 579 | policy->name().c_str(), |
| 580 | policy->info().c_str(), |
| 581 | including.size()); |
| 582 | } |
| 583 | if (g_replicationdebug > 2) { |
| 584 | for (auto& entry : entryResults) { |
| 585 | printf(" item: %s\n", servers->getEntryInfo(entry).c_str()); |
| 586 | } |
| 587 | for (auto& entry : including) { |
| 588 | printf(" also: %s\n", servers->getEntryInfo(entry).c_str()); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | valid = (validate) ? policy->validateFull(solved, entryResults, including, servers) : true; |
| 593 | |
| 594 | if (g_replicationdebug > 0) { |
| 595 | if (including.size()) { |
| 596 | includeText = " with "; |
| 597 | for (auto& entry : including) { |
| 598 | includeText += " " + servers->getEntryInfo(entry); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | if (results.size()) { |
| 603 | outputText = policy->info() + includeText + " -> "; |
| 604 | int count = 0; |
| 605 | for (auto& entry : entryResults) { |
| 606 | outputText += " " + *results[count] + "-" + servers->getEntryInfo(entry); |
| 607 | count++; |
| 608 | } |
no test coverage detected