Browse Source

added a trivial method IntervalTimer::getInterval() for the convenient of
other tests.

JINMEI Tatuya 14 years ago
parent
commit
d55bcb9c5f

+ 5 - 0
src/bin/auth/auth.spec.pre.in

@@ -52,6 +52,11 @@
 	    }
 	  ]
         }
+      },
+      { "item_name": "statistics-interval",
+        "item_type": "integer",
+        "item_optional": true,
+        "item_default": 60
       }
     ],
     "commands": [

+ 14 - 0
src/bin/auth/config.cc

@@ -169,6 +169,18 @@ MemoryDatasourceConfig::build(ConstElementPtr config_value) {
     }
 }
 
+class StatisticsIntervalConfig : public AuthConfigParser {
+public:
+    StatisticsIntervalConfig(AuthSrv& server) :
+        server_(server)
+    {}
+    //virtual void build(ConstElementPtr config_value);
+    virtual void build(ConstElementPtr) {}
+    virtual void commit() {}
+private:
+    AuthSrv& server_;
+};
+
 /// A special parser for testing: it throws from commit() despite the
 /// suggested convention of the class interface.
 class ThrowerCommitConfig : public AuthConfigParser {
@@ -191,6 +203,8 @@ createAuthConfigParser(AuthSrv& server, const std::string& config_id,
     // that it can be dynamically customized.
     if (config_id == "datasources") {
         return (new DatasourcesConfig(server));
+    } else if (config_id == "statistics-interval") {
+        return (new StatisticsIntervalConfig(server));
     } else if (internal && config_id == "datasources/memory") {
         return (new MemoryDatasourceConfig(server));
     } else if (config_id == "_commit_throw") {

+ 19 - 0
src/bin/auth/tests/config_unittest.cc

@@ -320,4 +320,23 @@ TEST_F(MemoryDatasrcConfigTest, badDatasrcType) {
                                                  " {\"type\": \"memory\"}]")),
                  AuthConfigError);
 }
+
+class StatisticsIntervalConfigTest : public AuthConfigTest {
+protected:
+    StatisticsIntervalConfigTest() :
+        parser(createAuthConfigParser(server, "statistics-interval"))
+    {
+        server.setStatisticsSession(&statistics_session);
+    }
+    ~StatisticsIntervalConfigTest() {
+        delete parser;
+    }
+    MockSession statistics_session;
+    AuthConfigParser* parser;
+};
+
+TEST_F(StatisticsIntervalConfigTest, setInterval) {
+    parser->build(Element::fromJSON("1"));
+    parser->commit();
+}
 }

+ 6 - 0
src/lib/asiolink/asiolink.cc

@@ -386,6 +386,7 @@ public:
     void setupTimer(const IntervalTimer::Callback& cbfunc,
                     const uint32_t interval);
     void callback(const asio::error_code& error);
+    uint32_t getInterval() const { return (interval_); }
 private:
     // a function to update timer_ when it expires
     void updateTimer();
@@ -461,4 +462,9 @@ IntervalTimer::setupTimer(const Callback& cbfunc, const uint32_t interval) {
     return (impl_->setupTimer(cbfunc, interval));
 }
 
+uint32_t
+IntervalTimer::getInterval() const {
+    return (impl_->getInterval());
+}
+
 }

+ 4 - 0
src/lib/asiolink/asiolink.h

@@ -657,6 +657,10 @@ public:
     /// \throw isc::Unexpected ASIO library error
     ///
     void setupTimer(const Callback& cbfunc, const uint32_t interval);
+
+    /// TBD
+    uint32_t getInterval() const;
+
 private:
     IntervalTimerImpl* impl_;
 };

+ 1 - 0
src/lib/asiolink/tests/asiolink_unittest.cc

@@ -864,6 +864,7 @@ TEST_F(IntervalTimerTest, startIntervalTimer) {
     start = boost::posix_time::microsec_clock::universal_time();
     // setup timer
     itimer.setupTimer(TimerCallBack(this), 1);
+    EXPECT_EQ(1, itimer.getInterval());
     io_service_.run();
     // reaches here after timer expired
     // delta: difference between elapsed time and 1 second