9#include <framework/database/MetadataProvider.h>
10#include <framework/logging/Logger.h>
11#include <framework/utilities/testhelpers/Fixtures.h>
12#include <gtest/gtest.h>
15using namespace Conditions;
22 std::vector<PayloadMetadata> m_testpayloads;
25 explicit TestMetadataProvider(
const std::vector<PayloadMetadata>& payloads): m_testpayloads(payloads) {}
32 B2ERROR(
"This globaltag is missing" <<
LogVar(
"globaltag",
"") <<
LogVar(
"error",
"missing"));
35 if (name.substr(0, 3) ==
"tag") {
44 bool updatePayloads(
const std::string& globaltag,
int exp,
int run)
override
48 for (
auto p : m_testpayloads) {
49 if (p.globaltag == globaltag and p.iov.contains(iov)) {
62 TEST_F(MetadataProviderTest, tagstates)
64 TestMetadataProvider provider({});
65 EXPECT_TRUE(provider.setTags({
"TESTING",
"VALIDATED",
"RUNNING",
"PUBLISHED"}));
66 EXPECT_FALSE(provider.setTags({
"OPEN"}));
68 expectErrorWithVariables({{
"globaltag",
"OPEN"}, {
"status",
"OPEN"}});
69 EXPECT_FALSE(provider.setTags({
"INVALID"}));
70 expectErrorWithVariables({{
"globaltag",
"INVALID"}, {
"status",
"INVALID"}});
72 EXPECT_FALSE(provider.setTags({
"TESTING",
"VALIDATED",
"OPEN",
"RUNNING",
"PUBLISHED"}));
73 expectErrorWithVariables({{
"globaltag",
"OPEN"}, {
"status",
"OPEN"}});
74 provider.setUsableTagStates({
"OPEN",
"INVALID"});
75 EXPECT_TRUE(provider.setTags({
"OPEN"}));
76 EXPECT_FALSE(provider.setTags({
"INVALID"}));
77 expectErrorWithVariables({{
"globaltag",
"INVALID"}, {
"status",
"INVALID"}});
78 EXPECT_FALSE(provider.setTags({
""}));
79 expectErrorWithVariables({{
"globaltag",
""}, {
"error",
"missing"}});
83 TEST_F(MetadataProviderTest, exception)
85 TestMetadataProvider provider({});
87 ASSERT_TRUE(provider.setTags({
"tag1"}));
88 ASSERT_THROW(provider.getPayloads(0, 0, query), std::runtime_error);
93 TEST_F(MetadataProviderTest, onlyfillneeded)
95 TestMetadataProvider provider({
97 PayloadMetadata{
"A",
"tag1",
"",
"",
"", 0, 0, -1, -1, 2},
102 query[1].revision = 1;
103 ASSERT_TRUE(provider.setTags({
"tag1"}));
104 ASSERT_TRUE(provider.getPayloads(0, 0, query));
108 EXPECT_EQ(query[0].name,
"A");
109 EXPECT_EQ(query[0].revision, 1);
110 EXPECT_EQ(query[1].name,
"B");
111 EXPECT_EQ(query[1].revision, 1);
115 TEST_F(MetadataProviderTest, payloads)
117 TestMetadataProvider provider({
119 PayloadMetadata{
"A",
"tag1",
"",
"",
"", 0, 0, -1, -1, 1},
120 PayloadMetadata{
"A",
"tag1",
"",
"",
"", 1, 0, 1, 10, 3},
121 PayloadMetadata{
"A",
"tag1",
"",
"",
"", 1, 0, 1, 10, 2},
122 PayloadMetadata{
"B",
"tag1",
"",
"",
"", 1, 0, 1, 10, 1},
125 ASSERT_TRUE(provider.setTags({
"tag1"}));
126 ASSERT_FALSE(provider.getPayloads(0, 0, query));
127 expectErrorWithVariables({{
"globaltags",
"tag1"}, {
"name",
"B"}, {
"experiment",
"0"}, {
"run",
"0"}});
128 EXPECT_EQ(query[0].revision, 1);
129 EXPECT_EQ(query[1].revision, 0);
133 EXPECT_TRUE(provider.getPayloads(1, 0, query));
134 EXPECT_EQ(query[0].revision, 3);
135 EXPECT_EQ(query[1].revision, 1);
138 EXPECT_FALSE(provider.getPayloads(0, 0, query));
139 expectErrorWithVariables({{
"globaltags",
"tag1"}, {
"name",
"B"}, {
"experiment",
"0"}, {
"run",
"0"}});
140 EXPECT_EQ(query[0].revision, 1);
141 EXPECT_EQ(query[1].revision, 0);
144 EXPECT_TRUE(provider.getPayloads(0, 0, query));
145 EXPECT_EQ(query[0].revision, 1);
146 EXPECT_EQ(query[1].revision, 0);
147 EXPECT_EQ(query[1].required,
false);
150 TEST_F(MetadataProviderTest, payloads_multiple_gt)
152 TestMetadataProvider provider({
154 PayloadMetadata{
"A",
"tag1",
"",
"",
"", 0, 0, -1, -1, 1},
155 PayloadMetadata{
"A",
"tag2",
"",
"",
"", 0, 0, -1, -1, 2},
156 PayloadMetadata{
"B",
"tag2",
"",
"",
"", 0, 0, -1, -1, 2},
160 ASSERT_TRUE(provider.setTags({
"tag1",
"tag2"}));
162 EXPECT_TRUE(provider.getPayloads(1, 0, query));
163 EXPECT_EQ(query[0].revision, 1);
164 EXPECT_EQ(query[1].revision, 2);
165 EXPECT_EQ(query[0].globaltag,
"tag1");
166 EXPECT_EQ(query[1].globaltag,
"tag2");
A class that describes the interval of experiments/runs for which an object in the database is valid.
@ c_Error
Error: for things that went wrong and have to be fixed.
Test fixture to be able to check the contents and types of emitted log messages in detail.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.