Browse Source

[2853] Update getStatus() C++ method

* Return the correct segment type
* Return SEGMENT_WAITING when the segment is not usable
* Update tests
Mukund Sivaraman 12 years ago
parent
commit
fbe7def71c
2 changed files with 36 additions and 5 deletions
  1. 16 5
      src/lib/datasrc/client_list.cc
  2. 20 0
      src/lib/datasrc/tests/client_list_unittest.cc

+ 16 - 5
src/lib/datasrc/client_list.cc

@@ -410,11 +410,22 @@ vector<DataSourceStatus>
 ConfigurableClientList::getStatus() const {
     vector<DataSourceStatus> result;
     BOOST_FOREACH(const DataSourceInfo& info, data_sources_) {
-        // TODO: Once we support mapped cache, decide when we need the
-        // SEGMENT_WAITING.
-        result.push_back(DataSourceStatus(info.name_, info.cache_ ?
-                                          SEGMENT_INUSE : SEGMENT_UNUSED,
-                                          "local"));
+        MemorySegmentState segment_state = SEGMENT_UNUSED;
+        if (info.cache_) {
+            if (info.ztable_segment_ && info.ztable_segment_->isUsable()) {
+                segment_state = SEGMENT_INUSE;
+            } else {
+                segment_state = SEGMENT_WAITING;
+            }
+        }
+
+        std::string segment_type;
+        if (info.ztable_segment_) {
+            segment_type = info.ztable_segment_->getImplType();
+        }
+
+        result.push_back(DataSourceStatus(info.name_, segment_state,
+                                          segment_type));
     }
     return (result);
 }

+ 20 - 0
src/lib/datasrc/tests/client_list_unittest.cc

@@ -116,6 +116,7 @@ public:
                        const std::string& datasrc_name,
                        ZoneTableSegment::MemorySegmentOpenMode mode,
                        ConstElementPtr config_params) = 0;
+    virtual std::string getType() = 0;
 };
 
 class ListTest : public ::testing::TestWithParam<SegmentType*> {
@@ -332,6 +333,9 @@ public:
                        ConstElementPtr) {
         // We must not call reset on local ZoneTableSegments.
     }
+    virtual std::string getType() {
+        return ("local");
+    }
 };
 
 LocalSegmentType local_segment_type;
@@ -360,6 +364,9 @@ public:
                        ConstElementPtr config_params) {
         list.resetMemorySegment(datasrc_name, mode, config_params);
     }
+    virtual std::string getType() {
+        return ("mapped");
+    }
 };
 
 MappedSegmentType mapped_segment_type;
@@ -1002,6 +1009,13 @@ ListTest::doReload(const Name& origin, const string& datasrc_name) {
 // Test we can reload a zone
 TEST_P(ListTest, reloadSuccess) {
     list_->configure(config_elem_zones_, true);
+
+    const vector<DataSourceStatus> statii_before(list_->getStatus());
+    ASSERT_EQ(1, statii_before.size());
+    EXPECT_EQ("test_type", statii_before[0].getName());
+    EXPECT_EQ(SEGMENT_UNUSED, statii_before[0].getSegmentState());
+    EXPECT_THROW(statii_before[0].getSegmentType(), isc::InvalidOperation);
+
     const Name name("example.org");
     prepareCache(0, name);
     // The cache currently contains a tweaked version of zone, which
@@ -1017,6 +1031,12 @@ TEST_P(ListTest, reloadSuccess) {
               list_->find(name).finder_->
                   find(Name("tstzonedata").concatenate(name),
                        RRType::A())->code);
+
+    const vector<DataSourceStatus> statii_after(list_->getStatus());
+    ASSERT_EQ(1, statii_after.size());
+    EXPECT_EQ("test_type", statii_after[0].getName());
+    EXPECT_EQ(SEGMENT_INUSE, statii_after[0].getSegmentState());
+    EXPECT_EQ(GetParam()->getType(), statii_after[0].getSegmentType());
 }
 
 // The cache is not enabled. The load should be rejected.