Commit cb814de4 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2862] Put the command into the queue

parent 22880765
......@@ -400,6 +400,36 @@ public:
sendCommand(datasrc_clientmgr_internal::LOADZONE, args, callback);
}
void segmentInfoUpdate(const data::ConstElementPtr& args,
const datasrc_clientmgr_internal::FinishedCallback&
callback =
datasrc_clientmgr_internal::FinishedCallback()) {
// Some minimal validation
if (!args) {
isc_throw(CommandError, "segmentInfoUpdate argument empty");
}
if (args->getType() != isc::data::Element::map) {
isc_throw(CommandError, "segmentInfoUpdate argument not a map");
}
const char* params[] = {
"data-source-name",
"data-source-class",
"segment-params",
NULL
};
for (const char** param = params; *param; ++param) {
if (!args->contains(*param)) {
isc_throw(CommandError,
"segmentInfoUpdate argument has no '" << param <<
"' value");
}
}
sendCommand(datasrc_clientmgr_internal::SEGMENT_INFO_UPDATE, args,
callback);
}
private:
// This is expected to be called at the end of the destructor. It
// actually does nothing, but provides a customization point for
......
......@@ -248,6 +248,30 @@ TEST(DataSrcClientsMgrTest, reload) {
EXPECT_EQ(3, FakeDataSrcClientsBuilder::command_queue->size());
}
TEST(DataSrcClientsMgrTest, segmentUpdate) {
TestDataSrcClientsMgr mgr;
EXPECT_TRUE(FakeDataSrcClientsBuilder::started);
EXPECT_TRUE(FakeDataSrcClientsBuilder::command_queue->empty());
isc::data::ElementPtr args =
isc::data::Element::fromJSON("{\"data-source-class\": \"IN\","
" \"data-source-name\": \"sqlite3\","
" \"segment-params\": {}}");
mgr.segmentInfoUpdate(args);
EXPECT_EQ(1, FakeDataSrcClientsBuilder::command_queue->size());
// Some invalid inputs
EXPECT_THROW(mgr.segmentInfoUpdate(isc::data::Element::fromJSON(
"{\"data-source-class\": \"IN\","
" \"data-source-name\": \"sqlite3\"}")), CommandError);
EXPECT_THROW(mgr.segmentInfoUpdate(isc::data::Element::fromJSON(
"{\"data-source-name\": \"sqlite3\","
" \"segment-params\": {}}")), CommandError);
EXPECT_THROW(mgr.segmentInfoUpdate(isc::data::Element::fromJSON(
"{\"data-source-class\": \"IN\","
" \"segment-params\": {}}")), CommandError);
EXPECT_EQ(1, FakeDataSrcClientsBuilder::command_queue->size());
}
void
callback(bool* called, int *tag_target, int tag_value) {
*called = true;
......
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