BIND 10 trac2203, updated. 44d9dfa8aad85d583b7b90fa01c50613a9d9d1a5 [2203] renamed datasrc_configurator to datasrc_config; it represents it better.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Oct 5 17:13:43 UTC 2012
The branch, trac2203 has been updated
via 44d9dfa8aad85d583b7b90fa01c50613a9d9d1a5 (commit)
from 6b99a39f0ab27939c29a05b0332d5ec255bc0764 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 44d9dfa8aad85d583b7b90fa01c50613a9d9d1a5
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Oct 5 10:12:42 2012 -0700
[2203] renamed datasrc_configurator to datasrc_config; it represents it better.
-----------------------------------------------------------------------
Summary of changes:
src/bin/auth/Makefile.am | 2 +-
src/bin/auth/benchmarks/Makefile.am | 2 +-
src/bin/auth/benchmarks/query_bench.cc | 2 +-
.../{datasrc_configurator.cc => datasrc_config.cc} | 2 +-
.../{datasrc_configurator.h => datasrc_config.h} | 8 ++---
src/bin/auth/main.cc | 2 +-
src/bin/auth/tests/Makefile.am | 4 +--
src/bin/auth/tests/auth_srv_unittest.cc | 2 +-
src/bin/auth/tests/command_unittest.cc | 2 +-
...ator_unittest.cc => datasrc_config_unittest.cc} | 31 ++++++++++----------
10 files changed, 28 insertions(+), 29 deletions(-)
rename src/bin/auth/{datasrc_configurator.cc => datasrc_config.cc} (97%)
rename src/bin/auth/{datasrc_configurator.h => datasrc_config.h} (97%)
rename src/bin/auth/tests/{datasrc_configurator_unittest.cc => datasrc_config_unittest.cc} (92%)
-----------------------------------------------------------------------
diff --git a/src/bin/auth/Makefile.am b/src/bin/auth/Makefile.am
index df30a42..9eee9d4 100644
--- a/src/bin/auth/Makefile.am
+++ b/src/bin/auth/Makefile.am
@@ -55,7 +55,7 @@ b10_auth_SOURCES += auth_config.cc auth_config.h
b10_auth_SOURCES += command.cc command.h
b10_auth_SOURCES += common.h common.cc
b10_auth_SOURCES += statistics.cc statistics.h
-b10_auth_SOURCES += datasrc_configurator.h datasrc_configurator.cc
+b10_auth_SOURCES += datasrc_config.h datasrc_config.cc
b10_auth_SOURCES += main.cc
nodist_b10_auth_SOURCES = auth_messages.h auth_messages.cc
diff --git a/src/bin/auth/benchmarks/Makefile.am b/src/bin/auth/benchmarks/Makefile.am
index fcfcb8a..c525b66 100644
--- a/src/bin/auth/benchmarks/Makefile.am
+++ b/src/bin/auth/benchmarks/Makefile.am
@@ -17,7 +17,7 @@ query_bench_SOURCES += ../auth_srv.h ../auth_srv.cc
query_bench_SOURCES += ../auth_config.h ../auth_config.cc
query_bench_SOURCES += ../statistics.h ../statistics.cc
query_bench_SOURCES += ../auth_log.h ../auth_log.cc
-query_bench_SOURCES += ../datasrc_configurator.h ../datasrc_configurator.cc
+query_bench_SOURCES += ../datasrc_config.h ../datasrc_config.cc
nodist_query_bench_SOURCES = ../auth_messages.h ../auth_messages.cc
diff --git a/src/bin/auth/benchmarks/query_bench.cc b/src/bin/auth/benchmarks/query_bench.cc
index 07111a5..73f702b 100644
--- a/src/bin/auth/benchmarks/query_bench.cc
+++ b/src/bin/auth/benchmarks/query_bench.cc
@@ -30,7 +30,7 @@
#include <auth/auth_srv.h>
#include <auth/auth_config.h>
-#include <auth/datasrc_configurator.h>
+#include <auth/datasrc_config.h>
#include <auth/query.h>
#include <asiodns/asiodns.h>
diff --git a/src/bin/auth/datasrc_config.cc b/src/bin/auth/datasrc_config.cc
new file mode 100644
index 0000000..73fb519
--- /dev/null
+++ b/src/bin/auth/datasrc_config.cc
@@ -0,0 +1,26 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <cc/data.h>
+#include "auth_srv.h"
+#include "datasrc_config.h"
+
+// This is a trivial specialization for the commonly used version.
+// Defined in .cc to avoid accidental creation of multiple copies.
+void
+configureDataSource(AuthSrv& server, const isc::data::ConstElementPtr& config)
+{
+ return (configureDataSourceGeneric<AuthSrv,
+ isc::datasrc::ConfigurableClientList>(server, config));
+}
diff --git a/src/bin/auth/datasrc_config.h b/src/bin/auth/datasrc_config.h
new file mode 100644
index 0000000..79ace28
--- /dev/null
+++ b/src/bin/auth/datasrc_config.h
@@ -0,0 +1,120 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef DATASRC_CONFIG_H
+#define DATASRC_CONFIG_H
+
+#include "auth_srv.h"
+
+#include <cc/data.h>
+#include <datasrc/client_list.h>
+#include <util/threads/lock.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <set>
+
+/// \brief Configure the authoritative server's data source lists
+///
+/// This will hook into the data_sources module configuration and it will
+/// keep the local copy of data source clients in the list in the authoritative
+/// server.
+///
+/// This function is templated. This is simply because of easier testing.
+/// You don't need to pay attention to it, use the configureDataSource
+/// specialization instead.
+///
+/// \param server It is the server to configure.
+/// \param config The configuration value to parse. It is in the form
+/// as an update from the config manager.
+template<class Server, class List>
+void
+configureDataSourceGeneric(Server& server,
+ const isc::data::ConstElementPtr& config)
+{
+ typedef boost::shared_ptr<List> ListPtr;
+ typedef std::map<std::string, isc::data::ConstElementPtr> Map;
+ typedef std::pair<isc::dns::RRClass, ListPtr> RollbackPair;
+ typedef std::pair<isc::dns::RRClass, isc::data::ConstElementPtr>
+ RollbackConfiguration;
+
+ // Lock the client lists, we're going to manipulate them.
+ isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
+
+ // Some structures to be able to perform a rollback
+ std::vector<RollbackPair> rollback_sets;
+ std::vector<RollbackConfiguration> rollback_configurations;
+ try {
+ // Get the configuration and current state.
+ const Map& map(config->mapValue());
+ const std::vector<isc::dns::RRClass>
+ activeVector(server.getClientListClasses());
+ std::set<isc::dns::RRClass> active(activeVector.begin(),
+ activeVector.end());
+ // Go through the configuration and change everything.
+ for (Map::const_iterator it(map.begin()); it != map.end(); ++it) {
+ const isc::dns::RRClass rrclass(it->first);
+ active.erase(rrclass);
+ ListPtr list(server.getClientList(rrclass));
+ bool need_set(false);
+ if (list) {
+ rollback_configurations.
+ push_back(RollbackConfiguration(rrclass,
+ list->getConfiguration()));
+ } else {
+ list.reset(new List(rrclass));
+ need_set = true;
+ rollback_sets.push_back(RollbackPair(rrclass, ListPtr()));
+ }
+ list->configure(it->second, true);
+ if (need_set) {
+ server.setClientList(rrclass, list);
+ }
+ }
+ // Remove the ones that are not in the configuration.
+ for (std::set<isc::dns::RRClass>::iterator it(active.begin());
+ it != active.end(); ++it) {
+ // There seems to be no way the setClientList could throw.
+ // But this is just to make sure in case it did to restore
+ // the original.
+ rollback_sets.push_back(
+ RollbackPair(*it, server.getClientList(*it)));
+ server.setClientList(*it, ListPtr());
+ }
+ } catch (...) {
+ // Perform a rollback of the changes. The old configuration should
+ // work.
+ for (typename std::vector<RollbackPair>::const_iterator
+ it(rollback_sets.begin()); it != rollback_sets.end(); ++it) {
+ server.setClientList(it->first, it->second);
+ }
+ for (typename std::vector<RollbackConfiguration>::const_iterator
+ it(rollback_configurations.begin());
+ it != rollback_configurations.end(); ++it) {
+ server.getClientList(it->first)->configure(it->second, true);
+ }
+ throw;
+ }
+}
+
+/// \brief Concrete version of configureDataSource() for the
+/// use with authoritative server implementation.
+void
+configureDataSource(AuthSrv& server, const isc::data::ConstElementPtr& config);
+
+#endif // DATASRC_CONFIG_H
+
+// Local Variables:
+// mode: c++
+// End:
diff --git a/src/bin/auth/datasrc_configurator.cc b/src/bin/auth/datasrc_configurator.cc
deleted file mode 100644
index 5469389..0000000
--- a/src/bin/auth/datasrc_configurator.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <cc/data.h>
-#include "auth_srv.h"
-#include "datasrc_configurator.h"
-
-// This is a trivial specialization for the commonly used version.
-// Defined in .cc to avoid accidental creation of multiple copies.
-void
-configureDataSource(AuthSrv& server, const isc::data::ConstElementPtr& config)
-{
- return (configureDataSourceGeneric<AuthSrv,
- isc::datasrc::ConfigurableClientList>(server, config));
-}
diff --git a/src/bin/auth/datasrc_configurator.h b/src/bin/auth/datasrc_configurator.h
deleted file mode 100644
index b8d21f3..0000000
--- a/src/bin/auth/datasrc_configurator.h
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef DATASRC_CONFIGURATOR_H
-#define DATASRC_CONFIGURATOR_H
-
-#include "auth_srv.h"
-
-#include <cc/data.h>
-#include <datasrc/client_list.h>
-#include <util/threads/lock.h>
-
-#include <boost/shared_ptr.hpp>
-
-#include <set>
-
-/// \brief Configure the authoritative server's data source lists
-///
-/// This will hook into the data_sources module configuration and it will
-/// keep the local copy of data source clients in the list in the authoritative
-/// server.
-///
-/// This function is templated. This is simply because of easier testing.
-/// You don't need to pay attention to it, use the configureDataSource
-/// specialization instead.
-///
-/// \param server It is the server to configure.
-/// \param config The configuration value to parse. It is in the form
-/// as an update from the config manager.
-template<class Server, class List>
-void
-configureDataSourceGeneric(Server& server,
- const isc::data::ConstElementPtr& config)
-{
- typedef boost::shared_ptr<List> ListPtr;
- typedef std::map<std::string, isc::data::ConstElementPtr> Map;
- typedef std::pair<isc::dns::RRClass, ListPtr> RollbackPair;
- typedef std::pair<isc::dns::RRClass, isc::data::ConstElementPtr>
- RollbackConfiguration;
-
- // Lock the client lists, we're going to manipulate them.
- isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
-
- // Some structures to be able to perform a rollback
- std::vector<RollbackPair> rollback_sets;
- std::vector<RollbackConfiguration> rollback_configurations;
- try {
- // Get the configuration and current state.
- const Map& map(config->mapValue());
- const std::vector<isc::dns::RRClass>
- activeVector(server.getClientListClasses());
- std::set<isc::dns::RRClass> active(activeVector.begin(),
- activeVector.end());
- // Go through the configuration and change everything.
- for (Map::const_iterator it(map.begin()); it != map.end(); ++it) {
- const isc::dns::RRClass rrclass(it->first);
- active.erase(rrclass);
- ListPtr list(server.getClientList(rrclass));
- bool need_set(false);
- if (list) {
- rollback_configurations.
- push_back(RollbackConfiguration(rrclass,
- list->getConfiguration()));
- } else {
- list.reset(new List(rrclass));
- need_set = true;
- rollback_sets.push_back(RollbackPair(rrclass, ListPtr()));
- }
- list->configure(it->second, true);
- if (need_set) {
- server.setClientList(rrclass, list);
- }
- }
- // Remove the ones that are not in the configuration.
- for (std::set<isc::dns::RRClass>::iterator it(active.begin());
- it != active.end(); ++it) {
- // There seems to be no way the setClientList could throw.
- // But this is just to make sure in case it did to restore
- // the original.
- rollback_sets.push_back(
- RollbackPair(*it, server.getClientList(*it)));
- server.setClientList(*it, ListPtr());
- }
- } catch (...) {
- // Perform a rollback of the changes. The old configuration should
- // work.
- for (typename std::vector<RollbackPair>::const_iterator
- it(rollback_sets.begin()); it != rollback_sets.end(); ++it) {
- server.setClientList(it->first, it->second);
- }
- for (typename std::vector<RollbackConfiguration>::const_iterator
- it(rollback_configurations.begin());
- it != rollback_configurations.end(); ++it) {
- server.getClientList(it->first)->configure(it->second, true);
- }
- throw;
- }
-}
-
-/// \brief Concrete version of DataSourceConfiguratorGeneric for the
-/// use with authoritative server implementation.
-void
-configureDataSource(AuthSrv& server, const isc::data::ConstElementPtr& config);
-
-#endif
-
-// Local Variables:
-// mode: c++
-// End:
diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc
index 8431a48..b425813 100644
--- a/src/bin/auth/main.cc
+++ b/src/bin/auth/main.cc
@@ -34,7 +34,7 @@
#include <auth/command.h>
#include <auth/auth_srv.h>
#include <auth/auth_log.h>
-#include <auth/datasrc_configurator.h>
+#include <auth/datasrc_config.h>
#include <asiodns/asiodns.h>
#include <asiolink/asiolink.h>
#include <log/logger_support.h>
diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am
index 3b18736..6b9d385 100644
--- a/src/bin/auth/tests/Makefile.am
+++ b/src/bin/auth/tests/Makefile.am
@@ -42,7 +42,7 @@ run_unittests_SOURCES += ../auth_config.h ../auth_config.cc
run_unittests_SOURCES += ../command.h ../command.cc
run_unittests_SOURCES += ../common.h ../common.cc
run_unittests_SOURCES += ../statistics.h ../statistics.cc
-run_unittests_SOURCES += ../datasrc_configurator.h ../datasrc_configurator.cc
+run_unittests_SOURCES += ../datasrc_config.h ../datasrc_config.cc
run_unittests_SOURCES += datasrc_util.h datasrc_util.cc
run_unittests_SOURCES += auth_srv_unittest.cc
run_unittests_SOURCES += config_unittest.cc
@@ -51,7 +51,7 @@ run_unittests_SOURCES += command_unittest.cc
run_unittests_SOURCES += common_unittest.cc
run_unittests_SOURCES += query_unittest.cc
run_unittests_SOURCES += statistics_unittest.cc
-run_unittests_SOURCES += datasrc_configurator_unittest.cc
+run_unittests_SOURCES += datasrc_config_unittest.cc
run_unittests_SOURCES += run_unittests.cc
nodist_run_unittests_SOURCES = ../auth_messages.h ../auth_messages.cc
diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc
index 00d7350..8cf5146 100644
--- a/src/bin/auth/tests/auth_srv_unittest.cc
+++ b/src/bin/auth/tests/auth_srv_unittest.cc
@@ -36,7 +36,7 @@
#include <auth/command.h>
#include <auth/common.h>
#include <auth/statistics.h>
-#include <auth/datasrc_configurator.h>
+#include <auth/datasrc_config.h>
#include <util/unittests/mock_socketsession.h>
#include <util/threads/lock.h>
diff --git a/src/bin/auth/tests/command_unittest.cc b/src/bin/auth/tests/command_unittest.cc
index c746526..c799483 100644
--- a/src/bin/auth/tests/command_unittest.cc
+++ b/src/bin/auth/tests/command_unittest.cc
@@ -19,7 +19,7 @@
#include <auth/auth_srv.h>
#include <auth/auth_config.h>
#include <auth/command.h>
-#include <auth/datasrc_configurator.h>
+#include <auth/datasrc_config.h>
#include <dns/name.h>
#include <dns/rrclass.h>
diff --git a/src/bin/auth/tests/datasrc_config_unittest.cc b/src/bin/auth/tests/datasrc_config_unittest.cc
new file mode 100644
index 0000000..3d3aa58
--- /dev/null
+++ b/src/bin/auth/tests/datasrc_config_unittest.cc
@@ -0,0 +1,298 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <auth/datasrc_config.h>
+
+#include <config/tests/fake_session.h>
+#include <config/ccsession.h>
+#include <util/threads/lock.h>
+
+#include <gtest/gtest.h>
+
+#include <boost/bind.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <memory>
+
+using namespace isc;
+using namespace isc::cc;
+using namespace isc::config;
+using namespace isc::data;
+using namespace isc::dns;
+using namespace std;
+using namespace boost;
+
+namespace {
+
+class DatasrcConfigTest;
+
+class FakeList {
+public:
+ FakeList(const RRClass&) :
+ configuration_(new ListElement)
+ {}
+ void configure(const ConstElementPtr& configuration, bool allow_cache) {
+ EXPECT_TRUE(allow_cache);
+ conf_ = configuration->get(0)->get("type")->stringValue();
+ configuration_ = configuration;
+ }
+ const string& getConf() const {
+ return (conf_);
+ }
+ ConstElementPtr getConfiguration() const {
+ return (configuration_);
+ }
+private:
+ string conf_;
+ ConstElementPtr configuration_;
+};
+
+typedef shared_ptr<FakeList> ListPtr;
+
+void
+testConfigureDataSource(DatasrcConfigTest& test,
+ const isc::data::ConstElementPtr& config)
+{
+ // We use the test fixture for the Server type. This makes it possible
+ // to easily fake all needed methods and look that they were called.
+ configureDataSourceGeneric<DatasrcConfigTest, FakeList>(test, config);
+}
+
+void
+datasrcConfigHandler(DatasrcConfigTest* fake_server, const std::string&,
+ isc::data::ConstElementPtr config,
+ const isc::config::ConfigData&)
+{
+ if (config->contains("classes")) {
+ testConfigureDataSource(*fake_server, config->get("classes"));
+ }
+}
+
+class DatasrcConfigTest : public ::testing::Test {
+public:
+ // These pretend to be the server
+ ListPtr getClientList(const RRClass& rrclass) {
+ log_ += "get " + rrclass.toText() + "\n";
+ return (lists_[rrclass]);
+ }
+ void setClientList(const RRClass& rrclass, const ListPtr& list) {
+ log_ += "set " + rrclass.toText() + " " +
+ (list ? list->getConf() : "") + "\n";
+ lists_[rrclass] = list;
+ }
+ vector<RRClass> getClientListClasses() const {
+ vector<RRClass> result;
+ for (std::map<RRClass, ListPtr>::const_iterator it(lists_.begin());
+ it != lists_.end(); ++it) {
+ result.push_back(it->first);
+ }
+ return (result);
+ }
+ isc::util::thread::Mutex& getClientListMutex() const {
+ return (mutex_);
+ }
+protected:
+ DatasrcConfigTest() :
+ session(ElementPtr(new ListElement), ElementPtr(new ListElement),
+ ElementPtr(new ListElement)),
+ specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec")
+ {
+ initSession();
+ }
+ void initSession() {
+ session.getMessages()->add(createAnswer());
+ mccs.reset(new ModuleCCSession(specfile, session, NULL, NULL, false,
+ false));
+ }
+ void TearDown() {
+ // Make sure no matter what we did, it is cleaned up. Also check
+ // we really have subscribed to the configuration, and after removing
+ // it we actually cancel it.
+ EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
+ mccs->removeRemoteConfig("data_sources");
+ EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
+ }
+ void SetUp() {
+ session.getMessages()->
+ add(createAnswer(0,
+ moduleSpecFromFile(string(PLUGIN_DATA_PATH) +
+ "/datasrc.spec").
+ getFullSpec()));
+ session.getMessages()->add(createAnswer(0,
+ ElementPtr(new MapElement)));
+ mccs->addRemoteConfig("data_sources",
+ boost::bind(datasrcConfigHandler,
+ this, _1, _2, _3), false);
+ }
+ ElementPtr buildConfig(const string& config) const {
+ const ElementPtr internal(Element::fromJSON(config));
+ const ElementPtr external(Element::fromJSON("{\"version\": 1}"));
+ external->set("classes", internal);
+ return (external);
+ }
+ void initializeINList() {
+ const ConstElementPtr
+ config(buildConfig("{\"IN\": [{\"type\": \"xxx\"}]}"));
+ session.addMessage(createCommand("config_update", config),
+ "data_sources", "*");
+ mccs->checkCommand();
+ // Check it called the correct things (check that there's no IN yet and
+ // set a new one.
+ EXPECT_EQ("get IN\nset IN xxx\n", log_);
+ EXPECT_EQ(1, lists_.size());
+ }
+ FakeSession session;
+ auto_ptr<ModuleCCSession> mccs;
+ const string specfile;
+ std::map<RRClass, ListPtr> lists_;
+ string log_;
+ mutable isc::util::thread::Mutex mutex_;
+};
+
+// Push there a configuration with a single list.
+TEST_F(DatasrcConfigTest, createList) {
+ initializeINList();
+}
+
+TEST_F(DatasrcConfigTest, modifyList) {
+ // First, initialize the list
+ initializeINList();
+ // And now change the configuration of the list
+ const ElementPtr
+ config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}]}"));
+ session.addMessage(createCommand("config_update", config), "data_sources",
+ "*");
+ log_ = "";
+ mccs->checkCommand();
+ // This one does not set
+ EXPECT_EQ("get IN\n", log_);
+ // But this should contain the yyy configuration
+ EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+ EXPECT_EQ(1, lists_.size());
+}
+
+// Check we can have multiple lists at once
+TEST_F(DatasrcConfigTest, multiple) {
+ const ElementPtr
+ config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}], "
+ "\"CH\": [{\"type\": \"xxx\"}]}"));
+ session.addMessage(createCommand("config_update", config), "data_sources",
+ "*");
+ mccs->checkCommand();
+ // We have set commands for both classes.
+ EXPECT_EQ("get CH\nset CH xxx\nget IN\nset IN yyy\n", log_);
+ // We should have both there
+ EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+ EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
+ EXPECT_EQ(2, lists_.size());
+}
+
+// Check we can add another one later and the old one does not get
+// overwritten.
+//
+// It's almost like above, but we initialize first with single-list
+// config.
+TEST_F(DatasrcConfigTest, updateAdd) {
+ initializeINList();
+ const ElementPtr
+ config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}], "
+ "\"CH\": [{\"type\": \"xxx\"}]}"));
+ session.addMessage(createCommand("config_update", config), "data_sources",
+ "*");
+ log_ = "";
+ mccs->checkCommand();
+ // The CH is set, IN not
+ EXPECT_EQ("get CH\nset CH xxx\nget IN\n", log_);
+ // But this should contain the yyy configuration
+ EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
+ EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+ EXPECT_EQ(2, lists_.size());
+}
+
+// We delete a class list in this test.
+TEST_F(DatasrcConfigTest, updateDelete) {
+ initializeINList();
+ const ElementPtr
+ config(buildConfig("{}"));
+ session.addMessage(createCommand("config_update", config), "data_sources",
+ "*");
+ log_ = "";
+ mccs->checkCommand();
+ EXPECT_EQ("get IN\nset IN \n", log_);
+ EXPECT_FALSE(lists_[RRClass::IN()]);
+ // In real auth server, the NULL one would be removed. However, we just
+ // store it, so the IN bucket is still in there. This checks there's nothing
+ // else.
+ EXPECT_EQ(1, lists_.size());
+}
+
+// Check that we can rollback an addition if something else fails
+TEST_F(DatasrcConfigTest, rollbackAddition) {
+ initializeINList();
+ // The configuration is wrong. However, the CH one will get done first.
+ const ElementPtr
+ config(buildConfig("{\"IN\": [{\"type\": 13}], "
+ "\"CH\": [{\"type\": \"xxx\"}]}"));
+ session.addMessage(createCommand("config_update", config), "data_sources",
+ "*");
+ log_ = "";
+ // It does not throw, as it is handled in the ModuleCCSession.
+ // Throwing from the reconfigure is checked in other tests.
+ EXPECT_NO_THROW(mccs->checkCommand());
+ // Anyway, the result should not contain CH now and the original IN should
+ // be there.
+ EXPECT_EQ("xxx", lists_[RRClass::IN()]->getConf());
+ EXPECT_FALSE(lists_[RRClass::CH()]);
+}
+
+// Check that we can rollback a deletion if something else fails
+TEST_F(DatasrcConfigTest, rollbackDeletion) {
+ initializeINList();
+ // Put the CH there
+ const ElementPtr
+ config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
+ "\"CH\": [{\"type\": \"xxx\"}]}"));
+ testConfigureDataSource(*this, config1);
+ const ElementPtr
+ config2(Element::fromJSON("{\"IN\": [{\"type\": 13}]}"));
+ // This would delete CH. However, the IN one fails.
+ // As the deletions happen after the additions/settings
+ // and there's no known way to cause an exception during the
+ // deletions, it is not a true rollback, but the result should
+ // be the same.
+ EXPECT_THROW(testConfigureDataSource(*this, config2), TypeError);
+ EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+ EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
+}
+
+// Check that we can roll back configuration change if something
+// fails later on.
+TEST_F(DatasrcConfigTest, rollbackConfiguration) {
+ initializeINList();
+ // Put the CH there
+ const ElementPtr
+ config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
+ "\"CH\": [{\"type\": \"xxx\"}]}"));
+ testConfigureDataSource(*this, config1);
+ // Now, the CH happens first. But nevertheless, it should be
+ // restored to the previoeus version.
+ const ElementPtr
+ config2(Element::fromJSON("{\"IN\": [{\"type\": 13}], "
+ "\"CH\": [{\"type\": \"yyy\"}]}"));
+ EXPECT_THROW(testConfigureDataSource(*this, config2), TypeError);
+ EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
+ EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
+}
+
+}
diff --git a/src/bin/auth/tests/datasrc_configurator_unittest.cc b/src/bin/auth/tests/datasrc_configurator_unittest.cc
deleted file mode 100644
index f294536..0000000
--- a/src/bin/auth/tests/datasrc_configurator_unittest.cc
+++ /dev/null
@@ -1,299 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <auth/datasrc_configurator.h>
-
-#include <config/tests/fake_session.h>
-#include <config/ccsession.h>
-#include <util/threads/lock.h>
-
-#include <gtest/gtest.h>
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <memory>
-
-using namespace isc;
-using namespace isc::cc;
-using namespace isc::config;
-using namespace isc::data;
-using namespace isc::dns;
-using namespace std;
-using namespace boost;
-
-namespace {
-
-class DatasrcConfiguratorTest;
-
-class FakeList {
-public:
- FakeList(const RRClass&) :
- configuration_(new ListElement)
- {}
- void configure(const ConstElementPtr& configuration, bool allow_cache) {
- EXPECT_TRUE(allow_cache);
- conf_ = configuration->get(0)->get("type")->stringValue();
- configuration_ = configuration;
- }
- const string& getConf() const {
- return (conf_);
- }
- ConstElementPtr getConfiguration() const {
- return (configuration_);
- }
-private:
- string conf_;
- ConstElementPtr configuration_;
-};
-
-typedef shared_ptr<FakeList> ListPtr;
-
-void
-testConfigureDataSource(DatasrcConfiguratorTest& test,
- const isc::data::ConstElementPtr& config)
-{
- // We use the test fixture for the Server type. This makes it possible
- // to easily fake all needed methods and look that they were called.
- configureDataSourceGeneric<DatasrcConfiguratorTest, FakeList>(test,
- config);
-}
-
-void
-datasrcConfigHandler(DatasrcConfiguratorTest* fake_server, const std::string&,
- isc::data::ConstElementPtr config,
- const isc::config::ConfigData&)
-{
- if (config->contains("classes")) {
- testConfigureDataSource(*fake_server, config->get("classes"));
- }
-}
-
-class DatasrcConfiguratorTest : public ::testing::Test {
-public:
- // These pretend to be the server
- ListPtr getClientList(const RRClass& rrclass) {
- log_ += "get " + rrclass.toText() + "\n";
- return (lists_[rrclass]);
- }
- void setClientList(const RRClass& rrclass, const ListPtr& list) {
- log_ += "set " + rrclass.toText() + " " +
- (list ? list->getConf() : "") + "\n";
- lists_[rrclass] = list;
- }
- vector<RRClass> getClientListClasses() const {
- vector<RRClass> result;
- for (std::map<RRClass, ListPtr>::const_iterator it(lists_.begin());
- it != lists_.end(); ++it) {
- result.push_back(it->first);
- }
- return (result);
- }
- isc::util::thread::Mutex& getClientListMutex() const {
- return (mutex_);
- }
-protected:
- DatasrcConfiguratorTest() :
- session(ElementPtr(new ListElement), ElementPtr(new ListElement),
- ElementPtr(new ListElement)),
- specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec")
- {
- initSession();
- }
- void initSession() {
- session.getMessages()->add(createAnswer());
- mccs.reset(new ModuleCCSession(specfile, session, NULL, NULL, false,
- false));
- }
- void TearDown() {
- // Make sure no matter what we did, it is cleaned up. Also check
- // we really have subscribed to the configuration, and after removing
- // it we actually cancel it.
- EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
- mccs->removeRemoteConfig("data_sources");
- EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
- }
- void SetUp() {
- session.getMessages()->
- add(createAnswer(0,
- moduleSpecFromFile(string(PLUGIN_DATA_PATH) +
- "/datasrc.spec").
- getFullSpec()));
- session.getMessages()->add(createAnswer(0,
- ElementPtr(new MapElement)));
- mccs->addRemoteConfig("data_sources",
- boost::bind(datasrcConfigHandler,
- this, _1, _2, _3), false);
- }
- ElementPtr buildConfig(const string& config) const {
- const ElementPtr internal(Element::fromJSON(config));
- const ElementPtr external(Element::fromJSON("{\"version\": 1}"));
- external->set("classes", internal);
- return (external);
- }
- void initializeINList() {
- const ConstElementPtr
- config(buildConfig("{\"IN\": [{\"type\": \"xxx\"}]}"));
- session.addMessage(createCommand("config_update", config),
- "data_sources", "*");
- mccs->checkCommand();
- // Check it called the correct things (check that there's no IN yet and
- // set a new one.
- EXPECT_EQ("get IN\nset IN xxx\n", log_);
- EXPECT_EQ(1, lists_.size());
- }
- FakeSession session;
- auto_ptr<ModuleCCSession> mccs;
- const string specfile;
- std::map<RRClass, ListPtr> lists_;
- string log_;
- mutable isc::util::thread::Mutex mutex_;
-};
-
-// Push there a configuration with a single list.
-TEST_F(DatasrcConfiguratorTest, createList) {
- initializeINList();
-}
-
-TEST_F(DatasrcConfiguratorTest, modifyList) {
- // First, initialize the list
- initializeINList();
- // And now change the configuration of the list
- const ElementPtr
- config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}]}"));
- session.addMessage(createCommand("config_update", config), "data_sources",
- "*");
- log_ = "";
- mccs->checkCommand();
- // This one does not set
- EXPECT_EQ("get IN\n", log_);
- // But this should contain the yyy configuration
- EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
- EXPECT_EQ(1, lists_.size());
-}
-
-// Check we can have multiple lists at once
-TEST_F(DatasrcConfiguratorTest, multiple) {
- const ElementPtr
- config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}], "
- "\"CH\": [{\"type\": \"xxx\"}]}"));
- session.addMessage(createCommand("config_update", config), "data_sources",
- "*");
- mccs->checkCommand();
- // We have set commands for both classes.
- EXPECT_EQ("get CH\nset CH xxx\nget IN\nset IN yyy\n", log_);
- // We should have both there
- EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
- EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
- EXPECT_EQ(2, lists_.size());
-}
-
-// Check we can add another one later and the old one does not get
-// overwritten.
-//
-// It's almost like above, but we initialize first with single-list
-// config.
-TEST_F(DatasrcConfiguratorTest, updateAdd) {
- initializeINList();
- const ElementPtr
- config(buildConfig("{\"IN\": [{\"type\": \"yyy\"}], "
- "\"CH\": [{\"type\": \"xxx\"}]}"));
- session.addMessage(createCommand("config_update", config), "data_sources",
- "*");
- log_ = "";
- mccs->checkCommand();
- // The CH is set, IN not
- EXPECT_EQ("get CH\nset CH xxx\nget IN\n", log_);
- // But this should contain the yyy configuration
- EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
- EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
- EXPECT_EQ(2, lists_.size());
-}
-
-// We delete a class list in this test.
-TEST_F(DatasrcConfiguratorTest, updateDelete) {
- initializeINList();
- const ElementPtr
- config(buildConfig("{}"));
- session.addMessage(createCommand("config_update", config), "data_sources",
- "*");
- log_ = "";
- mccs->checkCommand();
- EXPECT_EQ("get IN\nset IN \n", log_);
- EXPECT_FALSE(lists_[RRClass::IN()]);
- // In real auth server, the NULL one would be removed. However, we just
- // store it, so the IN bucket is still in there. This checks there's nothing
- // else.
- EXPECT_EQ(1, lists_.size());
-}
-
-// Check that we can rollback an addition if something else fails
-TEST_F(DatasrcConfiguratorTest, rollbackAddition) {
- initializeINList();
- // The configuration is wrong. However, the CH one will get done first.
- const ElementPtr
- config(buildConfig("{\"IN\": [{\"type\": 13}], "
- "\"CH\": [{\"type\": \"xxx\"}]}"));
- session.addMessage(createCommand("config_update", config), "data_sources",
- "*");
- log_ = "";
- // It does not throw, as it is handled in the ModuleCCSession.
- // Throwing from the reconfigure is checked in other tests.
- EXPECT_NO_THROW(mccs->checkCommand());
- // Anyway, the result should not contain CH now and the original IN should
- // be there.
- EXPECT_EQ("xxx", lists_[RRClass::IN()]->getConf());
- EXPECT_FALSE(lists_[RRClass::CH()]);
-}
-
-// Check that we can rollback a deletion if something else fails
-TEST_F(DatasrcConfiguratorTest, rollbackDeletion) {
- initializeINList();
- // Put the CH there
- const ElementPtr
- config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
- "\"CH\": [{\"type\": \"xxx\"}]}"));
- testConfigureDataSource(*this, config1);
- const ElementPtr
- config2(Element::fromJSON("{\"IN\": [{\"type\": 13}]}"));
- // This would delete CH. However, the IN one fails.
- // As the deletions happen after the additions/settings
- // and there's no known way to cause an exception during the
- // deletions, it is not a true rollback, but the result should
- // be the same.
- EXPECT_THROW(testConfigureDataSource(*this, config2), TypeError);
- EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
- EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
-}
-
-// Check that we can roll back configuration change if something
-// fails later on.
-TEST_F(DatasrcConfiguratorTest, rollbackConfiguration) {
- initializeINList();
- // Put the CH there
- const ElementPtr
- config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
- "\"CH\": [{\"type\": \"xxx\"}]}"));
- testConfigureDataSource(*this, config1);
- // Now, the CH happens first. But nevertheless, it should be
- // restored to the previoeus version.
- const ElementPtr
- config2(Element::fromJSON("{\"IN\": [{\"type\": 13}], "
- "\"CH\": [{\"type\": \"yyy\"}]}"));
- EXPECT_THROW(testConfigureDataSource(*this, config2), TypeError);
- EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
- EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
-}
-
-}
More information about the bind10-changes
mailing list