#include "client_list.h"
#include "client.h"
#include "factory.h"
+#include "memory_datasrc.h"
#include <memory>
#include <boost/foreach.hpp>
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
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
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.
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<MockDataSourceClient*>(
ASSERT_NE(ds, static_cast<const MockDataSourceClient*>(NULL));
EXPECT_EQ(type, ds->type_);
EXPECT_TRUE(Element::fromJSON(params)->equals(*ds->configuration_));
+ EXPECT_EQ(cache, list_->getDataSources()[index].cache_ !=
+ shared_ptr<InMemoryClient>());
}
shared_ptr<TestedList> list_;
const ClientList::FindResult negativeResult_;
));
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
"}]"));
list_->configure(*elem, true);
EXPECT_EQ(1, list_->getDataSources().size());
- checkDS(0, "t", *param);
+ checkDS(0, "t", *param, false);
}
}
};
// 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());
}
}
"}]"));
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
" \"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);
}
}