Skip to content

Commit 793528f

Browse files
authored
Stabilize CCDB tests and update API (QC-221) (#237)
* remove getListOfTasksWithPublications * fix tests
1 parent f8f89bc commit 793528f

7 files changed

Lines changed: 54 additions & 566 deletions

File tree

Framework/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,14 @@ foreach(t testTaskInterface testWorkflow testTaskRunner
246246
target_include_directories(${t} PRIVATE ${CMAKE_SOURCE_DIR})
247247
endforeach()
248248

249-
set_property(TEST testTaskInterface PROPERTY LABELS slow)
250-
set_property(TEST testWorkflow PROPERTY TIMEOUT 120)
249+
set_property(TEST testWorkflow PROPERTY TIMEOUT 10)
251250
set_property(TEST testWorkflow PROPERTY LABELS slow)
252-
set_property(TEST testObjectsManager PROPERTY TIMEOUT 120)
251+
set_property(TEST testObjectsManager PROPERTY TIMEOUT 60)
253252
set_property(TEST testObjectsManager PROPERTY LABELS slow)
253+
set_property(TEST testCcdbDatabase PROPERTY TIMEOUT 60)
254+
set_property(TEST testCcdbDatabase PROPERTY LABELS slow)
254255
# Temporarily disable tests that fail on CI
255256
set_property(TEST testWorkflow PROPERTY LABELS manual)
256-
set_property(TEST testCcdbDatabaseExtra PROPERTY LABELS manual)
257-
set_property(TEST testCcdbDatabase PROPERTY LABELS manual)
258-
set_property(TEST testDbFactory PROPERTY LABELS manual)
259257

260258
# ---- Install ----
261259

Framework/include/QualityControl/CcdbDatabase.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ class CcdbDatabase : public DatabaseInterface
5656
void connect(std::string host, std::string database, std::string username, std::string password) override;
5757
void connect(const std::unordered_map<std::string, std::string>& config) override;
5858
void store(std::shared_ptr<o2::quality_control::core::MonitorObject> mo) override;
59-
core::MonitorObject* retrieve(std::string taskName, std::string objectName, long timestamp = 0) override;
60-
std::string retrieveJson(std::string taskName, std::string objectName) override;
59+
core::MonitorObject* retrieve(std::string path, std::string objectName, long timestamp = 0) override;
60+
std::string retrieveJson(std::string path, std::string objectName) override;
6161
void disconnect() override;
6262
void prepareTaskDataContainer(std::string taskName) override;
63-
std::vector<std::string> getListOfTasksWithPublications() override;
6463
std::vector<std::string> getPublishedObjectNames(std::string taskName) override;
6564
void truncate(std::string taskName, std::string objectName) override;
6665
void storeStreamerInfosToFile(std::string filename);
6766
static long getCurrentTimestamp();
6867
static long getFutureTimestamp(int secondsInFuture);
68+
/**
69+
* Return the listing of folder and/or objects in the subpath.
70+
* @param subpath The folder we want to list the children of.
71+
* @return The listing of folder and/or objects at the subpath.
72+
*/
73+
std::vector<std::string> getListing(std::string subpath = "");
6974

7075
private:
7176
/**
@@ -83,7 +88,7 @@ class CcdbDatabase : public DatabaseInterface
8388
* @param accept The format of the returned string as an \"Accept\", i.e. text/plain, application/json, text/xml
8489
* @return The listing of folder and/or objects in the format requested and as returned by the http server.
8590
*/
86-
std::string getListing(std::string subpath = "", std::string accept = "text/plain");
91+
std::string getListingAsString(std::string subpath = "", std::string accept = "text/plain");
8792
o2::ccdb::CcdbApi ccdbApi;
8893
std::string mUrl = "";
8994
};

Framework/include/QualityControl/DatabaseInterface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class DatabaseInterface
7979
* the given Task. If the container already exists, we do nothing.
8080
*/
8181
virtual void prepareTaskDataContainer(std::string taskName) = 0;
82-
virtual std::vector<std::string> getListOfTasksWithPublications() = 0;
8382
virtual std::vector<std::string> getPublishedObjectNames(std::string taskName) = 0;
8483
/**
8584
* Delete all versions of a given object

Framework/include/QualityControl/MySqlDatabase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MySqlDatabase : public DatabaseInterface
4444
std::string retrieveJson(std::string taskName, std::string objectName) override;
4545
void disconnect() override;
4646
std::vector<std::string> getPublishedObjectNames(std::string taskName) override;
47-
std::vector<std::string> getListOfTasksWithPublications() override;
47+
std::vector<std::string> getListOfTasksWithPublications();
4848
void truncate(std::string taskName, std::string objectName) override;
4949

5050
private:

Framework/src/CcdbDatabase.cxx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sstream>
3131

3232
#include <fairlogger/Logger.h>
33+
#include <boost/algorithm/string.hpp>
3334

3435
using namespace std::chrono;
3536
using namespace AliceO2::Common;
@@ -114,32 +115,32 @@ void CcdbDatabase::store(std::shared_ptr<o2::quality_control::core::MonitorObjec
114115
ccdbApi.storeAsTFile(mo.get(), path, metadata, from, to);
115116
}
116117

117-
core::MonitorObject* CcdbDatabase::retrieve(std::string taskName, std::string objectName, long timestamp)
118+
core::MonitorObject* CcdbDatabase::retrieve(std::string path, std::string objectName, long timestamp)
118119
{
119-
string path = taskName + "/" + objectName;
120+
string fullPath = path + "/" + objectName;
120121
map<string, string> metadata;
121122
long when = timestamp == 0 ? getCurrentTimestamp() : timestamp;
122123

123124
// we try first to load a TFile
124-
TObject* object = ccdbApi.retrieveFromTFile(path, metadata, when);
125+
TObject* object = ccdbApi.retrieveFromTFile(fullPath, metadata, when);
125126
if (object == nullptr) {
126127
// We could not open a TFile we should now try to open an object directly serialized
127-
object = ccdbApi.retrieve(path, metadata, when);
128-
LOG(DEBUG) << "We could retrieve the object " << path << " as a streamed object.";
128+
object = ccdbApi.retrieve(fullPath, metadata, when);
129+
LOG(DEBUG) << "We could retrieve the object " << fullPath << " as a streamed object.";
129130
if (object == nullptr) {
130131
return nullptr;
131132
}
132133
}
133134
auto* mo = dynamic_cast<core::MonitorObject*>(object);
134135
if (mo == nullptr) {
135-
LOG(ERROR) << "Could not cast the object " << taskName << "/" << objectName << " to MonitorObject";
136+
LOG(ERROR) << "Could not cast the object " << fullPath << " to MonitorObject";
136137
}
137138
return mo;
138139
}
139140

140-
std::string CcdbDatabase::retrieveJson(std::string taskName, std::string objectName)
141+
std::string CcdbDatabase::retrieveJson(std::string path, std::string objectName)
141142
{
142-
std::unique_ptr<core::MonitorObject> monitor(retrieve(taskName, objectName));
143+
std::unique_ptr<core::MonitorObject> monitor(retrieve(path, objectName));
143144
if (monitor == nullptr) {
144145
return std::string();
145146
}
@@ -159,9 +160,9 @@ void CcdbDatabase::prepareTaskDataContainer(std::string /*taskName*/)
159160
// NOOP for CCDB
160161
}
161162

