This repository is currently being migrated. It's locked while the migration is in progress.
forked from d-led/influxdb-cpp-rest
-
Notifications
You must be signed in to change notification settings - Fork 3
/
async_c_test.cpp
66 lines (54 loc) · 2.23 KB
/
async_c_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
#include <catch.hpp>
#include "../influx-c-rest/influx_c_rest_async.h"
#include "../influx-c-rest/influx_c_rest_query.h"
#include <memory>
#include <chrono>
#include <thread>
struct async_c_test
{
std::shared_ptr<influx_c_rest_async_t> asyncdb;
std::shared_ptr<influx_c_rest_query_t> query;
async_c_test() {
asyncdb = std::shared_ptr<influx_c_rest_async_t>(
influx_c_rest_async_new("http://localhost:8086","c_test"),
influx_c_rest_async_destroy
);
REQUIRE(asyncdb.get());
influx_c_rest_async_drop(asyncdb.get());
// todo: wait loops
std::this_thread::sleep_for(std::chrono::seconds(1));
CHECK(influx_c_rest_async_create(asyncdb.get()) == 0);
std::this_thread::sleep_for(std::chrono::seconds(1));
query = std::shared_ptr<influx_c_rest_query_t>(
influx_c_rest_query_new("http://localhost:8086","c_test"),
influx_c_rest_query_destroy
);
REQUIRE(query.get());
}
};
TEST_CASE_METHOD(async_c_test, "post values from C asynchronously") {
SECTION("insert some lines") {
influx_c_rest_async_insert(asyncdb.get(), "test,kvp1=42i kvp2=\"hi!\"");
influx_c_rest_async_insert_default_timestamp(asyncdb.get(), "test,kvp1=33i kvp2=\"ho!\"");
std::this_thread::sleep_for(std::chrono::seconds(1));
SECTION("query") {
auto res = std::shared_ptr<influx_c_rest_result_vt>(
influx_c_rest_query_get(query.get(),"select * from c_test..test"),
influx_c_rest_query_result_destroy
);
REQUIRE(res.get());
auto s = std::string(res.get());
CHECK(s.find("42i")!=std::string::npos);
CHECK(s.find("33i")!=std::string::npos);
CHECK(s.find("hi!")!=std::string::npos);
CHECK(s.find("ho!")!=std::string::npos);
}
}
}