-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathtestBasicCCDBManager.cxx
More file actions
128 lines (111 loc) · 5.66 KB
/
testBasicCCDBManager.cxx
File metadata and controls
128 lines (111 loc) · 5.66 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file testBasicCCDBManager.cxx
/// \brief Test BasicCCDBManager and caching functionality
/// \author ruben.shahoyan@cern.ch
///
#define BOOST_TEST_MODULE CCDB
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include "CCDB/CcdbApi.h"
#include "CCDB/BasicCCDBManager.h"
#include "Framework/Logger.h"
#include <boost/test/unit_test.hpp>
using namespace o2::ccdb;
BOOST_AUTO_TEST_CASE(TestBasicCCDBManager)
{
CcdbApi api;
const std::string uri = "http://ccdb-test.cern.ch:8080";
api.init(uri);
if (!api.isHostReachable()) {
LOG(warning) << "Host " << uri << " is not reacheable, abandoning the test";
return;
}
//
std::string pathA = "Test/CachingA";
std::string pathB = "Test/CachingB";
std::string ccdbObjO = "testObjectO";
std::string ccdbObjN = "testObjectN";
std::map<std::string, std::string> md;
long start = 1000, stop = 2000;
api.storeAsTFileAny(&ccdbObjO, pathA, md, start, stop);
api.storeAsTFileAny(&ccdbObjN, pathA, md, stop, stop + (stop - start)); // extra slot
api.storeAsTFileAny(&ccdbObjO, pathB, md, start, stop);
// test reading
auto& cdb = o2::ccdb::BasicCCDBManager::instance();
cdb.setURL(uri);
cdb.setTimestamp((start + stop) / 2);
cdb.setCaching(true);
auto* objA = cdb.get<std::string>(pathA); // will be loaded from scratch and fill the cache
LOG(info) << "1st reading of A: " << *objA;
BOOST_CHECK(objA && (*objA) == ccdbObjO); // make sure correct object is loaded
auto* objB = cdb.get<std::string>(pathB); // will be loaded from scratch and fill the cache
BOOST_CHECK(objB && (*objB) == ccdbObjO); // make sure correct object is loaded
std::string hack = "Cached";
(*objA) = hack;
(*objB) = hack;
objA = cdb.get<std::string>(pathA); // should get already cached and hacked object
LOG(info) << "Reading of cached and modified A: " << *objA;
BOOST_CHECK(objA && (*objA) == hack); // make sure correct object is loaded
// now check wrong object reading, 0 will be returned and cache will be cleaned
cdb.setFatalWhenNull(false);
objA = cdb.getForTimeStamp<std::string>(pathA, start - (stop - start) / 2); // wrong time
LOG(info) << "Read for wrong time, expect null: " << objA;
BOOST_CHECK(objA == nullptr);
cdb.setFatalWhenNull(true);
objA = cdb.get<std::string>(pathA); // cache again
LOG(info) << "Reading of A from scratch after error: " << *objA;
BOOST_CHECK(objA && (*objA) != hack); // make sure we did not get cached object
(*objA) = hack;
// read object from another time slot
objA = cdb.getForTimeStamp<std::string>(pathA, stop + (stop - start) / 2); // will be loaded from scratch and fill the cache
LOG(info) << "Reading of A for different time slost, expect non-cached object: " << *objA;
BOOST_CHECK(objA && (*objA) == ccdbObjN); // make sure correct object is loaded
// clear specific object cache
cdb.clearCache(pathA);
objA = cdb.get<std::string>(pathA); // will be loaded from scratch and fill the cache
LOG(info) << "Reading of A after cleaning its cache, expect non-cached object: " << *objA;
BOOST_CHECK(objA && (*objA) == ccdbObjO); // make sure correct object is loaded
(*objA) = hack;
objA = cdb.get<std::string>(pathA); // should get already cached and hacked object
LOG(info) << "Reading same A, expect cached and modified value: " << *objA;
BOOST_CHECK(objA && (*objA) == hack); // make sure correct object is loaded
objB = cdb.get<std::string>(pathB); // should get already cached and hacked object, since is was not reset
LOG(info) << "Reading B, expect cached since only A cache was cleaned: " << *objB;
BOOST_CHECK(objB && (*objB) == hack); // make sure correct object is loaded
// clear all caches
cdb.clearCache();
objB = cdb.get<std::string>(pathB); // will be loaded from scratch and fill the cache
LOG(info) << "Reading B after cleaning cache completely: " << *objB;
BOOST_CHECK(objB && (*objB) == ccdbObjO); // make sure correct object is loaded
// get object in TimeMachine mode in the past
cdb.setCreatedNotAfter(1); // set upper object validity
cdb.setFatalWhenNull(false);
objA = cdb.get<std::string>(pathA); // should not be loaded
BOOST_CHECK(!objA); // make sure correct object is not loaded
cdb.resetCreatedNotAfter(); // resetting upper validity limit
// get object in TimeMachine mode in the future
cdb.setCreatedNotBefore(4108971600000); // set upper object validity
objA = cdb.get<std::string>(pathA); // should not be loaded
BOOST_CHECK(!objA); // make sure correct object is not loaded
cdb.resetCreatedNotBefore(); // resetting upper validity limit
cdb.setFatalWhenNull(true);
// disable cache at all (will also clean it)
cdb.setCaching(false);
objA = cdb.get<std::string>(pathA); // will be loaded from scratch, w/o filling the cache
LOG(info) << "Reading A after disabling the cache: " << *objA;
BOOST_CHECK(objA && (*objA) == ccdbObjO); // make sure correct object is loaded
(*objA) = hack;
objA = cdb.get<std::string>(pathA); // will be loaded from scratch
LOG(info) << "Reading A again, it should not be cached: " << *objA;
BOOST_CHECK(objA && (*objA) != hack); // make sure correct object is loaded
}