aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/metrics/metric_value_ut.cpp
diff options
context:
space:
mode:
authorSergey Polovko <sergey@polovko.me>2022-02-10 16:47:02 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:02 +0300
commit3e0b762a82514bac89c1dd6ea7211e381d8aa248 (patch)
treec2d1b379ecaf05ca8f11ed0b5da9d1a950e6e554 /library/cpp/monlib/metrics/metric_value_ut.cpp
parentab3783171cc30e262243a0227c86118f7080c896 (diff)
downloadydb-3e0b762a82514bac89c1dd6ea7211e381d8aa248.tar.gz
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/metrics/metric_value_ut.cpp')
-rw-r--r--library/cpp/monlib/metrics/metric_value_ut.cpp288
1 files changed, 144 insertions, 144 deletions
diff --git a/library/cpp/monlib/metrics/metric_value_ut.cpp b/library/cpp/monlib/metrics/metric_value_ut.cpp
index 49b47c4057..6db9c583ad 100644
--- a/library/cpp/monlib/metrics/metric_value_ut.cpp
+++ b/library/cpp/monlib/metrics/metric_value_ut.cpp
@@ -1,33 +1,33 @@
-#include "metric_value.h"
-
+#include "metric_value.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NMonitoring;
-
-Y_UNIT_TEST_SUITE(TMetricValueTest) {
-
- class TTestHistogram: public IHistogramSnapshot {
+
+using namespace NMonitoring;
+
+Y_UNIT_TEST_SUITE(TMetricValueTest) {
+
+ class TTestHistogram: public IHistogramSnapshot {
public:
TTestHistogram(ui32 count = 1)
: Count_{count}
{}
private:
- ui32 Count() const override {
+ ui32 Count() const override {
return Count_;
- }
-
- TBucketBound UpperBound(ui32 /*index*/) const override {
- return 1234.56;
- }
-
- TBucketValue Value(ui32 /*index*/) const override {
- return 42;
- }
+ }
+
+ TBucketBound UpperBound(ui32 /*index*/) const override {
+ return 1234.56;
+ }
+
+ TBucketValue Value(ui32 /*index*/) const override {
+ return 42;
+ }
ui32 Count_{0};
- };
-
+ };
+
IHistogramSnapshotPtr MakeHistogramSnapshot() {
return MakeIntrusive<TTestHistogram>();
}
@@ -44,46 +44,46 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
return MakeIntrusive<TLogHistogramSnapshot>(1.5, 0u, 0, buckets);
}
- Y_UNIT_TEST(Sorted) {
- auto ts1 = TInstant::Now();
- auto ts2 = ts1 + TDuration::Seconds(1);
-
- TMetricTimeSeries timeSeries;
- timeSeries.Add(ts1, 3.14159);
- timeSeries.Add(ts1, 6.28318);
- timeSeries.Add(ts2, 2.71828);
-
- UNIT_ASSERT_EQUAL(timeSeries.Size(), 3);
-
- timeSeries.SortByTs();
- UNIT_ASSERT_EQUAL(timeSeries.Size(), 2);
-
- UNIT_ASSERT_EQUAL(ts1, timeSeries[0].GetTime());
+ Y_UNIT_TEST(Sorted) {
+ auto ts1 = TInstant::Now();
+ auto ts2 = ts1 + TDuration::Seconds(1);
+
+ TMetricTimeSeries timeSeries;
+ timeSeries.Add(ts1, 3.14159);
+ timeSeries.Add(ts1, 6.28318);
+ timeSeries.Add(ts2, 2.71828);
+
+ UNIT_ASSERT_EQUAL(timeSeries.Size(), 3);
+
+ timeSeries.SortByTs();
+ UNIT_ASSERT_EQUAL(timeSeries.Size(), 2);
+
+ UNIT_ASSERT_EQUAL(ts1, timeSeries[0].GetTime());
UNIT_ASSERT_DOUBLES_EQUAL(6.28318, timeSeries[0].GetValue().AsDouble(), Min<double>());
-
- UNIT_ASSERT_EQUAL(ts2, timeSeries[1].GetTime());
- UNIT_ASSERT_DOUBLES_EQUAL(2.71828, timeSeries[1].GetValue().AsDouble(), Min<double>());
- }
-
- Y_UNIT_TEST(Histograms) {
- auto ts = TInstant::Now();
- auto histogram = MakeIntrusive<TTestHistogram>();
-
- UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
- {
- TMetricTimeSeries timeSeries;
- timeSeries.Add(ts, histogram.Get());
- UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
- }
- UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
- }
-
+
+ UNIT_ASSERT_EQUAL(ts2, timeSeries[1].GetTime());
+ UNIT_ASSERT_DOUBLES_EQUAL(2.71828, timeSeries[1].GetValue().AsDouble(), Min<double>());
+ }
+
+ Y_UNIT_TEST(Histograms) {
+ auto ts = TInstant::Now();
+ auto histogram = MakeIntrusive<TTestHistogram>();
+
+ UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
+ {
+ TMetricTimeSeries timeSeries;
+ timeSeries.Add(ts, histogram.Get());
+ UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
+ }
+ UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
+ }
+
Y_UNIT_TEST(Summary) {
auto ts = TInstant::Now();
auto summary = MakeSummarySnapshot();
UNIT_ASSERT_VALUES_EQUAL(1, summary->RefCount());
{
- TMetricTimeSeries timeSeries;
+ TMetricTimeSeries timeSeries;
timeSeries.Add(ts, summary.Get());
UNIT_ASSERT_VALUES_EQUAL(2, summary->RefCount());
}
@@ -102,73 +102,73 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
UNIT_ASSERT_VALUES_EQUAL(1, logHist->RefCount());
}
- Y_UNIT_TEST(TimeSeriesMovable) {
- auto ts = TInstant::Now();
- auto histogram = MakeIntrusive<TTestHistogram>();
-
- UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
- {
- TMetricTimeSeries timeSeriesA;
- timeSeriesA.Add(ts, histogram.Get());
- UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
-
- TMetricTimeSeries timeSeriesB = std::move(timeSeriesA);
- UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
-
- UNIT_ASSERT_VALUES_EQUAL(1, timeSeriesB.Size());
- UNIT_ASSERT_EQUAL(EMetricValueType::HISTOGRAM, timeSeriesB.GetValueType());
-
- UNIT_ASSERT_VALUES_EQUAL(0, timeSeriesA.Size());
- UNIT_ASSERT_EQUAL(EMetricValueType::UNKNOWN, timeSeriesA.GetValueType());
- }
- UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
- }
-
- Y_UNIT_TEST(HistogramsUnique) {
- auto ts1 = TInstant::Now();
- auto ts2 = ts1 + TDuration::Seconds(1);
- auto ts3 = ts2 + TDuration::Seconds(1);
-
- auto h1 = MakeIntrusive<TTestHistogram>();
- auto h2 = MakeIntrusive<TTestHistogram>();
- auto h3 = MakeIntrusive<TTestHistogram>();
-
- UNIT_ASSERT_VALUES_EQUAL(1, h1->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(1, h2->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(1, h3->RefCount());
-
- {
- TMetricTimeSeries timeSeries;
- timeSeries.Add(ts1, h1.Get()); // drop at the head
- timeSeries.Add(ts1, h1.Get());
- timeSeries.Add(ts1, h1.Get());
-
- timeSeries.Add(ts2, h2.Get()); // drop in the middle
- timeSeries.Add(ts2, h2.Get());
- timeSeries.Add(ts2, h2.Get());
-
- timeSeries.Add(ts3, h3.Get()); // drop at the end
- timeSeries.Add(ts3, h3.Get());
- timeSeries.Add(ts3, h3.Get());
-
- UNIT_ASSERT_EQUAL(timeSeries.Size(), 9);
-
- UNIT_ASSERT_VALUES_EQUAL(4, h1->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(4, h2->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(4, h3->RefCount());
-
- timeSeries.SortByTs();
- UNIT_ASSERT_EQUAL(timeSeries.Size(), 3);
-
- UNIT_ASSERT_VALUES_EQUAL(2, h1->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(2, h2->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(2, h3->RefCount());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(1, h1->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(1, h2->RefCount());
- UNIT_ASSERT_VALUES_EQUAL(1, h3->RefCount());
- }
+ Y_UNIT_TEST(TimeSeriesMovable) {
+ auto ts = TInstant::Now();
+ auto histogram = MakeIntrusive<TTestHistogram>();
+
+ UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
+ {
+ TMetricTimeSeries timeSeriesA;
+ timeSeriesA.Add(ts, histogram.Get());
+ UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
+
+ TMetricTimeSeries timeSeriesB = std::move(timeSeriesA);
+ UNIT_ASSERT_VALUES_EQUAL(2, histogram->RefCount());
+
+ UNIT_ASSERT_VALUES_EQUAL(1, timeSeriesB.Size());
+ UNIT_ASSERT_EQUAL(EMetricValueType::HISTOGRAM, timeSeriesB.GetValueType());
+
+ UNIT_ASSERT_VALUES_EQUAL(0, timeSeriesA.Size());
+ UNIT_ASSERT_EQUAL(EMetricValueType::UNKNOWN, timeSeriesA.GetValueType());
+ }
+ UNIT_ASSERT_VALUES_EQUAL(1, histogram->RefCount());
+ }
+
+ Y_UNIT_TEST(HistogramsUnique) {
+ auto ts1 = TInstant::Now();
+ auto ts2 = ts1 + TDuration::Seconds(1);
+ auto ts3 = ts2 + TDuration::Seconds(1);
+
+ auto h1 = MakeIntrusive<TTestHistogram>();
+ auto h2 = MakeIntrusive<TTestHistogram>();
+ auto h3 = MakeIntrusive<TTestHistogram>();
+
+ UNIT_ASSERT_VALUES_EQUAL(1, h1->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(1, h2->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(1, h3->RefCount());
+
+ {
+ TMetricTimeSeries timeSeries;
+ timeSeries.Add(ts1, h1.Get()); // drop at the head
+ timeSeries.Add(ts1, h1.Get());
+ timeSeries.Add(ts1, h1.Get());
+
+ timeSeries.Add(ts2, h2.Get()); // drop in the middle
+ timeSeries.Add(ts2, h2.Get());
+ timeSeries.Add(ts2, h2.Get());
+
+ timeSeries.Add(ts3, h3.Get()); // drop at the end
+ timeSeries.Add(ts3, h3.Get());
+ timeSeries.Add(ts3, h3.Get());
+
+ UNIT_ASSERT_EQUAL(timeSeries.Size(), 9);
+
+ UNIT_ASSERT_VALUES_EQUAL(4, h1->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(4, h2->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(4, h3->RefCount());
+
+ timeSeries.SortByTs();
+ UNIT_ASSERT_EQUAL(timeSeries.Size(), 3);
+
+ UNIT_ASSERT_VALUES_EQUAL(2, h1->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(2, h2->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(2, h3->RefCount());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(1, h1->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(1, h2->RefCount());
+ UNIT_ASSERT_VALUES_EQUAL(1, h3->RefCount());
+ }
Y_UNIT_TEST(LogHistogramsUnique) {
auto ts1 = TInstant::Now();
@@ -230,7 +230,7 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
UNIT_ASSERT_VALUES_EQUAL(1, h3->RefCount());
{
- TMetricTimeSeries timeSeries;
+ TMetricTimeSeries timeSeries;
timeSeries.Add(ts1, h1.Get()); // drop at the head
timeSeries.Add(ts1, h1.Get());
timeSeries.Add(ts1, h1.Get());
@@ -278,7 +278,7 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
auto h7 = MakeIntrusive<TTestHistogram>(7u);
{
- TMetricTimeSeries timeSeries;
+ TMetricTimeSeries timeSeries;
timeSeries.Add(ts1, h1.Get());
timeSeries.Add(ts1, h2.Get());
@@ -356,7 +356,7 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
auto h7 = MakeSummarySnapshot(7u);
{
- TMetricTimeSeries timeSeries;
+ TMetricTimeSeries timeSeries;
timeSeries.Add(ts1, h1.Get());
timeSeries.Add(ts1, h2.Get());
@@ -379,27 +379,27 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
}
}
- Y_UNIT_TEST(TMetricValueWithType) {
+ Y_UNIT_TEST(TMetricValueWithType) {
// correct usage
{
double value = 1.23;
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
- UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::DOUBLE);
+ UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::DOUBLE);
UNIT_ASSERT_VALUES_EQUAL(v.AsDouble(), value);
}
{
ui64 value = 12;
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
- UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::UINT64);
+ UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::UINT64);
UNIT_ASSERT_VALUES_EQUAL(v.AsUint64(), value);
}
{
i64 value = i64(-12);
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
- UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::INT64);
+ UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::INT64);
UNIT_ASSERT_VALUES_EQUAL(v.AsInt64(), value);
}
{
@@ -408,11 +408,11 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
{
auto value = h.Get();
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
UNIT_ASSERT_VALUES_EQUAL(h.RefCount(), 2);
- UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::HISTOGRAM);
+ UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::HISTOGRAM);
UNIT_ASSERT_VALUES_EQUAL(v.AsHistogram(), value);
}
@@ -425,11 +425,11 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 1);
{
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 2);
- UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::SUMMARY);
+ UNIT_ASSERT_VALUES_EQUAL(v.GetType(), EMetricValueType::SUMMARY);
UNIT_ASSERT_VALUES_EQUAL(v.AsSummaryDouble(), value);
}
@@ -442,7 +442,7 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 1);
{
- TMetricValueWithType v{value};
+ TMetricValueWithType v{value};
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 2);
@@ -457,19 +457,19 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
auto value = s.Get();
{
- TMetricValueWithType v1{ui64{1}};
+ TMetricValueWithType v1{ui64{1}};
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 1);
{
- TMetricValueWithType v2{value};
+ TMetricValueWithType v2{value};
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 2);
v1 = std::move(v2);
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 2);
UNIT_ASSERT_VALUES_EQUAL(v1.AsSummaryDouble(), value);
- UNIT_ASSERT_VALUES_EQUAL(v1.GetType(), EMetricValueType::SUMMARY);
- UNIT_ASSERT_VALUES_EQUAL(v2.GetType(), EMetricValueType::UNKNOWN);
+ UNIT_ASSERT_VALUES_EQUAL(v1.GetType(), EMetricValueType::SUMMARY);
+ UNIT_ASSERT_VALUES_EQUAL(v2.GetType(), EMetricValueType::UNKNOWN);
}
UNIT_ASSERT_VALUES_EQUAL(s.RefCount(), 2);
@@ -480,14 +480,14 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
// incorrect usage
{
- TMetricValueWithType v{1.23};
+ TMetricValueWithType v{1.23};
UNIT_ASSERT_EXCEPTION(v.AsHistogram(), yexception);
UNIT_ASSERT_EXCEPTION(v.AsSummaryDouble(), yexception);
}
{
auto h = MakeHistogramSnapshot();
- TMetricValueWithType v{h.Get()};
+ TMetricValueWithType v{h.Get()};
UNIT_ASSERT_EXCEPTION(v.AsUint64(), yexception);
UNIT_ASSERT_EXCEPTION(v.AsInt64(), yexception);
@@ -496,7 +496,7 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
}
{
auto s = MakeSummarySnapshot();
- TMetricValueWithType v{s.Get()};
+ TMetricValueWithType v{s.Get()};
UNIT_ASSERT_EXCEPTION(v.AsUint64(), yexception);
UNIT_ASSERT_EXCEPTION(v.AsInt64(), yexception);
@@ -504,4 +504,4 @@ Y_UNIT_TEST_SUITE(TMetricValueTest) {
UNIT_ASSERT_EXCEPTION(v.AsHistogram(), yexception);
}
}
-}
+}