From: Michal 'vorner' Vaner Date: Mon, 25 Jun 2012 18:11:43 +0000 (+0200) Subject: [1976] Hold a cache in the DataSourceInfo X-Git-Tag: trac2351_base~196^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98d893ecdff8ee42d270a9548f91fe3dffdf6c43;p=thirdparty%2Fkea.git [1976] Hold a cache in the DataSourceInfo It is not created now, but there's the place to put it. --- diff --git a/src/lib/datasrc/client_list.cc b/src/lib/datasrc/client_list.cc index 549b2168fe..d1d47f82cc 100644 --- a/src/lib/datasrc/client_list.cc +++ b/src/lib/datasrc/client_list.cc @@ -15,6 +15,7 @@ #include "client_list.h" #include "client.h" #include "factory.h" +#include "memory_datasrc.h" #include #include @@ -25,6 +26,17 @@ using namespace std; namespace isc { namespace datasrc { +ConfigurableClientList::DataSourceInfo::DataSourceInfo( + DataSourceClient* data_src_client, + const DataSourceClientContainerPtr& container, bool hasCache) : + data_src_client_(data_src_client), + container_(container) +{ + if (hasCache) { + cache_.reset(new InMemoryClient); + } +} + void ConfigurableClientList::configure(const Element& config, bool) { // TODO: Implement the cache @@ -50,7 +62,8 @@ ConfigurableClientList::configure(const Element& config, bool) { const DataSourcePair ds(this->getDataSourceClient(type, paramConf)); // And put it into the vector - new_data_sources.push_back(DataSourceInfo(ds.first, ds.second)); + new_data_sources.push_back(DataSourceInfo(ds.first, ds.second, + false)); } // If everything is OK up until now, we have the new configuration // ready. So just put it there and let the old one die when we exit diff --git a/src/lib/datasrc/client_list.h b/src/lib/datasrc/client_list.h index 599dca8217..1b59b684ea 100644 --- a/src/lib/datasrc/client_list.h +++ b/src/lib/datasrc/client_list.h @@ -33,6 +33,7 @@ typedef boost::shared_ptr DataSourceClientPtr; class DataSourceClientContainer; typedef boost::shared_ptr DataSourceClientContainerPtr; +class InMemoryClient; /// \brief The list of data source clients. /// @@ -231,12 +232,11 @@ public: data_src_client_(NULL) {} DataSourceInfo(DataSourceClient* data_src_client, - const DataSourceClientContainerPtr& container) : - data_src_client_(data_src_client), - container_(container) - {} + const DataSourceClientContainerPtr& container, + bool hasCache); DataSourceClient* data_src_client_; DataSourceClientContainerPtr container_; + boost::shared_ptr cache_; }; /// \brief The collection of data sources. diff --git a/src/lib/datasrc/tests/client_list_unittest.cc b/src/lib/datasrc/tests/client_list_unittest.cc index ae22470e78..608ccc7706 100644 --- a/src/lib/datasrc/tests/client_list_unittest.cc +++ b/src/lib/datasrc/tests/client_list_unittest.cc @@ -175,7 +175,7 @@ public: ds(new MockDataSourceClient(ds_zones[i])); ds_.push_back(ds); ds_info_.push_back(ConfigurableClientList::DataSourceInfo(ds.get(), - DataSourceClientContainerPtr())); + DataSourceClientContainerPtr(), false)); } } // Check the positive result is as we expect it. @@ -220,7 +220,8 @@ public: FAIL() << "Unknown configuration index " << index; } } - void checkDS(size_t index, const string& type, const string& params) const + void checkDS(size_t index, const string& type, const string& params, + bool cache) const { ASSERT_GT(list_->getDataSources().size(), index); MockDataSourceClient* ds(dynamic_cast( @@ -230,6 +231,8 @@ public: ASSERT_NE(ds, static_cast(NULL)); EXPECT_EQ(type, ds->type_); EXPECT_TRUE(Element::fromJSON(params)->equals(*ds->configuration_)); + EXPECT_EQ(cache, list_->getDataSources()[index].cache_ != + shared_ptr()); } shared_ptr list_; const ClientList::FindResult negativeResult_; @@ -370,8 +373,8 @@ TEST_F(ListTest, configureMulti) { )); list_->configure(*elem, true); EXPECT_EQ(2, list_->getDataSources().size()); - checkDS(0, "type1", "{}"); - checkDS(1, "type2", "{}"); + checkDS(0, "type1", "{}", false); + checkDS(1, "type2", "{}", false); } // Check we can pass whatever we want to the params @@ -396,7 +399,7 @@ TEST_F(ListTest, configureParams) { "}]")); list_->configure(*elem, true); EXPECT_EQ(1, list_->getDataSources().size()); - checkDS(0, "t", *param); + checkDS(0, "t", *param, false); } } @@ -423,14 +426,14 @@ TEST_F(ListTest, wrongConfig) { }; // Put something inside to see it survives the exception list_->configure(*config_elem_, true); - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); for (const char** config(configs); *config; ++config) { SCOPED_TRACE(*config); ConstElementPtr elem(Element::fromJSON(*config)); EXPECT_THROW(list_->configure(*elem, true), ConfigurableClientList::ConfigurationError); // Still untouched - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); EXPECT_EQ(1, list_->getDataSources().size()); } } @@ -443,18 +446,18 @@ TEST_F(ListTest, defaults) { "}]")); list_->configure(*elem, true); EXPECT_EQ(1, list_->getDataSources().size()); - checkDS(0, "type1", "null"); + checkDS(0, "type1", "null", false); } // Check we can call the configure multiple times, to change the configuration TEST_F(ListTest, reconfigure) { ConstElementPtr empty(new ListElement); list_->configure(*config_elem_, true); - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); list_->configure(*empty, true); EXPECT_TRUE(list_->getDataSources().empty()); list_->configure(*config_elem_, true); - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); } // Make sure the data source error exception from the factory is propagated @@ -464,9 +467,9 @@ TEST_F(ListTest, dataSrcError) { " \"type\": \"error\"" "}]")); list_->configure(*config_elem_, true); - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); EXPECT_THROW(list_->configure(*elem, true), DataSourceError); - checkDS(0, "test_type", "{}"); + checkDS(0, "test_type", "{}", false); } }