isc::data::ConstElementPtr
Observation::getJSON() const {
- ElementPtr entry = isc::data::Element::createList(); // multiple observations
+ //ElementPtr entry = isc::data::Element::createList(); // multiple observations
+ ElementPtr list = isc::data::Element::createList(); // multiple observations
+ ElementPtr entry;
ElementPtr value;
ElementPtr timestamp;
// Iteration over all elements in the list
// and adding alternately value and timestamp to the entry
for (std::list<IntegerSample>::iterator it = s.begin(); it != s.end(); ++it) {
+ entry = isc::data::Element::createList();
value = isc::data::Element::create(static_cast<int64_t>((*it).first));
timestamp = isc::data::Element::create(isc::util::ptimeToText((*it).second));
entry->add(value);
entry->add(timestamp);
+
+ list->add(entry);
}
break;
}
// Iteration over all elements in the list
// and adding alternately value and timestamp to the entry
for (std::list<FloatSample>::iterator it = s.begin(); it != s.end(); ++it) {
+ entry = isc::data::Element::createList();
value = isc::data::Element::create((*it).first);
timestamp = isc::data::Element::create(isc::util::ptimeToText((*it).second));
entry->add(value);
entry->add(timestamp);
+
+ list->add(entry);
}
break;
}
// Iteration over all elements in the list
// and adding alternately value and timestamp to the entry
for (std::list<DurationSample>::iterator it = s.begin(); it != s.end(); ++it) {
+ entry = isc::data::Element::createList();
value = isc::data::Element::create(isc::util::durationToText((*it).first));
timestamp = isc::data::Element::create(isc::util::ptimeToText((*it).second));
entry->add(value);
entry->add(timestamp);
+
+ list->add(entry);
}
break;
}
// Iteration over all elements in the list
// and adding alternately value and timestamp to the entry
for (std::list<StringSample>::iterator it = s.begin(); it != s.end(); ++it) {
+ entry = isc::data::Element::createList();
value = isc::data::Element::create((*it).first);
timestamp = isc::data::Element::create(isc::util::ptimeToText((*it).second));
entry->add(value);
entry->add(timestamp);
+
+ list->add(entry);
}
break;
}
<< typeToText(type_));
};
- ElementPtr list = isc::data::Element::createList(); // multiple observations
- list->add(entry);
-
return (list);
}
/// for details.
TEST_F(ObservationTest, integerToJSON) {
// String which contains first added sample
- std::string first_sample = ", 1234, \"" +
+ std::string first_sample = ", [ 1234, \"" +
isc::util::ptimeToText(a.getInteger().second) + "\" ] ]";
a.setValue(static_cast<int64_t>(1234));
std::string exp = "[ [ 1234, \"" +
- isc::util::ptimeToText(a.getInteger().second) + "\"" + first_sample;
+ isc::util::ptimeToText(a.getInteger().second) + "\" ]" + first_sample;
std::cout << a.getJSON()->str() << std::endl;
EXPECT_EQ(exp, a.getJSON()->str());
/// for details.
TEST_F(ObservationTest, floatToJSON) {
// String which contains first added sample
- std::string first_sample = ", 12.34, \"" +
+ std::string first_sample = ", [ 12.34, \"" +
isc::util::ptimeToText(b.getFloat().second) + "\" ] ]";
// Let's use a value that converts easily to floating point.
b.setValue(1234.5);
std::string exp = "[ [ 1234.5, \"" +
- isc::util::ptimeToText(b.getFloat().second) + "\"" + first_sample;
+ isc::util::ptimeToText(b.getFloat().second) + "\" ]" + first_sample;
std::cout << b.getJSON()->str() << std::endl;
EXPECT_EQ(exp, b.getJSON()->str());
// details.
TEST_F(ObservationTest, durationToJSON) {
// String which contains first added sample
- std::string first_sample = ", \"01:02:03.000004\", \"" +
+ std::string first_sample = ", [ \"01:02:03.000004\", \"" +
isc::util::ptimeToText(c.getDuration().second) + "\" ] ]";
// 1 hour 2 minutes 3 seconds and 4 milliseconds
c.setValue(time_duration(1, 2, 3, 4));
std::string exp = "[ [ \"01:02:03.000004\", \"" +
- isc::util::ptimeToText(c.getDuration().second) + "\"" + first_sample;
+ isc::util::ptimeToText(c.getDuration().second) + "\" ]" + first_sample;
std::cout << c.getJSON()->str() << std::endl;
EXPECT_EQ(exp, c.getJSON()->str());
// for details.
TEST_F(ObservationTest, stringToJSON) {
// String which contains first added sample
- std::string first_sample = ", \"1234\", \"" +
+ std::string first_sample = ", [ \"1234\", \"" +
isc::util::ptimeToText(d.getString().second) + "\" ] ]";
d.setValue("Lorem ipsum dolor sit amet");
std::string exp = "[ [ \"Lorem ipsum dolor sit amet\", \"" +
- isc::util::ptimeToText(d.getString().second) + "\"" + first_sample;
+ isc::util::ptimeToText(d.getString().second) + "\" ]" + first_sample;
std::cout << d.getJSON()->str() << std::endl;
EXPECT_EQ(exp, d.getJSON()->str());
StatsMgr::instance().setValue("delta", "Lorem");
// The string's representation of firstly added statistics
- std::string alpha_first = ", 1234, \"" +
+ std::string alpha_first = ", [ 1234, \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("alpha")
->getInteger().second) + "\" ] ]";
- std::string beta_first = ", 12.34, \"" +
+ std::string beta_first = ", [ 12.34, \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("beta")
->getFloat().second) + "\" ] ]";
- std::string gamma_first = ", \"01:02:03.000004\", \"" +
+ std::string gamma_first = ", [ \"01:02:03.000004\", \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("gamma")
->getDuration().second) + "\" ] ]";
- std::string delta_first = ", \"Lorem\", \"" +
+ std::string delta_first = ", [ \"Lorem\", \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("delta")
->getString().second) + "\" ] ]";
std::string exp_str_alpha = "[ [ 6912, \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("alpha")
- ->getInteger().second) + "\"" + alpha_first;
+ ->getInteger().second) + "\" ]" + alpha_first;
std::string exp_str_beta = "[ [ 69.12, \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("beta")
- ->getFloat().second) + "\"" + beta_first;
+ ->getFloat().second) + "\" ]" + beta_first;
std::string exp_str_gamma = "[ [ \"06:08:10.000012\", \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("gamma")
- ->getDuration().second) + "\"" + gamma_first;
+ ->getDuration().second) + "\" ]" + gamma_first;
std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" +
isc::util::ptimeToText(StatsMgr::instance().getObservation("delta")
- ->getString().second) + "\"" + delta_first;
+ ->getString().second) + "\" ]" + delta_first;
// Check that individual stats are reported properly
EXPECT_EQ("{ \"alpha\": " + exp_str_alpha + " }", rep_alpha->str());