Commit 0fc5b23e authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[3059] Additional review related changes.

D2UpdateMgr members were rescoped to be more appropriate
and unit tests adjusted accordingly. Other minor changes.
parent 4f2cfbfa
...@@ -91,9 +91,6 @@ DdnsDomainListMgr::setDomains(DdnsDomainMapPtr domains) { ...@@ -91,9 +91,6 @@ DdnsDomainListMgr::setDomains(DdnsDomainMapPtr domains) {
bool bool
DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) { DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) {
// Clear the return parameter.
domain.reset();
// First check the case of one domain to rule them all. // First check the case of one domain to rule them all.
if ((size() == 1) && (wildcard_domain_)) { if ((size() == 1) && (wildcard_domain_)) {
domain = wildcard_domain_; domain = wildcard_domain_;
...@@ -106,6 +103,7 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) { ...@@ -106,6 +103,7 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) {
size_t req_len = fqdn.size(); size_t req_len = fqdn.size();
size_t match_len = 0; size_t match_len = 0;
DdnsDomainMapPair map_pair; DdnsDomainMapPair map_pair;
DdnsDomainPtr best_match;
BOOST_FOREACH (map_pair, *domains_) { BOOST_FOREACH (map_pair, *domains_) {
std::string domain_name = map_pair.first; std::string domain_name = map_pair.first;
size_t dom_len = domain_name.size(); size_t dom_len = domain_name.size();
...@@ -134,13 +132,13 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) { ...@@ -134,13 +132,13 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) {
// any we have matched so far. // any we have matched so far.
if (dom_len > match_len) { if (dom_len > match_len) {
match_len = dom_len; match_len = dom_len;
domain = map_pair.second; best_match = map_pair.second;
} }
} }
} }
} }
if (!domain) { if (!best_match) {
// There's no match. If they specified a wild card domain use it // There's no match. If they specified a wild card domain use it
// otherwise there's no domain for this entry. // otherwise there's no domain for this entry.
if (wildcard_domain_) { if (wildcard_domain_) {
...@@ -152,6 +150,7 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) { ...@@ -152,6 +150,7 @@ DdnsDomainListMgr::matchDomain(const std::string& fqdn, DdnsDomainPtr& domain) {
return (false); return (false);
} }
domain = best_match;
return (true); return (true);
} }
......
...@@ -414,8 +414,8 @@ public: ...@@ -414,8 +414,8 @@ public:
/// it will be returned immediately for any FQDN. /// it will be returned immediately for any FQDN.
/// ///
/// @param fqdn is the name for which to look. /// @param fqdn is the name for which to look.
/// @param domain receives the matching domain. Note that it will be reset /// @param domain receives the matching domain. If no match is found its
/// upon entry and only set if a match is subsequently found. /// contents will be unchanged.
/// ///
/// @return returns true if a match is found, false otherwise. /// @return returns true if a match is found, false otherwise.
/// @todo This is a very basic match method, which expects valid FQDNs /// @todo This is a very basic match method, which expects valid FQDNs
......
...@@ -152,7 +152,7 @@ public: ...@@ -152,7 +152,7 @@ public:
const size_t max_transactions = MAX_TRANSACTIONS_DEFAULT); const size_t max_transactions = MAX_TRANSACTIONS_DEFAULT);
/// @brief Destructor /// @brief Destructor
~D2UpdateMgr(); virtual ~D2UpdateMgr();
/// @brief Check current transactions; start transactions for new requests. /// @brief Check current transactions; start transactions for new requests.
/// ///
...@@ -170,6 +170,7 @@ public: ...@@ -170,6 +170,7 @@ public:
/// add the transaction to the list of transactions. /// add the transaction to the list of transactions.
void sweep(); void sweep();
protected:
/// @brief Performs post-completion cleanup on completed transactions. /// @brief Performs post-completion cleanup on completed transactions.
/// ///
/// Iterates through the list of transactions and removes any that have /// Iterates through the list of transactions and removes any that have
...@@ -208,6 +209,7 @@ public: ...@@ -208,6 +209,7 @@ public:
/// exists. Note this would be programmatic error. /// exists. Note this would be programmatic error.
void makeTransaction(isc::dhcp_ddns::NameChangeRequestPtr& ncr); void makeTransaction(isc::dhcp_ddns::NameChangeRequestPtr& ncr);
public:
/// @brief Returns the maximum number of concurrent transactions. /// @brief Returns the maximum number of concurrent transactions.
size_t getMaxTransactions() const { size_t getMaxTransactions() const {
return (max_transactions_); return (max_transactions_);
...@@ -286,6 +288,7 @@ private: ...@@ -286,6 +288,7 @@ private:
/// @brief Defines a pointer to a D2UpdateMgr instance. /// @brief Defines a pointer to a D2UpdateMgr instance.
typedef boost::shared_ptr<D2UpdateMgr> D2UpdateMgrPtr; typedef boost::shared_ptr<D2UpdateMgr> D2UpdateMgrPtr;
} // namespace isc::d2 } // namespace isc::d2
} // namespace isc } // namespace isc
#endif #endif
...@@ -31,23 +31,56 @@ using namespace isc::d2; ...@@ -31,23 +31,56 @@ using namespace isc::d2;
namespace { namespace {
/// @brief Wrapper class for D2UpdateMgr to provide acces non-public methods.
///
/// This class faciliates testing by making non-public methods accessible so
/// they can be invoked directly in test routines.
class D2UpdateMgrWrapper : public D2UpdateMgr {
public:
/// @brief Constructor
///
/// Parameters match those needed by D2UpdateMgr.
D2UpdateMgrWrapper(D2QueueMgrPtr& queue_mgr, D2CfgMgrPtr& cfg_mgr,
isc::asiolink::IOService& io_service,
const size_t max_transactions = MAX_TRANSACTIONS_DEFAULT)
: D2UpdateMgr(queue_mgr, cfg_mgr, io_service, max_transactions) {
}
/// @brief Destructor
virtual ~D2UpdateMgrWrapper() {
}
// Expose the protected methods to be tested.
using D2UpdateMgr::checkFinishedTransactions;
using D2UpdateMgr::pickNextJob;
using D2UpdateMgr::makeTransaction;
};
/// @brief Defines a pointer to a D2UpdateMgr instance.
typedef boost::shared_ptr<D2UpdateMgrWrapper> D2UpdateMgrWrapperPtr;
/// @brief Test fixture for testing D2UpdateMgr. /// @brief Test fixture for testing D2UpdateMgr.
/// D2UpdateMgr depends on both D2QueueMgr and D2CfgMgr. This fixture ///
/// provides an instance of each, plus a canned, valid DHCP_DDNS configuration /// Note this class uses D2UpdateMgrWrapper class to exercise non-public
/// sufficient to test D2UpdateMgr's basic functions. /// aspects of D2UpdateMgr. D2UpdateMgr depends on both D2QueueMgr and
/// D2CfgMgr. This fixture provides an instance of each, plus a canned,
/// valid DHCP_DDNS configuration sufficient to test D2UpdateMgr's basic
/// functions.
class D2UpdateMgrTest : public ConfigParseTest { class D2UpdateMgrTest : public ConfigParseTest {
public: public:
isc::asiolink::IOService io_service_; isc::asiolink::IOService io_service_;
D2QueueMgrPtr queue_mgr_; D2QueueMgrPtr queue_mgr_;
D2CfgMgrPtr cfg_mgr_; D2CfgMgrPtr cfg_mgr_;
D2UpdateMgrPtr update_mgr_; //D2UpdateMgrPtr update_mgr_;
D2UpdateMgrWrapperPtr update_mgr_;
std::vector<NameChangeRequestPtr> canned_ncrs_; std::vector<NameChangeRequestPtr> canned_ncrs_;
size_t canned_count_; size_t canned_count_;
D2UpdateMgrTest() { D2UpdateMgrTest() {
queue_mgr_.reset(new D2QueueMgr(io_service_)); queue_mgr_.reset(new D2QueueMgr(io_service_));
cfg_mgr_.reset(new D2CfgMgr()); cfg_mgr_.reset(new D2CfgMgr());
update_mgr_.reset(new D2UpdateMgr(queue_mgr_, cfg_mgr_, io_service_)); update_mgr_.reset(new D2UpdateMgrWrapper(queue_mgr_, cfg_mgr_,
io_service_));
makeCannedNcrs(); makeCannedNcrs();
makeCannedConfig(); makeCannedConfig();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment