Project
Loading...
Searching...
No Matches
testCcdbApiMultipleUrls.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
12#define BOOST_TEST_MODULE CCDB
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include "CCDB/CcdbApi.h"
18#include <boost/test/unit_test.hpp>
19#include <cstdio>
20#include <TH1F.h>
21
22using namespace std;
23using namespace o2::ccdb;
24namespace utf = boost::unit_test;
25namespace tt = boost::test_tools;
26
27static std::string ccdbUrl;
28static std::string basePath;
29bool hostReachable = false;
30
34struct Fixture {
36 {
37 CcdbApi api;
38 // Deliberately NOT reading ALICEO2_CCDB_HOST like the other suites: this
39 // one is skipped in practice, because isHostReachable() cannot report a
40 // multi-host pool reachable (see CcdbApi::isHostReachable). Making it
41 // configurable only matters once that is fixed and the suite runs.
42 ccdbUrl = "https://localhost:22,https://localhost:8080,http://ccdb-test.cern.ch:8080";
43 api.init(ccdbUrl);
44 cout << "ccdb url: " << ccdbUrl << endl;
46 cout << "Is host reachable ? --> " << hostReachable << endl;
47 basePath = std::string("Test/pid") + getpid() + "/";
48 cout << "Path we will use in this test suite : " + basePath << endl;
49 }
51 {
52 if (hostReachable) {
53 CcdbApi api;
54 std::map<std::string, std::string> metadata;
55 api.init(ccdbUrl);
56 api.truncate(basePath + "*");
57 cout << "Test data truncated (" << basePath << ")" << endl;
58 }
59 }
60};
62
66struct if_reachable {
67 tt::assertion_result operator()(utf::test_unit_id)
68 {
69 return hostReachable;
70 }
71};
72
76struct test_fixture {
78 {
80 metadata["Hello"] = "World";
81 std::cout << "*** " << boost::unit_test::framework::current_test_case().p_name << " ***" << std::endl;
82 }
83 ~test_fixture() = default;
84
86 std::map<std::string, std::string> metadata;
87};
88
89BOOST_AUTO_TEST_CASE(storeAndRetrieve, *utf::precondition(if_reachable()))
90{
92
93 TH1F h1("th1name", "th1name", 100, 0, 99);
94 h1.FillRandom("gaus", 10000);
95 BOOST_CHECK_EQUAL(h1.ClassName(), "TH1F");
96 cout << "ccdb/TObject/TEST" << endl;
97 long timestamp = getCurrentTimestamp();
98 f.api.storeAsTFile(&h1, "ccdb/TObject/TEST", f.metadata, timestamp);
99
100 TObject* returnResult = f.api.retrieve("ccdb/TObject/TEST/" + to_string(timestamp), f.metadata, timestamp);
101 BOOST_CHECK(returnResult != nullptr);
102}
void init(std::string const &hosts)
Definition CcdbApi.cxx:183
bool isHostReachable() const
Definition CcdbApi.cxx:1377
void truncate(std::string const &path) const
Definition CcdbApi.cxx:1335
GLdouble f
Definition glcorearb.h:310
information complementary to a CCDB object (path, metadata, startTimeValidity, endTimeValidity etc)
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
tt::assertion_result operator()(utf::test_unit_id)
~test_fixture()=default
std::map< std::string, std::string > metadata
std::string ccdbUrl
bool hostReachable
BOOST_GLOBAL_FIXTURE(Fixture)
bool hostReachable
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())