aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/json/json_decoder_ut.cpp
diff options
context:
space:
mode:
authorivanzhukov <ivanzhukov@yandex-team.ru>2022-02-10 16:49:41 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:41 +0300
commitca3252a147a429eac4ba8221857493c58dcd09b5 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/monlib/encode/json/json_decoder_ut.cpp
parent0892d79ab411592ad25175c4bdadbcb09b466cf5 (diff)
downloadydb-ca3252a147a429eac4ba8221857493c58dcd09b5.tar.gz
Restoring authorship annotation for <ivanzhukov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/encode/json/json_decoder_ut.cpp')
-rw-r--r--library/cpp/monlib/encode/json/json_decoder_ut.cpp228
1 files changed, 114 insertions, 114 deletions
diff --git a/library/cpp/monlib/encode/json/json_decoder_ut.cpp b/library/cpp/monlib/encode/json/json_decoder_ut.cpp
index 1f9513664a..4464e1d26a 100644
--- a/library/cpp/monlib/encode/json/json_decoder_ut.cpp
+++ b/library/cpp/monlib/encode/json/json_decoder_ut.cpp
@@ -1,125 +1,125 @@
-#include "json_decoder.cpp"
-
-#include <library/cpp/monlib/consumers/collecting_consumer.h>
-#include <library/cpp/testing/unittest/registar.h>
-
-#include <array>
-
-
-using namespace NMonitoring;
-
-enum EJsonPart : ui8 {
- METRICS = 0,
- COMMON_TS = 1,
- COMMON_LABELS = 2,
-};
-
-constexpr std::array<TStringBuf, 3> JSON_PARTS = {
+#include "json_decoder.cpp"
+
+#include <library/cpp/monlib/consumers/collecting_consumer.h>
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <array>
+
+
+using namespace NMonitoring;
+
+enum EJsonPart : ui8 {
+ METRICS = 0,
+ COMMON_TS = 1,
+ COMMON_LABELS = 2,
+};
+
+constexpr std::array<TStringBuf, 3> JSON_PARTS = {
TStringBuf(R"("metrics": [{
- "labels": { "key": "value" },
- "type": "GAUGE",
- "value": 123
- }])"),
-
+ "labels": { "key": "value" },
+ "type": "GAUGE",
+ "value": 123
+ }])"),
+
TStringBuf(R"("ts": 1)"),
-
+
TStringBuf(R"("commonLabels": {
- "key1": "value1",
- "key2": "value2"
- })"),
-};
-
-TString BuildJson(std::initializer_list<EJsonPart> parts) {
- TString data = "{";
-
- for (auto it = parts.begin(); it != parts.end(); ++it) {
- data += JSON_PARTS[*it];
-
- if (it + 1 != parts.end()) {
- data += ",";
- }
- }
-
- data += "}";
- return data;
-}
-
-void ValidateCommonParts(TCommonParts&& commonParts, bool checkLabels, bool checkTs) {
- if (checkTs) {
- UNIT_ASSERT_VALUES_EQUAL(commonParts.CommonTime.MilliSeconds(), 1000);
- }
-
- if (checkLabels) {
- auto& labels = commonParts.CommonLabels;
- UNIT_ASSERT_VALUES_EQUAL(labels.Size(), 2);
+ "key1": "value1",
+ "key2": "value2"
+ })"),
+};
+
+TString BuildJson(std::initializer_list<EJsonPart> parts) {
+ TString data = "{";
+
+ for (auto it = parts.begin(); it != parts.end(); ++it) {
+ data += JSON_PARTS[*it];
+
+ if (it + 1 != parts.end()) {
+ data += ",";
+ }
+ }
+
+ data += "}";
+ return data;
+}
+
+void ValidateCommonParts(TCommonParts&& commonParts, bool checkLabels, bool checkTs) {
+ if (checkTs) {
+ UNIT_ASSERT_VALUES_EQUAL(commonParts.CommonTime.MilliSeconds(), 1000);
+ }
+
+ if (checkLabels) {
+ auto& labels = commonParts.CommonLabels;
+ UNIT_ASSERT_VALUES_EQUAL(labels.Size(), 2);
UNIT_ASSERT(labels.Has(TStringBuf("key1")));
UNIT_ASSERT(labels.Has(TStringBuf("key2")));
UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key1")).value()->Value(), "value1");
UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key2")).value()->Value(), "value2");
- }
-}
-
-void ValidateMetrics(const TVector<TMetricData>& metrics) {
- UNIT_ASSERT_VALUES_EQUAL(metrics.size(), 1);
-
- auto& m = metrics[0];
- UNIT_ASSERT_VALUES_EQUAL(m.Kind, EMetricType::GAUGE);
- auto& l = m.Labels;
- UNIT_ASSERT_VALUES_EQUAL(l.Size(), 1);
- UNIT_ASSERT_VALUES_EQUAL(l.Get(0)->Name(), "key");
- UNIT_ASSERT_VALUES_EQUAL(l.Get(0)->Value(), "value");
-
- UNIT_ASSERT_VALUES_EQUAL(m.Values->Size(), 1);
- UNIT_ASSERT_VALUES_EQUAL((*m.Values)[0].GetValue().AsDouble(), 123);
-}
-
+ }
+}
+
+void ValidateMetrics(const TVector<TMetricData>& metrics) {
+ UNIT_ASSERT_VALUES_EQUAL(metrics.size(), 1);
+
+ auto& m = metrics[0];
+ UNIT_ASSERT_VALUES_EQUAL(m.Kind, EMetricType::GAUGE);
+ auto& l = m.Labels;
+ UNIT_ASSERT_VALUES_EQUAL(l.Size(), 1);
+ UNIT_ASSERT_VALUES_EQUAL(l.Get(0)->Name(), "key");
+ UNIT_ASSERT_VALUES_EQUAL(l.Get(0)->Value(), "value");
+
+ UNIT_ASSERT_VALUES_EQUAL(m.Values->Size(), 1);
+ UNIT_ASSERT_VALUES_EQUAL((*m.Values)[0].GetValue().AsDouble(), 123);
+}
+
void CheckCommonPartsCollector(TString data, bool shouldBeStopped, bool checkLabels = true, bool checkTs = true, TStringBuf metricNameLabel = "name") {
- TCommonPartsCollector commonPartsCollector;
- TMemoryInput memIn(data);
+ TCommonPartsCollector commonPartsCollector;
+ TMemoryInput memIn(data);
TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel);
-
- bool isOk{false};
- UNIT_ASSERT_NO_EXCEPTION(isOk = NJson::ReadJson(&memIn, &decoder));
- UNIT_ASSERT_VALUES_EQUAL(isOk, !shouldBeStopped);
-
- ValidateCommonParts(commonPartsCollector.CommonParts(), checkLabels, checkTs);
-}
-
-Y_UNIT_TEST_SUITE(TJsonDecoderTest) {
- Y_UNIT_TEST(FullCommonParts) {
- CheckCommonPartsCollector(BuildJson({COMMON_LABELS, COMMON_TS, METRICS}), true);
- CheckCommonPartsCollector(BuildJson({COMMON_TS, COMMON_LABELS, METRICS}), true);
-
- CheckCommonPartsCollector(BuildJson({METRICS, COMMON_TS, COMMON_LABELS}), true);
- CheckCommonPartsCollector(BuildJson({METRICS, COMMON_LABELS, COMMON_TS}), true);
-
- CheckCommonPartsCollector(BuildJson({COMMON_LABELS, METRICS, COMMON_TS}), true);
- CheckCommonPartsCollector(BuildJson({COMMON_TS, METRICS, COMMON_LABELS}), true);
- }
-
- Y_UNIT_TEST(PartialCommonParts) {
- CheckCommonPartsCollector(BuildJson({COMMON_TS, METRICS}), false, false, true);
- CheckCommonPartsCollector(BuildJson({COMMON_LABELS, METRICS}), false, true, false);
-
- CheckCommonPartsCollector(BuildJson({METRICS, COMMON_LABELS}), false, true, false);
- CheckCommonPartsCollector(BuildJson({METRICS, COMMON_TS}), false, false, true);
-
- CheckCommonPartsCollector(BuildJson({METRICS}), false, false, false);
- }
-
- Y_UNIT_TEST(CheckCommonPartsAndMetrics) {
- auto data = BuildJson({COMMON_LABELS, COMMON_TS, METRICS});
- TCollectingConsumer collector;
-
- DecodeJson(data, &collector);
-
- TCommonParts commonParts;
- commonParts.CommonTime = collector.CommonTime;
- commonParts.CommonLabels = collector.CommonLabels;
-
- ValidateCommonParts(std::move(commonParts), true, true);
- ValidateMetrics(collector.Metrics);
- }
+
+ bool isOk{false};
+ UNIT_ASSERT_NO_EXCEPTION(isOk = NJson::ReadJson(&memIn, &decoder));
+ UNIT_ASSERT_VALUES_EQUAL(isOk, !shouldBeStopped);
+
+ ValidateCommonParts(commonPartsCollector.CommonParts(), checkLabels, checkTs);
+}
+
+Y_UNIT_TEST_SUITE(TJsonDecoderTest) {
+ Y_UNIT_TEST(FullCommonParts) {
+ CheckCommonPartsCollector(BuildJson({COMMON_LABELS, COMMON_TS, METRICS}), true);
+ CheckCommonPartsCollector(BuildJson({COMMON_TS, COMMON_LABELS, METRICS}), true);
+
+ CheckCommonPartsCollector(BuildJson({METRICS, COMMON_TS, COMMON_LABELS}), true);
+ CheckCommonPartsCollector(BuildJson({METRICS, COMMON_LABELS, COMMON_TS}), true);
+
+ CheckCommonPartsCollector(BuildJson({COMMON_LABELS, METRICS, COMMON_TS}), true);
+ CheckCommonPartsCollector(BuildJson({COMMON_TS, METRICS, COMMON_LABELS}), true);
+ }
+
+ Y_UNIT_TEST(PartialCommonParts) {
+ CheckCommonPartsCollector(BuildJson({COMMON_TS, METRICS}), false, false, true);
+ CheckCommonPartsCollector(BuildJson({COMMON_LABELS, METRICS}), false, true, false);
+
+ CheckCommonPartsCollector(BuildJson({METRICS, COMMON_LABELS}), false, true, false);
+ CheckCommonPartsCollector(BuildJson({METRICS, COMMON_TS}), false, false, true);
+
+ CheckCommonPartsCollector(BuildJson({METRICS}), false, false, false);
+ }
+
+ Y_UNIT_TEST(CheckCommonPartsAndMetrics) {
+ auto data = BuildJson({COMMON_LABELS, COMMON_TS, METRICS});
+ TCollectingConsumer collector;
+
+ DecodeJson(data, &collector);
+
+ TCommonParts commonParts;
+ commonParts.CommonTime = collector.CommonTime;
+ commonParts.CommonLabels = collector.CommonLabels;
+
+ ValidateCommonParts(std::move(commonParts), true, true);
+ ValidateMetrics(collector.Metrics);
+ }
Y_UNIT_TEST(CanParseHistogramsWithInf) {
const char* metricsData = R"({
@@ -176,4 +176,4 @@ Y_UNIT_TEST_SUITE(TJsonDecoderTest) {
UNIT_ASSERT_VALUES_EQUAL(histogram->Value(0), 21);
}
}
-}
+}