Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 5337:b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 27 Jun 2023 17:55:09 +0200 |
parents | dd9795dc380d |
children | 303e930fff0f |
comparison
equal
deleted
inserted
replaced
5336:dd9795dc380d | 5337:b376abae664a |
---|---|
1310 TEST(MetricsRegistry, Basic) | 1310 TEST(MetricsRegistry, Basic) |
1311 { | 1311 { |
1312 { | 1312 { |
1313 MetricsRegistry m; | 1313 MetricsRegistry m; |
1314 m.SetEnabled(false); | 1314 m.SetEnabled(false); |
1315 m.SetValue("hello.world", 42); | 1315 m.SetIntegerValue("hello.world", 42); |
1316 | 1316 |
1317 std::string s; | 1317 std::string s; |
1318 m.ExportPrometheusText(s); | 1318 m.ExportPrometheusText(s); |
1319 ASSERT_TRUE(s.empty()); | 1319 ASSERT_TRUE(s.empty()); |
1320 } | 1320 } |
1321 | 1321 |
1322 { | 1322 { |
1323 MetricsRegistry m; | 1323 MetricsRegistry m; |
1324 m.Register("hello.world", MetricsUpdate_Directly); | 1324 m.Register("hello.world", MetricsUpdatePolicy_Directly, MetricsDataType_Integer); |
1325 | 1325 |
1326 std::string s; | 1326 std::string s; |
1327 m.ExportPrometheusText(s); | 1327 m.ExportPrometheusText(s); |
1328 ASSERT_TRUE(s.empty()); | 1328 ASSERT_TRUE(s.empty()); |
1329 } | 1329 } |
1330 | 1330 |
1331 { | 1331 { |
1332 MetricsRegistry m; | 1332 MetricsRegistry m; |
1333 m.SetValue("hello.world", -42); | 1333 m.SetIntegerValue("hello.world", -42); |
1334 ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("hello.world")); | 1334 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.world")); |
1335 ASSERT_THROW(m.GetMetricsUpdate("nope"), OrthancException); | 1335 ASSERT_THROW(m.GetUpdatePolicy("nope"), OrthancException); |
1336 | 1336 |
1337 std::string s; | 1337 std::string s; |
1338 m.ExportPrometheusText(s); | 1338 m.ExportPrometheusText(s); |
1339 | 1339 |
1340 std::vector<std::string> t; | 1340 std::vector<std::string> t; |
1344 ASSERT_TRUE(t[1].empty()); | 1344 ASSERT_TRUE(t[1].empty()); |
1345 } | 1345 } |
1346 | 1346 |
1347 { | 1347 { |
1348 MetricsRegistry m; | 1348 MetricsRegistry m; |
1349 m.Register("hello.max", MetricsUpdate_MaxOver10Seconds); | 1349 m.Register("hello.max", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
1350 m.SetValue("hello.max", 10); | 1350 m.SetIntegerValue("hello.max", 10); |
1351 m.SetValue("hello.max", 20); | 1351 m.SetIntegerValue("hello.max", 20); |
1352 m.SetValue("hello.max", -10); | 1352 m.SetIntegerValue("hello.max", -10); |
1353 m.SetValue("hello.max", 5); | 1353 m.SetIntegerValue("hello.max", 5); |
1354 | 1354 |
1355 m.Register("hello.min", MetricsUpdate_MinOver10Seconds); | 1355 m.Register("hello.min", MetricsUpdatePolicy_MinOver10Seconds, MetricsDataType_Integer); |
1356 m.SetValue("hello.min", 10); | 1356 m.SetIntegerValue("hello.min", 10); |
1357 m.SetValue("hello.min", 20); | 1357 m.SetIntegerValue("hello.min", 20); |
1358 m.SetValue("hello.min", -10); | 1358 m.SetIntegerValue("hello.min", -10); |
1359 m.SetValue("hello.min", 5); | 1359 m.SetIntegerValue("hello.min", 5); |
1360 | 1360 |
1361 m.Register("hello.directly", MetricsUpdate_Directly); | 1361 m.Register("hello.directly", MetricsUpdatePolicy_Directly, MetricsDataType_Integer); |
1362 m.SetValue("hello.directly", 10); | 1362 m.SetIntegerValue("hello.directly", 10); |
1363 m.SetValue("hello.directly", 20); | 1363 m.SetIntegerValue("hello.directly", 20); |
1364 m.SetValue("hello.directly", -10); | 1364 m.SetIntegerValue("hello.directly", -10); |
1365 m.SetValue("hello.directly", 5); | 1365 m.SetIntegerValue("hello.directly", 5); |
1366 | 1366 |
1367 ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("hello.max")); | 1367 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("hello.max")); |
1368 ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("hello.min")); | 1368 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("hello.min")); |
1369 ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("hello.directly")); | 1369 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.directly")); |
1370 | 1370 |
1371 std::string s; | 1371 std::string s; |
1372 m.ExportPrometheusText(s); | 1372 m.ExportPrometheusText(s); |
1373 | 1373 |
1374 std::vector<std::string> t; | 1374 std::vector<std::string> t; |
1390 } | 1390 } |
1391 | 1391 |
1392 { | 1392 { |
1393 MetricsRegistry m; | 1393 MetricsRegistry m; |
1394 | 1394 |
1395 m.SetValue("a", 10); | 1395 m.SetIntegerValue("a", 10); |
1396 m.SetValue("b", 10, MetricsUpdate_MinOver10Seconds); | 1396 m.SetIntegerValue("b", 10, MetricsUpdatePolicy_MinOver10Seconds); |
1397 | 1397 |
1398 m.Register("c", MetricsUpdate_MaxOver10Seconds); | 1398 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
1399 m.SetValue("c", 10, MetricsUpdate_MinOver10Seconds); | 1399 m.SetIntegerValue("c", 10, MetricsUpdatePolicy_MinOver10Seconds); |
1400 | 1400 |
1401 m.Register("d", MetricsUpdate_MaxOver10Seconds); | 1401 m.Register("d", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
1402 m.Register("d", MetricsUpdate_Directly); | 1402 ASSERT_THROW(m.Register("d", MetricsUpdatePolicy_Directly, MetricsDataType_Integer), OrthancException); |
1403 | 1403 |
1404 ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("a")); | 1404 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("a")); |
1405 ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("b")); | 1405 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b")); |
1406 ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("c")); | 1406 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); |
1407 ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("d")); | 1407 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("d")); |
1408 } | 1408 } |
1409 | 1409 |
1410 { | 1410 { |
1411 MetricsRegistry m; | 1411 MetricsRegistry m; |
1412 | 1412 |
1413 { | 1413 { |
1414 MetricsRegistry::Timer t1(m, "a"); | 1414 MetricsRegistry::Timer t1(m, "a"); |
1415 MetricsRegistry::Timer t2(m, "b", MetricsUpdate_MinOver10Seconds); | 1415 MetricsRegistry::Timer t2(m, "b", MetricsUpdatePolicy_MinOver10Seconds); |
1416 } | 1416 } |
1417 | 1417 |
1418 ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("a")); | 1418 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("a")); |
1419 ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("b")); | 1419 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b")); |
1420 } | |
1421 | |
1422 { | |
1423 MetricsRegistry m; | |
1424 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); | |
1425 m.SetFloatValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); | |
1426 | |
1427 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); | |
1428 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); | |
1429 } | |
1430 | |
1431 { | |
1432 MetricsRegistry m; | |
1433 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Float); | |
1434 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); | |
1435 | |
1436 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); | |
1437 ASSERT_EQ(MetricsDataType_Float, m.GetDataType("c")); | |
1438 } | |
1439 | |
1440 { | |
1441 MetricsRegistry m; | |
1442 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); | |
1443 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds); | |
1444 | |
1445 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("c")); | |
1446 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); | |
1447 } | |
1448 | |
1449 { | |
1450 MetricsRegistry m; | |
1451 m.SetIntegerValue("c", 100); | |
1452 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds); | |
1453 | |
1454 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("c")); | |
1455 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); | |
1420 } | 1456 } |
1421 } | 1457 } |
1422 #endif | 1458 #endif |
1423 | 1459 |
1424 | 1460 |