162-
std::string CcdbDatabase::getListing(std::string path, std::string accept)
163+
std::string CcdbDatabase::getListingAsString(std::string subpath, std::string accept)
163164
{
164-
std::string tempString = ccdbApi.list(path, false, accept);
165+
std::string tempString = ccdbApi.list(subpath, false, accept);
165166

166167
return tempString;
167168
}
@@ -180,12 +181,12 @@ static inline void rtrim(std::string& s)
180181
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
181182
}
182183

183-
std::vector<std::string> CcdbDatabase::getListOfTasksWithPublications()
184+
std::vector<std::string> CcdbDatabase::getListing(std::string subpath)
184185
{
185186
std::vector<string> result;
186187

187-
// Get the listing from CCDB
188-
string listing = getListing();
188+
// Get the listing from CCDB (folder qc)
189+
string listing = getListingAsString(subpath);
189190

190191
// Split the string we received, by line. Also trim it and remove empty lines.
191192
std::stringstream ss(listing);
@@ -210,11 +211,12 @@ std::vector<std::string> CcdbDatabase::getPublishedObjectNames(std::string taskN
210211
// Split the string we received, by line. Also trim it and remove empty lines. Select the lines starting with "path".
211212
std::stringstream ss(listing);
212213
std::string line;
214+
std::string taskNameEscaped = boost::replace_all_copy(taskName, "/", "\\/");
213215
while (std::getline(ss, line, '\n')) {
214216
ltrim(line);
215217
rtrim(line);
216218
if (line.length() > 0 && line.find("\"path\"") == 0) {
217-
unsigned long objNameStart = 9 + taskName.length();
219+
unsigned long objNameStart = 9 + taskNameEscaped.length();
218220
string path = line.substr(objNameStart, line.length() - 2 /*final 2 char*/ - objNameStart);
219221
result.push_back(path);
220222
}

Framework/test/testCcdbDatabase.cxx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ BOOST_AUTO_TEST_CASE(ccdb_getobjects_name)
6868
{
6969
test_fixture f;
7070

71-
auto tasks = f.backend->getListOfTasksWithPublications();
71+
CcdbDatabase* ccdb = static_cast<CcdbDatabase*>(f.backend.get());
72+
auto tasks = ccdb->getListing();
7273
for (auto& task : tasks) {
7374
auto objects = f.backend->getPublishedObjectNames(task);
7475
for (auto& object : objects) {
@@ -84,15 +85,15 @@ BOOST_AUTO_TEST_CASE(ccdb_store)
8485
test_fixture f;
8586
TH1F* h1 = new TH1F("asdf/asdf", "asdf", 100, 0, 99);
8687
h1->FillRandom("gaus", 10000);
87-
shared_ptr<MonitorObject> mo1 = make_shared<MonitorObject>(h1, "my/task");
88+
shared_ptr<MonitorObject> mo1 = make_shared<MonitorObject>(h1, "my/task", "TST");
8889
oldTimestamp = CcdbDatabase::getCurrentTimestamp();
8990
f.backend->store(mo1);
9091
}
9192

9293
BOOST_AUTO_TEST_CASE(ccdb_retrieve, *utf::depends_on("ccdb_store"))
9394
{
9495
test_fixture f;
95-
MonitorObject* mo = f.backend->retrieve("my/task", "asdf/asdf");
96+
MonitorObject* mo = f.backend->retrieve("qc/TST/my/task", "asdf/asdf");
9697
BOOST_CHECK_NE(mo, nullptr);
9798
TH1F* h1 = dynamic_cast<TH1F*>(mo->getObject());
9899
BOOST_CHECK_NE(h1, nullptr);
@@ -105,25 +106,25 @@ BOOST_AUTO_TEST_CASE(ccdb_retrieve_former_versions, *utf::depends_on("ccdb_store
105106
test_fixture f;
106107
TH1F* h1 = new TH1F("asdf/asdf", "asdf", 100, 0, 99);
107108
h1->FillRandom("gaus", 10001);
108-
shared_ptr<MonitorObject> mo1 = make_shared<MonitorObject>(h1, "my/task");
109+
shared_ptr<MonitorObject> mo1 = make_shared<MonitorObject>(h1, "my/task", "TST");
109110
f.backend->store(mo1);
110111

111112
// Retrieve old object stored at timestampStorage
112-
MonitorObject* mo = f.backend->retrieve("my/task", "asdf/asdf", oldTimestamp);
113+
MonitorObject* mo = f.backend->retrieve("qc/TST/my/task", "asdf/asdf", oldTimestamp);
113114
BOOST_CHECK_NE(mo, nullptr);
114115
TH1F* old = dynamic_cast<TH1F*>(mo->getObject());
115116
BOOST_CHECK_NE(old, nullptr);
116117
BOOST_CHECK_EQUAL(old->GetEntries(), 10000);
117118

118119
// Retrieve latest object with timestamp
119-
MonitorObject* mo2 = f.backend->retrieve("my/task", "asdf/asdf", CcdbDatabase::getCurrentTimestamp());
120+
MonitorObject* mo2 = f.backend->retrieve("qc/TST/my/task", "asdf/asdf", CcdbDatabase::getCurrentTimestamp());
120121
BOOST_CHECK_NE(mo2, nullptr);
121122
TH1F* latest = dynamic_cast<TH1F*>(mo2->getObject());
122123
BOOST_CHECK_NE(latest, nullptr);
123124
BOOST_CHECK_EQUAL(latest->GetEntries(), 10001);
124125

125126
// Retrieve latest object without timetsamp
126-
MonitorObject* mo3 = f.backend->retrieve("my/task", "asdf/asdf");
127+
MonitorObject* mo3 = f.backend->retrieve("qc/TST/my/task", "asdf/asdf");
127128
BOOST_CHECK_NE(mo3, nullptr);
128129
TH1F* latest2 = dynamic_cast<TH1F*>(mo3->getObject());
129130
BOOST_CHECK_NE(latest2, nullptr);

0 commit comments

Comments
 (0)