]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2044] Create the cache when requested
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Mon, 25 Jun 2012 18:37:12 +0000 (20:37 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Mon, 25 Jun 2012 18:37:12 +0000 (20:37 +0200)
But it is not yet filled up

src/lib/datasrc/client_list.cc
src/lib/datasrc/tests/client_list_unittest.cc

index d1d47f82cc7298ece12c59fc31e2524ec260fa2c..dd39c3b5b0df033a93af216a89a9bbd326b83d5e 100644 (file)
@@ -38,8 +38,7 @@ ConfigurableClientList::DataSourceInfo::DataSourceInfo(
 }
 
 void
-ConfigurableClientList::configure(const Element& config, bool) {
-    // TODO: Implement the cache
+ConfigurableClientList::configure(const Element& config, bool allowCache) {
     // TODO: Implement recycling from the old configuration.
     size_t i(0); // Outside of the try to be able to access it in the catch
     try {
@@ -61,9 +60,12 @@ ConfigurableClientList::configure(const Element& config, bool) {
             // Ask the factory to create the data source for us
             const DataSourcePair ds(this->getDataSourceClient(type,
                                                               paramConf));
+            const bool wantCache(allowCache &&
+                                 dconf->contains("cache-enable") &&
+                                 dconf->get("cache-enable")->boolValue());
             // And put it into the vector
             new_data_sources.push_back(DataSourceInfo(ds.first, ds.second,
-                                                      false));
+                                                      wantCache));
         }
         // 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
index 608ccc7706ce6dfca5a6281b176af0fbe5a0f389..3d55c49e00a20b37b78cb5e4a52f4315592f4abc 100644 (file)
@@ -166,7 +166,6 @@ public:
         config_elem_(Element::fromJSON("["
             "{"
             "   \"type\": \"test_type\","
-            "   \"cache\": \"off\","
             "   \"params\": {}"
             "}]"))
     {
@@ -472,4 +471,48 @@ TEST_F(ListTest, dataSrcError) {
     checkDS(0, "test_type", "{}", false);
 }
 
+// Check we can get the cache
+TEST_F(ListTest, configureCacheEmpty) {
+    ConstElementPtr elem(Element::fromJSON("["
+        "{"
+        "   \"type\": \"type1\","
+        "   \"cache-enable\": true,"
+        "   \"cache-zones\": [],"
+        "   \"params\": {}"
+        "},"
+        "{"
+        "   \"type\": \"type2\","
+        "   \"cache-enable\": false,"
+        "   \"cache-zones\": [],"
+        "   \"params\": {}"
+        "}]"
+    ));
+    list_->configure(*elem, true);
+    EXPECT_EQ(2, list_->getDataSources().size());
+    checkDS(0, "type1", "{}", true);
+    checkDS(1, "type2", "{}", false);
+}
+
+// But no cache if we disallow it globally
+TEST_F(ListTest, configureCacheDisabled) {
+    ConstElementPtr elem(Element::fromJSON("["
+        "{"
+        "   \"type\": \"type1\","
+        "   \"cache-enable\": true,"
+        "   \"cache-zones\": [],"
+        "   \"params\": {}"
+        "},"
+        "{"
+        "   \"type\": \"type2\","
+        "   \"cache-enable\": false,"
+        "   \"cache-zones\": [],"
+        "   \"params\": {}"
+        "}]"
+    ));
+    list_->configure(*elem, false);
+    EXPECT_EQ(2, list_->getDataSources().size());
+    checkDS(0, "type1", "{}", false);
+    checkDS(1, "type2", "{}", false);
+}
+
 }