12#define BOOST_TEST_MODULE CCDB
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
23#include <fairlogger/Logger.h>
25#include <boost/test/unit_test.hpp>
26#include <boost/asio/ip/host_name.hpp>
29#include <boost/algorithm/string.hpp>
41 size_t newLength =
size * nmemb;
42 size_t oldLength =
s->size();
44 s->resize(oldLength + newLength);
45 }
catch (std::bad_alloc&
e) {
46 LOG(
error) <<
"memory error when getting data from CCDB";
50 std::copy((
char*)contents, (
char*)contents + newLength,
s->begin() + oldLength);
56 std::string host = boost::asio::ip::host_name();
57 char const* jobID = getenv(
"ALIEN_PROC_ID");
67 CURL*
handle = curl_easy_init();
69 curl_easy_setopt(
handle, CURLOPT_WRITEDATA,
dst);
70 curl_easy_setopt(
handle, CURLOPT_URL,
"http://ccdb-test.cern.ch:8080/");
72 curl_easy_setopt(
handle, CURLOPT_USERAGENT, userAgent.c_str());
78template <
typename MapType = std::map<std::
string, std::
string>>
79size_t header_map_callback(
char*
buffer,
size_t size,
size_t nitems,
void* userdata)
81 auto* headers =
static_cast<MapType*
>(userdata);
84 if (
index != std::string::npos) {
85 const auto key = boost::algorithm::trim_copy(
header.substr(0,
index));
87 headers->insert(std::make_pair(
key,
value));
97 size_t realsize =
size * nmemb, sz = 0;
100 if (chunk.capacity() < chunk.size() + realsize) {
101 auto cl = ho.header.find(
"Content-Length");
102 if (cl != ho.header.end()) {
103 sz = std::max(chunk.size() + realsize, (
size_t)std::stol(cl->second));
105 sz = chunk.size() + realsize;
110 char* contC = (
char*)contents;
111 chunk.insert(chunk.end(), contC, contC + realsize);
112 }
catch (std::exception
e) {
121 std::vector<CURL*> handles;
123 for (
int i = 0;
i <
num;
i++) {
125 dests.push_back(dest);
126 CURL* curl_handle = curl_easy_init();
127 handles.push_back(curl_handle);
130 data->hoPair.object = dest;
131 data->hosts.emplace_back(
"http://ccdb-test.cern.ch:8080");
132 data->path =
"Analysis/ALICE3/Centrality";
133 data->timestamp = 1646729604010;
134 data->localContentCallback =
nullptr;
136 curl_easy_setopt(curl_handle, CURLOPT_URL,
"http://ccdb-test.cern.ch:8080/Analysis/ALICE3/Centrality/1646729604010");
138 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (
void*)&(
data->hoPair));
140 curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, header_map_callback<
decltype(
data->hoPair.header)>);
141 curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, (
void*)&(
data->hoPair.header));
142 curl_easy_setopt(curl_handle, CURLOPT_PRIVATE, (
void*)
data);
151 if (curl_global_init(CURL_GLOBAL_ALL)) {
152 fprintf(stderr,
"Could not init curl\n");
157 std::vector<o2::pmr::vector<char>*> dests;
159 size_t transfersLeft = 0;
161 for (
auto handle : handles) {
165 while (transfersLeft > 0) {
169 for (
int i = 0;
i < TRANSFERS;
i++) {
182 curl_global_cleanup();
187 if (curl_global_init(CURL_GLOBAL_ALL)) {
188 fprintf(stderr,
"Could not init curl\n");
193 std::string
dst =
"";
201 curl_easy_getinfo(
handle, CURLINFO_HTTP_CODE, &httpCode);
204 curl_easy_cleanup(
handle);
205 curl_global_cleanup();
210 if (curl_global_init(CURL_GLOBAL_ALL)) {
211 fprintf(stderr,
"Could not init curl\n");
216 std::vector<CURL*> handleVector;
217 std::vector<std::string*> destinations;
218 for (
int i = 0;
i < 100;
i++) {
219 destinations.push_back(
new std::string());
224 for (CURLcode code : curlCodes) {
228 for (CURL*
handle : handleVector) {
230 curl_easy_getinfo(
handle, CURLINFO_HTTP_CODE, &httpCode);
232 curl_easy_cleanup(
handle);
235 for (std::string*
dst : destinations) {
239 curl_global_cleanup();
244 if (curl_global_init(CURL_GLOBAL_ALL)) {
245 fprintf(stderr,
"Could not init curl\n");
250 std::vector<CURL*> handleVector;
251 std::vector<std::string*> destinations;
252 for (
int i = 0;
i < 100;
i++) {
253 destinations.push_back(
new std::string());
259 for (CURLcode code : curlCodes) {
263 for (CURL*
handle : handleVector) {
265 curl_easy_getinfo(
handle, CURLINFO_HTTP_CODE, &httpCode);
267 curl_easy_cleanup(
handle);
270 for (std::string*
dst : destinations) {
276 std::vector<CURL*> handleVector2;
277 std::vector<std::string*> destinations2;
278 for (
int i = 0;
i < 100;
i++) {
279 destinations2.push_back(
new std::string());
284 for (CURLcode code : curlCodes2) {
288 for (CURL*
handle : handleVector2) {
290 curl_easy_getinfo(
handle, CURLINFO_HTTP_CODE, &httpCode);
292 curl_easy_cleanup(
handle);
295 for (std::string*
dst : destinations2) {
299 curl_global_cleanup();
311 if (!uv_is_closing(
handle)) {
325 uv_loop_init(uvLoop);
329 uv_timer_init(uvLoop, testTimer);
332 if (curl_global_init(CURL_GLOBAL_ALL)) {
333 fprintf(stderr,
"Could not init curl\n");
339 std::string
dst =
"";
342 CURLcode curlCode = downloader->perform(
handle);
347 curl_easy_getinfo(
handle, CURLINFO_HTTP_CODE, &httpCode);
350 curl_easy_cleanup(
handle);
351 curl_global_cleanup();
354 BOOST_CHECK_NE(uv_is_active((
uv_handle_t*)testTimer), 0);
355 BOOST_CHECK_NE(uv_loop_alive(uvLoop), 0);
361 while (uv_loop_alive(uvLoop) || uv_loop_close(uvLoop) == UV_EBUSY) {
363 uv_run(uvLoop, UV_RUN_ONCE);
struct uv_timer_s uv_timer_t
struct uv_handle_s uv_handle_t
struct uv_loop_s uv_loop_t
std::vector< std::string > header
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
char error[CURL_ERROR_SIZE]
CURLcode perform(CURL *handle)
void asynchSchedule(CURL *handle, size_t *requestCounter)
std::string trimHostUrl(std::string full_host_url) const
void runLoop(bool noWait)
std::vector< CURLcode > batchBlockingPerform(std::vector< CURL * > const &handleVector)
GLsizei const GLfloat * value
CURL * createTestHandle(std::string *dst)
std::string uniqueAgentID()
void closeAllHandles(uv_handle_t *handle, void *arg)
std::vector< CURL * > prepareAsyncHandles(size_t num, std::vector< o2::pmr::vector< char > * > &dests)
void testTimerCB(uv_timer_t *handle)
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
size_t writeCallbackNoLambda(void *contents, size_t size, size_t nmemb, void *chunkptr)
void onUVClose(uv_handle_t *handle)
size_t CurlWrite_CallbackFunc_StdString2(void *contents, size_t size, size_t nmemb, std::string *s)
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string getRandomString(int length)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())