Project
Loading...
Searching...
No Matches
testCcdbApi_ConfigParam.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#define BOOST_TEST_MODULE CCDB
18#define BOOST_TEST_MAIN
19#define BOOST_TEST_DYN_LINK
20#define BOOST_BIND_GLOBAL_PLACEHOLDERS
21
22#include "CCDB/CcdbApi.h"
26#include <boost/test/unit_test.hpp>
27#include <filesystem>
28#include <cstdio>
29#include <cassert>
30#include <iostream>
31#include <cstdio>
32#include <curl/curl.h>
33#include <sys/stat.h>
34#include <fcntl.h>
35#include <chrono>
37#include <sys/types.h>
38#include <unistd.h>
39
40#include <boost/property_tree/json_parser.hpp>
41#include <boost/property_tree/ptree.hpp>
42#include <boost/foreach.hpp>
43#include <boost/optional/optional.hpp>
44
45using namespace std;
46using namespace o2::ccdb;
47namespace utf = boost::unit_test;
48namespace tt = boost::test_tools;
49
50static string ccdbUrl;
51static string basePath;
52bool hostReachable = false;
53
57struct Fixture {
59 {
60 CcdbApi api;
61 ccdbUrl = "http://ccdb-test.cern.ch:8080";
62 api.init(ccdbUrl);
63 cout << "ccdb url: " << ccdbUrl << endl;
65 char hostname[_POSIX_HOST_NAME_MAX];
66 gethostname(hostname, _POSIX_HOST_NAME_MAX);
67 basePath = string("Test/") + hostname + "/pid" + getpid() + "/";
68 cout << "Path we will use in this test suite : " + basePath << endl;
69 }
71 {
72 if (hostReachable) {
73 CcdbApi api;
74 map<string, string> metadata;
75 api.init(ccdbUrl);
76 api.truncate(basePath + "*");
77 cout << "Test data truncated (" << basePath << ")" << endl;
78 }
79 }
80};
82
86struct if_reachable {
87 tt::assertion_result operator()(utf::test_unit_id)
88 {
89 return hostReachable;
90 }
91};
92
96struct test_fixture {
98 {
100 metadata["Hello"] = "World";
101 std::cout << "*** " << boost::unit_test::framework::current_test_case().p_name << " ***" << std::endl;
102 }
103 ~test_fixture() = default;
104
105 CcdbApi api;
106 map<string, string> metadata;
107};
108
109BOOST_AUTO_TEST_CASE(testConfigParamRetrieval, *utf::precondition(if_reachable()))
110{
112
113 // We'd like to demonstrate the following:
114 // GIVEN:
115 // - user modifies field in a config param from command line (RT)
116 // - user fetches config param from CCDB
117 //
118 // WE'D LIKE TO ARRIVE AT A STATE with
119 // - the returned object from CCDB gets syncs with the config param registry
120 // - everything is consistent
121
122 // fetch the default instance
124
125 // update the config system with some runtime keys
126 o2::conf::ConfigurableParam::updateFromString("pvertexer.dbscanDeltaT=-3.");
127
128 std::map<std::string, std::string> headers;
129 std::map<std::string, std::string> meta;
130 long from = o2::ccdb::getCurrentTimestamp();
131 auto* object = f.api.retrieveFromTFileAny<o2::vertexing::PVertexerParams>("GLO/Config/PVertexer", meta, from + 1, &headers);
132 BOOST_CHECK(object != nullptr);
133 BOOST_CHECK(object->getMemberProvenance("dbscanDeltaT") == o2::conf::ConfigurableParam::EParamProvenance::kRT);
134 BOOST_CHECK(object->getMemberProvenance("useMeanVertexConstraint") == o2::conf::ConfigurableParam::EParamProvenance::kCCDB);
135 BOOST_CHECK(p1.getMemberProvenance("dbscanDeltaT") == o2::conf::ConfigurableParam::EParamProvenance::kRT);
136 BOOST_CHECK(p1.getMemberProvenance("useMeanVertexConstraint") == o2::conf::ConfigurableParam::EParamProvenance::kCCDB);
137 BOOST_CHECK(object == &p1);
138}
constexpr int p1()
constexpr to accelerate the coordinates changing
void init(std::string const &hosts)
Definition CcdbApi.cxx:165
bool isHostReachable() const
Definition CcdbApi.cxx:1301
void truncate(std::string const &path) const
Definition CcdbApi.cxx:1270
static void updateFromString(std::string const &)
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLdouble f
Definition glcorearb.h:310
GLuint object
Definition glcorearb.h:4041
information complementary to a CCDB object (path, metadata, startTimeValidity, endTimeValidity etc)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
Defining DataPointCompositeObject explicitly as copiable.
tt::assertion_result operator()(utf::test_unit_id)
~test_fixture()=default
map< string, string > metadata
std::string ccdbUrl
bool hostReachable
bool hostReachable
BOOST_GLOBAL_FIXTURE(Fixture)
BOOST_AUTO_TEST_CASE(testConfigParamRetrieval, *utf::precondition(if_reachable()))
bool hostReachable
BOOST_CHECK(tree)