|
24 | 24 | #include "CCDB/CCDBTimeStampUtils.h" |
25 | 25 | #include <boost/test/unit_test.hpp> |
26 | 26 | #include <filesystem> |
27 | | -#include <cstdio> |
28 | | -#include <cassert> |
29 | 27 | #include <iostream> |
30 | | -#include <cstdio> |
31 | | -#include <curl/curl.h> |
32 | | -#include <sys/stat.h> |
33 | | -#include <fcntl.h> |
34 | 28 | #include <TH1F.h> |
35 | 29 | #include <chrono> |
36 | 30 | #include <CommonUtils/StringUtils.h> |
37 | | -#include <TMessage.h> |
38 | 31 | #include <TStreamerInfo.h> |
39 | 32 | #include <TGraph.h> |
40 | 33 | #include <TTree.h> |
41 | 34 | #include <TString.h> |
42 | | -#include <sys/types.h> |
43 | 35 | #include <unistd.h> |
44 | 36 |
|
45 | 37 | #include <boost/property_tree/json_parser.hpp> |
@@ -479,3 +471,66 @@ BOOST_AUTO_TEST_CASE(TestRetrieveHeaders, *utf::precondition(if_reachable())) |
479 | 471 | } |
480 | 472 | BOOST_CHECK_EQUAL(headers.size(), 0); |
481 | 473 | } |
| 474 | + |
| 475 | +BOOST_AUTO_TEST_CASE(TestUpdateMetadata, *utf::precondition(if_reachable())) |
| 476 | +{ |
| 477 | + test_fixture f; |
| 478 | + |
| 479 | + // upload an object |
| 480 | + TH1F h1("object1", "object1", 100, 0, 99); |
| 481 | + cout << "storing object 1 in " << basePath << "Test" << endl; |
| 482 | + map<string, string> metadata; |
| 483 | + metadata["custom"] = "whatever"; |
| 484 | + metadata["id"] = "first"; |
| 485 | + f.api.storeAsTFile(&h1, basePath + "Test", metadata); |
| 486 | + |
| 487 | + // retrieve the headers just to be sure |
| 488 | + std::map<std::string, std::string> headers = f.api.retrieveHeaders(basePath + "Test", metadata); |
| 489 | + BOOST_CHECK(headers.count("custom") > 0); |
| 490 | + BOOST_CHECK(headers.at("custom") == "whatever"); |
| 491 | + string firstID = headers.at("ETag"); |
| 492 | + firstID.erase(std::remove(firstID.begin(), firstID.end(), '"'), firstID.end()); |
| 493 | + |
| 494 | + map<string, string> newMetadata; |
| 495 | + newMetadata["custom"] = "somethingelse"; |
| 496 | + |
| 497 | + // update the metadata and check |
| 498 | + f.api.updateMetadata(basePath + "Test", newMetadata, o2::ccdb::getCurrentTimestamp()); |
| 499 | + headers = f.api.retrieveHeaders(basePath + "Test", newMetadata); |
| 500 | + BOOST_CHECK(headers.count("custom") > 0); |
| 501 | + BOOST_CHECK(headers.at("custom") == "somethingelse"); |
| 502 | + |
| 503 | + // add a second object |
| 504 | + cout << "storing object 2 in " << basePath << "Test" << endl; |
| 505 | + metadata.clear(); |
| 506 | + metadata["custom"] = "whatever"; |
| 507 | + metadata["id"] = "second"; |
| 508 | + f.api.storeAsTFile(&h1, basePath + "Test", metadata); |
| 509 | + |
| 510 | + // get id |
| 511 | + cout << "get id" << endl; |
| 512 | + headers = f.api.retrieveHeaders(basePath + "Test", metadata); |
| 513 | + string secondID = headers.at("ETag"); |
| 514 | + secondID.erase(std::remove(secondID.begin(), secondID.end(), '"'), secondID.end()); |
| 515 | + |
| 516 | + // update the metadata by id |
| 517 | + cout << "update the metadata by id" << endl; |
| 518 | + newMetadata.clear(); |
| 519 | + newMetadata["custom"] = "first"; |
| 520 | + f.api.updateMetadata(basePath + "Test", newMetadata, o2::ccdb::getCurrentTimestamp(), firstID); |
| 521 | + newMetadata.clear(); |
| 522 | + newMetadata["custom"] = "second"; |
| 523 | + f.api.updateMetadata(basePath + "Test", newMetadata, o2::ccdb::getCurrentTimestamp(), secondID); |
| 524 | + |
| 525 | + // check |
| 526 | + metadata.clear(); |
| 527 | + metadata["id"] = "first"; |
| 528 | + headers = f.api.retrieveHeaders(basePath + "Test", metadata); |
| 529 | + BOOST_CHECK(headers.count("custom") > 0); |
| 530 | + BOOST_CHECK(headers.at("custom") == "first"); |
| 531 | + metadata.clear(); |
| 532 | + metadata["id"] = "second"; |
| 533 | + headers = f.api.retrieveHeaders(basePath + "Test", metadata); |
| 534 | + BOOST_CHECK(headers.count("custom") > 0); |
| 535 | + BOOST_CHECK(headers.at("custom") == "second"); |
| 536 | +} |
0 commit comments