lokinet/test/util/metrics/test_llarp_metrics_publisher.cpp

38 lines
903 B
C++
Raw Normal View History

2019-09-01 12:58:27 +00:00
#include <util/metrics/stream_publisher.hpp>
2019-02-27 21:46:23 +00:00
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace llarp;
2019-06-13 21:58:17 +00:00
using namespace metrics;
2019-02-27 21:46:23 +00:00
TEST(MetricsPublisher, StreamPublisher)
{
2019-06-13 21:58:17 +00:00
Category myCategory("MyCategory");
Description descA(&myCategory, "MetricA");
Description descB(&myCategory, "MetricB");
2019-02-27 21:46:23 +00:00
2019-06-13 21:58:17 +00:00
Id metricA(&descA);
Id metricB(&descB);
2019-02-27 21:46:23 +00:00
std::stringstream stream;
2019-06-13 21:58:17 +00:00
StreamPublisher myPublisher(stream);
2019-02-27 21:46:23 +00:00
2019-06-13 21:58:17 +00:00
std::vector< TaggedRecords< double > > records;
2019-02-27 21:46:23 +00:00
2019-06-13 21:58:17 +00:00
records.emplace_back(
metricA,
TaggedRecordsData< double >{{{}, Record< double >(5, 25.0, 6.0, 25.0)}});
records.emplace_back(
metricB,
TaggedRecordsData< double >{{{}, Record< double >(2, 7.0, 3.0, 11.0)}});
2019-02-27 21:46:23 +00:00
2019-06-13 21:58:17 +00:00
Sample sample;
2019-02-27 21:46:23 +00:00
sample.sampleTime(absl::Now());
sample.pushGroup(records.data(), records.size(), absl::Seconds(5));
2019-06-11 20:46:51 +00:00
myPublisher.publish(sample);
2019-02-27 21:46:23 +00:00
std::cout << stream.str();
}