Commit d55bcb9c authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

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

other tests.
parent 692e3a1c
......@@ -52,6 +52,11 @@
}
]
}
},
{ "item_name": "statistics-interval",
"item_type": "integer",
"item_optional": true,
"item_default": 60
}
],
"commands": [
......
......@@ -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") {
......
......@@ -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();
}
}
......@@ -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());
}
}
......@@ -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_;
};
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment