Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Added support to long long int injection (as influx supports 64 bits …
Browse files Browse the repository at this point in the history
…ints by default) (#48)
  • Loading branch information
jmsanchezff authored Jan 29, 2020
1 parent 1d069ff commit 2ab74d0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions include/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Point
Point&& addTag(std::string_view key, std::string_view value);

/// Adds filed
Point&& addField(std::string_view name, std::variant<int, std::string, double> value);
Point&& addField(std::string_view name, std::variant<int, long long int, std::string, double> value);

/// Generetes current timestamp
static auto getCurrentTimestamp() -> decltype(std::chrono::system_clock::now());
Expand All @@ -48,7 +48,7 @@ class Point

protected:
/// A value
std::variant<int, std::string, double> mValue;
std::variant<long long int, std::string, double> mValue;

/// A name
std::string mMeasurement;
Expand Down
3 changes: 2 additions & 1 deletion src/Point.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ Point::Point(const std::string& measurement) :
mFields = {};
}

Point&& Point::addField(std::string_view name, std::variant<int, std::string, double> value)
Point&& Point::addField(std::string_view name, std::variant<int, long long int, std::string, double> value)
{
std::stringstream convert;
if (!mFields.empty()) convert << ",";

convert << name << "=";
std::visit(overloaded {
[&convert](int value) { convert << value << 'i'; },
[&convert](long long int value) { convert << value << 'i'; },
[&convert](double value) { convert << value; },
[&convert](const std::string& value) { convert << '"' << value << '"'; },
}, value);
Expand Down
4 changes: 4 additions & 0 deletions test/testHttp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ BOOST_AUTO_TEST_CASE(write1)
.addField("value", 20)
.addTag("host", "localhost")
);

influxdb->write(Point{"test"}
.addField("value", 200LL)
.addTag("host", "localhost"));
}

} // namespace test
Expand Down
7 changes: 4 additions & 3 deletions test/testPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::vector<std::string> getVector(const Point& point)
BOOST_AUTO_TEST_CASE(test1)
{
auto point = Point{"test"}
.addField("value", 10);
.addField("value", 10LL);

auto result = getVector(point);

Expand All @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(test1)
BOOST_AUTO_TEST_CASE(test2)
{
auto point = Point{"test"}
.addField("value", 10)
.addField("value", 10LL)
.addField("dvalue", 10.10);

auto result = getVector(point);
Expand All @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(test2)
BOOST_AUTO_TEST_CASE(test3)
{
auto point = Point{"test"}
.addField("value", 10)
.addField("value", 10LL)
.addField("dvalue", 10.10)
.addTag("tag", "tagval");

Expand All @@ -55,6 +55,7 @@ BOOST_AUTO_TEST_CASE(test4)
{
auto point = Point{"test"}
.addField("value", 10)
.addField("value", 100LL)
.setTimestamp(std::chrono::time_point<std::chrono::system_clock>(std::chrono::milliseconds(1572830914)));

auto result = getVector(point);
Expand Down
12 changes: 7 additions & 5 deletions test/testQuery.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ namespace test {
BOOST_AUTO_TEST_CASE(query1)
{
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
auto points = influxdb->query("SELECT * from test LIMIT 2");
BOOST_CHECK_EQUAL(points.front().getName(), "test");
BOOST_CHECK_EQUAL(points.back().getName(), "test");
BOOST_CHECK_EQUAL(points.front().getFields(), "value=10");
BOOST_CHECK_EQUAL(points.back().getFields(), "value=20");
auto points = influxdb->query("SELECT * from test LIMIT 3");
BOOST_CHECK_EQUAL(points[0].getName(), "test");
BOOST_CHECK_EQUAL(points[1].getName(), "test");
BOOST_CHECK_EQUAL(points[2].getName(), "test");
BOOST_CHECK_EQUAL(points[0].getFields(), "value=10");
BOOST_CHECK_EQUAL(points[1].getFields(), "value=20");
BOOST_CHECK_EQUAL(points[2].getFields(), "value=200");
}

} // namespace test
Expand Down
5 changes: 5 additions & 0 deletions test/testUdp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ BOOST_AUTO_TEST_CASE(test)
auto influxdb = influxdb::InfluxDBFactory::Get("udp://localhost:8084");
influxdb->write(Point{"test"}
.addField("value", 10)
.addField("value", 20)
.addField("value", 100LL)
.addTag("host", "adampc")
);
}
Expand All @@ -23,6 +25,9 @@ BOOST_AUTO_TEST_CASE(test2)
influxdb->write(Point{"test"}.addField("value", 10));
influxdb->write(Point{"test"}.addField("value", 10));
influxdb->write(Point{"test"}.addField("value", 10));
influxdb->write(Point{"test"}.addField("value", 100LL));
influxdb->write(Point{"test"}.addField("value", 100LL));
influxdb->write(Point{"test"}.addField("value", 100LL));
}

} // namespace test
Expand Down

0 comments on commit 2ab74d0

Please sign in to comment.