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+
12+ // /
13+ // / \file testCcdbApi_ConfigParam.cxx
14+ // / \author Sandro Wenzel
15+ // /
16+
17+ #define BOOST_TEST_MODULE CCDB
18+ #define BOOST_TEST_MAIN
19+ #define BOOST_TEST_DYN_LINK
20+
21+ #include " CCDB/CcdbApi.h"
22+ #include " CommonUtils/ConfigurableParam.h"
23+ #include " DetectorsVertexing/PVertexerParams.h"
24+ #include " CCDB/CCDBTimeStampUtils.h"
25+ #include < boost/test/unit_test.hpp>
26+ #include < filesystem>
27+ #include < cstdio>
28+ #include < cassert>
29+ #include < iostream>
30+ #include < cstdio>
31+ #include < curl/curl.h>
32+ #include < sys/stat.h>
33+ #include < fcntl.h>
34+ #include < chrono>
35+ #include < CommonUtils/StringUtils.h>
36+ #include < sys/types.h>
37+ #include < unistd.h>
38+
39+ #include < boost/property_tree/json_parser.hpp>
40+ #include < boost/property_tree/ptree.hpp>
41+ #include < boost/foreach.hpp>
42+ #include < boost/optional/optional.hpp>
43+
44+ using namespace std ;
45+ using namespace o2 ::ccdb;
46+ namespace utf = boost::unit_test;
47+ namespace tt = boost::test_tools;
48+
49+ static string ccdbUrl;
50+ static string basePath;
51+ bool hostReachable = false ;
52+
53+ /* *
54+ * Global fixture, ie general setup and teardown
55+ */
56+ struct Fixture {
57+ Fixture ()
58+ {
59+ CcdbApi api;
60+ ccdbUrl = " http://ccdb-test.cern.ch:8080" ;
61+ api.init (ccdbUrl);
62+ cout << " ccdb url: " << ccdbUrl << endl;
63+ hostReachable = api.isHostReachable ();
64+ cout << " Is host reachable ? --> " << hostReachable << endl;
65+ basePath = string (" Test/pid" ) + getpid () + " /" ;
66+ cout << " Path we will use in this test suite : " + basePath << endl;
67+ }
68+ ~Fixture ()
69+ {
70+ if (hostReachable) {
71+ CcdbApi api;
72+ map<string, string> metadata;
73+ api.init (ccdbUrl);
74+ api.truncate (basePath + " *" );
75+ cout << " Test data truncated (" << basePath << " )" << endl;
76+ }
77+ }
78+ };
79+ BOOST_GLOBAL_FIXTURE (Fixture);
80+
81+ /* *
82+ * Just an accessor to the hostReachable variable to be used to determine whether tests can be ran or not.
83+ */
84+ struct if_reachable {
85+ tt::assertion_result operator ()(utf::test_unit_id)
86+ {
87+ return hostReachable;
88+ }
89+ };
90+
91+ /* *
92+ * Fixture for the tests, i.e. code is ran in every test that uses it, i.e. it is like a setup and teardown for tests.
93+ */
94+ struct test_fixture {
95+ test_fixture ()
96+ {
97+ api.init (ccdbUrl);
98+ metadata[" Hello" ] = " World" ;
99+ std::cout << " *** " << boost::unit_test::framework::current_test_case ().p_name << " ***" << std::endl;
100+ }
101+ ~test_fixture () = default ;
102+
103+ CcdbApi api;
104+ map<string, string> metadata;
105+ };
106+
107+ BOOST_AUTO_TEST_CASE (testConfigParamRetrieval, *utf::precondition (if_reachable()))
108+ {
109+ test_fixture f;
110+
111+ // We'd like to demonstrate the following:
112+ // GIVEN:
113+ // - user modifies field in a config param from command line (RT)
114+ // - user fetches config param from CCDB
115+ //
116+ // WE'D LIKE TO ARRIVE AT A STATE with
117+ // - the returned object from CCDB gets syncs with the config param registry
118+ // - everything is consistent
119+
120+ // fetch the default instance
121+ auto & p1 = o2::vertexing::PVertexerParams::Instance ();
122+
123+ // update the config system with some runtime keys
124+ o2::conf::ConfigurableParam::updateFromString (" pvertexer.dbscanDeltaT=-3." );
125+
126+ std::map<std::string, std::string> headers;
127+ std::map<std::string, std::string> meta;
128+ long from = o2::ccdb::getCurrentTimestamp ();
129+ auto * object = f.api .retrieveFromTFileAny <o2::vertexing::PVertexerParams>(" GLO/Config/PVertexer" , meta, from + 1 , &headers);
130+ BOOST_CHECK (object != nullptr );
131+ BOOST_CHECK (object->getMemberProvenance (" dbscanDeltaT" ) == o2::conf::ConfigurableParam::EParamProvenance::kRT );
132+ BOOST_CHECK (object->getMemberProvenance (" useMeanVertexConstraint" ) == o2::conf::ConfigurableParam::EParamProvenance::kCCDB );
133+ BOOST_CHECK (p1.getMemberProvenance (" dbscanDeltaT" ) == o2::conf::ConfigurableParam::EParamProvenance::kRT );
134+ BOOST_CHECK (p1.getMemberProvenance (" useMeanVertexConstraint" ) == o2::conf::ConfigurableParam::EParamProvenance::kCCDB );
135+ BOOST_CHECK (object == &p1);
136+ }
0 commit comments