summaryrefslogtreecommitdiffstats
path: root/metrics
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-05-09 07:47:56 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-05-09 09:01:50 +0000
commite8ca6eeeb580292ece4ade40ad995f7932c55204 (patch)
tree1e68592c197d232334799470a2661d99a905000d /metrics
parent72db80647f7b9e6dab491dc6634b1bd477cf59cd (diff)
Rewrite metrics tests from cppunit to gtest.
Diffstat (limited to 'metrics')
-rw-r--r--metrics/src/tests/CMakeLists.txt10
-rw-r--r--metrics/src/tests/metric_timer_test.cpp27
-rw-r--r--metrics/src/tests/metricsettest.cpp119
-rw-r--r--metrics/src/tests/metrictest.cpp74
-rw-r--r--metrics/src/tests/snapshottest.cpp49
-rw-r--r--metrics/src/tests/valuemetrictest.cpp205
6 files changed, 196 insertions, 288 deletions
diff --git a/metrics/src/tests/CMakeLists.txt b/metrics/src/tests/CMakeLists.txt
index 11d59e63c30..cb6b5212e28 100644
--- a/metrics/src/tests/CMakeLists.txt
+++ b/metrics/src/tests/CMakeLists.txt
@@ -6,7 +6,12 @@ vespa_add_executable(metrics_gtest_runner_app TEST
SOURCES
countmetrictest.cpp
loadmetrictest.cpp
+ metric_timer_test.cpp
+ metricsettest.cpp
+ metrictest.cpp
+ snapshottest.cpp
summetrictest.cpp
+ valuemetrictest.cpp
gtest_runner.cpp
DEPENDS
metrics
@@ -23,13 +28,8 @@ vespa_add_test(
vespa_add_executable(metrics_testrunner_app TEST
SOURCES
testrunner.cpp
- valuemetrictest.cpp
- metricsettest.cpp
metricmanagertest.cpp
- snapshottest.cpp
stresstest.cpp
- metrictest.cpp
- metric_timer_test.cpp
DEPENDS
metrics
vdstestlib
diff --git a/metrics/src/tests/metric_timer_test.cpp b/metrics/src/tests/metric_timer_test.cpp
index 0087da713b9..cf73c86e4f2 100644
--- a/metrics/src/tests/metric_timer_test.cpp
+++ b/metrics/src/tests/metric_timer_test.cpp
@@ -1,46 +1,31 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/metrics/valuemetric.h>
#include <vespa/metrics/metrictimer.h>
+#include <vespa/vespalib/gtest/gtest.h>
#include <thread>
namespace metrics {
-struct MetricTimerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(MetricTimerTest);
- CPPUNIT_TEST(timer_duration_is_correct_for_double_value_metric);
- CPPUNIT_TEST(timer_duration_is_correct_for_long_value_metric);
- CPPUNIT_TEST_SUITE_END();
-
- void timer_duration_is_correct_for_double_value_metric();
- void timer_duration_is_correct_for_long_value_metric();
-
- template <typename MetricType>
- void do_test_metric_timer_for_metric_type();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(MetricTimerTest);
-
using namespace std::literals::chrono_literals;
template <typename MetricType>
-void MetricTimerTest::do_test_metric_timer_for_metric_type() {
+void do_test_metric_timer_for_metric_type() {
MetricTimer timer;
MetricType metric("foo", {}, "");
std::this_thread::sleep_for(5ms); // Guaranteed to be monotonic time
timer.stop(metric);
// getDoubleValue() is present for both long and double metric types
- CPPUNIT_ASSERT(metric.getDoubleValue("last") >= 5.0);
+ EXPECT_GE(metric.getDoubleValue("last"), 5.0);
}
-void MetricTimerTest::timer_duration_is_correct_for_double_value_metric() {
+TEST(MetricTimerTest, timer_duration_is_correct_for_double_value_metric) {
do_test_metric_timer_for_metric_type<DoubleAverageMetric>();
}
-void MetricTimerTest::timer_duration_is_correct_for_long_value_metric() {
+TEST(MetricTimerTest, timer_duration_is_correct_for_long_value_metric) {
do_test_metric_timer_for_metric_type<LongAverageMetric>();
}
-} // metrics
+}
diff --git a/metrics/src/tests/metricsettest.cpp b/metrics/src/tests/metricsettest.cpp
index e4601a7b573..a6071af6404 100644
--- a/metrics/src/tests/metricsettest.cpp
+++ b/metrics/src/tests/metricsettest.cpp
@@ -1,52 +1,37 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vdstestlib/cppunit/macros.h>
-#include <vespa/vespalib/objects/floatingpointtype.h>
#include <vespa/metrics/metrics.h>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/vespalib/objects/floatingpointtype.h>
namespace metrics {
-struct MetricSetTest : public CppUnit::TestFixture {
- void testNormalUsage();
- void supportMultipleMetricsWithSameNameDifferentDimensions();
- void uniqueTargetMetricsAreAddedToMetricSet();
-
- CPPUNIT_TEST_SUITE(MetricSetTest);
- CPPUNIT_TEST(testNormalUsage);
- CPPUNIT_TEST(supportMultipleMetricsWithSameNameDifferentDimensions);
- CPPUNIT_TEST(uniqueTargetMetricsAreAddedToMetricSet);
- CPPUNIT_TEST_SUITE_END();
-};
+namespace {
+struct TestMetricVisitor : public MetricVisitor {
+ std::ostringstream ost;
+ uint32_t setsToVisit;
-CPPUNIT_TEST_SUITE_REGISTRATION(MetricSetTest);
+ TestMetricVisitor(uint32_t setsToVisit_ = 100)
+ : ost(), setsToVisit(setsToVisit_) {}
-namespace {
- struct TestMetricVisitor : public MetricVisitor {
- std::ostringstream ost;
- uint32_t setsToVisit;
-
- TestMetricVisitor(uint32_t setsToVisit_ = 100)
- : ost(), setsToVisit(setsToVisit_) {}
-
- bool visitMetricSet(const MetricSet& set, bool autoGenerated) override {
- ost << "[" << (autoGenerated ? "*" : "") << set.getName() << "]\n";
- if (setsToVisit > 0) {
- --setsToVisit;
- return true;
- }
- return false;
- }
- bool visitMetric(const Metric& m, bool autoGenerated) override {
- ost << (autoGenerated ? "*" : "") << m.getName() << "\n";
+ bool visitMetricSet(const MetricSet& set, bool autoGenerated) override {
+ ost << "[" << (autoGenerated ? "*" : "") << set.getName() << "]\n";
+ if (setsToVisit > 0) {
+ --setsToVisit;
return true;
}
- };
+ return false;
+ }
+ bool visitMetric(const Metric& m, bool autoGenerated) override {
+ ost << (autoGenerated ? "*" : "") << m.getName() << "\n";
+ return true;
+ }
+};
}
-void
-MetricSetTest::testNormalUsage()
+TEST(MetricSetTest, test_normal_usage)
{
- // Set up some metrics to test..
+ // Set up some metrics to test..
MetricSet set("a", {{"foo"}}, "");
DoubleValueMetric v1("c", {{"foo"}}, "", &set);
LongAverageMetric v2("b", {}, "", &set);
@@ -54,41 +39,41 @@ MetricSetTest::testNormalUsage()
MetricSet set2("e", {{"bar"}}, "", &set);
LongCountMetric v4("f", {{"foo"}}, "", &set2);
- // Give them some values
+ // Give them some values
v1.addValue(4.2);
v2.addValue(8);
v3.inc();
v4.inc(3);
- // Check that we can register through registerMetric function too.
+ // Check that we can register through registerMetric function too.
LongCountMetric v5("g", {}, "");
set.registerMetric(v5);
v5.inc(3);
v5.dec();
- // Check that getMetric works, and doesn't return copy.
+ // Check that getMetric works, and doesn't return copy.
LongAverageMetric* v2copy(
dynamic_cast<LongAverageMetric*>(set.getMetric("b")));
- CPPUNIT_ASSERT(v2copy != 0);
+ ASSERT_TRUE(v2copy != 0);
v2copy->addValue(9);
Metric* nonExistingCopy = set.getMetric("nonexisting");
- CPPUNIT_ASSERT(nonExistingCopy == 0);
+ EXPECT_TRUE(nonExistingCopy == 0);
nonExistingCopy = set.getMetric("non.existing");
- CPPUNIT_ASSERT(nonExistingCopy == 0);
+ EXPECT_TRUE(nonExistingCopy == 0);
- // Check that paths are set
+ // Check that paths are set
MetricSet topSet("top", {}, "");
topSet.registerMetric(set);
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a"), set.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.c"), v1.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.b"), v2.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.d"), v3.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.e"), set2.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.e.f"), v4.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.g"), v5.getPath());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("a.b"), v2copy->getPath());
-
- // Verify XML output. Should be in register order.
+ EXPECT_EQ(vespalib::string("a"), set.getPath());
+ EXPECT_EQ(vespalib::string("a.c"), v1.getPath());
+ EXPECT_EQ(vespalib::string("a.b"), v2.getPath());
+ EXPECT_EQ(vespalib::string("a.d"), v3.getPath());
+ EXPECT_EQ(vespalib::string("a.e"), set2.getPath());
+ EXPECT_EQ(vespalib::string("a.e.f"), v4.getPath());
+ EXPECT_EQ(vespalib::string("a.g"), v5.getPath());
+ EXPECT_EQ(vespalib::string("a.b"), v2copy->getPath());
+
+ // Verify XML output. Should be in register order.
std::string expected("'\n"
"a:\n"
" c average=4.2 last=4.2 min=4.2 max=4.2 count=1 total=4.2\n"
@@ -98,43 +83,41 @@ MetricSetTest::testNormalUsage()
" f count=3\n"
" g count=2'"
);
- CPPUNIT_ASSERT_EQUAL(expected, "'\n" + set.toString() + "'");
+ EXPECT_EQ(expected, "'\n" + set.toString() + "'");
- // Verify that visiting works. That you get all metrics if you answer
- // true to all sets, and that you don't get members of sets you answer
- // false to get.
+ // Verify that visiting works. That you get all metrics if you answer
+ // true to all sets, and that you don't get members of sets you answer
+ // false to get.
{
TestMetricVisitor visitor(2);
set.visit(visitor);
expected = "[a]\nc\nb\nd\n[e]\nf\ng\n";
- CPPUNIT_ASSERT_EQUAL("\n" + expected, "\n" + visitor.ost.str());
+ EXPECT_EQ("\n" + expected, "\n" + visitor.ost.str());
}
{
TestMetricVisitor visitor(1);
set.visit(visitor);
expected = "[a]\nc\nb\nd\n[e]\ng\n";
- CPPUNIT_ASSERT_EQUAL("\n" + expected, "\n" + visitor.ost.str());
+ EXPECT_EQ("\n" + expected, "\n" + visitor.ost.str());
}
{
TestMetricVisitor visitor(0);
set.visit(visitor);
expected = "[a]\n";
- CPPUNIT_ASSERT_EQUAL("\n" + expected, "\n" + visitor.ost.str());
+ EXPECT_EQ("\n" + expected, "\n" + visitor.ost.str());
}
}
-void
-MetricSetTest::supportMultipleMetricsWithSameNameDifferentDimensions()
+TEST(MetricSetTest, support_multiple_metrics_with_same_name_different_dimensions)
{
MetricSet set("dimset", {{"foo", "bar"}}, "");
DoubleValueMetric v1("stuff", {{"baz", "blarg"}}, "", &set);
LongAverageMetric v2("stuff", {{"flarn", "yarn"}}, "", &set);
- CPPUNIT_ASSERT_EQUAL(size_t(2), set.getRegisteredMetrics().size());
+ EXPECT_EQ(size_t(2), set.getRegisteredMetrics().size());
}
-void
-MetricSetTest::uniqueTargetMetricsAreAddedToMetricSet()
+TEST(MetricSetTest, unique_target_metrics_are_added_to_metric_set)
{
MetricSet set1("a", {{"foo"}}, "");
LongCountMetric v1("wow", {{"foo"}}, "", &set1);
@@ -150,8 +133,8 @@ MetricSetTest::uniqueTargetMetricsAreAddedToMetricSet()
std::vector<Metric::UP> ownerList;
set1.addToSnapshot(set2, ownerList);
- CPPUNIT_ASSERT(set2.getMetric("wow") != nullptr);
- CPPUNIT_ASSERT(set2.getMetric("doge") != nullptr);
+ EXPECT_TRUE(set2.getMetric("wow") != nullptr);
+ EXPECT_TRUE(set2.getMetric("doge") != nullptr);
}
-} // metrics
+}
diff --git a/metrics/src/tests/metrictest.cpp b/metrics/src/tests/metrictest.cpp
index eb1f5943a87..ab815f5e78c 100644
--- a/metrics/src/tests/metrictest.cpp
+++ b/metrics/src/tests/metrictest.cpp
@@ -1,80 +1,48 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vdstestlib/cppunit/macros.h>
-#include <vespa/metrics/valuemetric.h>
+
#include <vespa/metrics/countmetric.h>
+#include <vespa/metrics/valuemetric.h>
+#include <vespa/vespalib/gtest/gtest.h>
namespace metrics {
-struct MetricTest : public CppUnit::TestFixture
-{
- template <typename MetricImpl>
- void testMetricsGetDimensionsAsPartOfMangledNameImpl();
- template <typename MetricImpl>
- void testMangledNameMayContainMultipleDimensionsImpl();
-
- void valueMetricsGetDimensionsAsPartOfMangledName();
- void countMetricsGetDimensionsAsPartOfMangledName();
- void valueMetricMangledNameMayContainMultipleDimensions();
- void countMetricMangledNameMayContainMultipleDimensions();
- void mangledNameListsDimensionsInLexicographicOrder();
- void manglingDoesNotChangeOriginalMetricName();
- void legacyTagsDoNotCreateMangledName();
-
- CPPUNIT_TEST_SUITE(MetricTest);
- CPPUNIT_TEST(valueMetricsGetDimensionsAsPartOfMangledName);
- CPPUNIT_TEST(countMetricsGetDimensionsAsPartOfMangledName);
- CPPUNIT_TEST(valueMetricMangledNameMayContainMultipleDimensions);
- CPPUNIT_TEST(countMetricMangledNameMayContainMultipleDimensions);
- CPPUNIT_TEST(mangledNameListsDimensionsInLexicographicOrder);
- CPPUNIT_TEST(manglingDoesNotChangeOriginalMetricName);
- CPPUNIT_TEST(legacyTagsDoNotCreateMangledName);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(MetricTest);
-
// Metric subclasses have the same constructor parameters, so we template
// our way from having to duplicate code. Templated GTest fixtures would be
// a far more elegant solution.
template <typename MetricImpl>
void
-MetricTest::testMetricsGetDimensionsAsPartOfMangledNameImpl()
+testMetricsGetDimensionsAsPartOfMangledNameImpl()
{
MetricImpl m("test", {{"foo", "bar"}}, "description goes here");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test{foo:bar}"), m.getMangledName());
+ EXPECT_EQ(vespalib::string("test{foo:bar}"), m.getMangledName());
}
template <typename MetricImpl>
void
-MetricTest::testMangledNameMayContainMultipleDimensionsImpl()
+testMangledNameMayContainMultipleDimensionsImpl()
{
MetricImpl m("test",
{{"flarn", "yarn"}, {"foo", "bar"}},
"description goes here");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test{flarn:yarn,foo:bar}"),
- m.getMangledName());
+ EXPECT_EQ(vespalib::string("test{flarn:yarn,foo:bar}"), m.getMangledName());
}
-void
-MetricTest::valueMetricsGetDimensionsAsPartOfMangledName()
+TEST(MetricTest, value_metrics_get_dimensions_as_part_of_mangled_name)
{
testMetricsGetDimensionsAsPartOfMangledNameImpl<LongValueMetric>();
}
-void
-MetricTest::countMetricsGetDimensionsAsPartOfMangledName()
+TEST(MetricTest, count_metrics_get_dimensions_as_part_of_mangled_name)
{
testMetricsGetDimensionsAsPartOfMangledNameImpl<LongCountMetric>();
}
-void
-MetricTest::valueMetricMangledNameMayContainMultipleDimensions()
+TEST(MetricTest, value_metric_mangled_name_may_contain_multiple_dimensions)
{
testMangledNameMayContainMultipleDimensionsImpl<LongValueMetric>();
}
-void
-MetricTest::countMetricMangledNameMayContainMultipleDimensions()
+TEST(MetricTest, count_metric_mangled_name_may_contain_multiple_dimensions)
{
testMangledNameMayContainMultipleDimensionsImpl<LongCountMetric>();
}
@@ -82,30 +50,26 @@ MetricTest::countMetricMangledNameMayContainMultipleDimensions()
// Assuming the above tests pass, we simplify by not requiring all subclasses
// to be tested since propagation down to the base class has already been
// verified.
-void
-MetricTest::mangledNameListsDimensionsInLexicographicOrder()
+TEST(MetricTest, mangled_name_lists_dimensions_in_lexicographic_order)
{
LongValueMetric m("test",
{{"xyz", "bar"}, {"abc", "foo"}, {"def", "baz"}},
"");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test{abc:foo,def:baz,xyz:bar}"),
- m.getMangledName());
+ EXPECT_EQ(vespalib::string("test{abc:foo,def:baz,xyz:bar}"), m.getMangledName());
}
-void
-MetricTest::manglingDoesNotChangeOriginalMetricName()
+TEST(MetricTest, mangling_does_not_change_original_metric_name)
{
LongValueMetric m("test", {{"foo", "bar"}}, "");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test"), m.getName());
+ EXPECT_EQ(vespalib::string("test"), m.getName());
}
-void
-MetricTest::legacyTagsDoNotCreateMangledName()
+TEST(MetricTest, legacy_tags_do_not_create_mangled_name)
{
LongValueMetric m("test", {{"foo"},{"bar"}}, "");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test"), m.getName());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test"), m.getMangledName());
+ EXPECT_EQ(vespalib::string("test"), m.getName());
+ EXPECT_EQ(vespalib::string("test"), m.getMangledName());
}
-} // metrics
+}
diff --git a/metrics/src/tests/snapshottest.cpp b/metrics/src/tests/snapshottest.cpp
index df9dd0a1e64..8336af41a79 100644
--- a/metrics/src/tests/snapshottest.cpp
+++ b/metrics/src/tests/snapshottest.cpp
@@ -1,24 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/metrics/metrics.h>
#include <vespa/metrics/loadmetric.hpp>
-#include <vespa/metrics/summetric.hpp>
#include <vespa/metrics/metricmanager.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
+#include <vespa/metrics/metrics.h>
+#include <vespa/metrics/summetric.hpp>
+#include <vespa/vespalib/gtest/gtest.h>
namespace metrics {
-struct SnapshotTest : public CppUnit::TestFixture {
- void testSnapshotTwoDays();
-
- CPPUNIT_TEST_SUITE(SnapshotTest);
- CPPUNIT_TEST(testSnapshotTwoDays);
- CPPUNIT_TEST_SUITE_END();
-
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(SnapshotTest);
-
namespace {
struct SubSubMetricSet : public MetricSet {
@@ -200,16 +189,22 @@ void ASSERT_VALUE(int32_t value, const MetricSnapshot & snapshot, const char *na
{
const Metric* _metricValue_((snapshot).getMetrics().getMetric(name));
if (_metricValue_ == 0) {
- CPPUNIT_FAIL("Metric value '" + std::string(name) + "' not found in snapshot");
+ FAIL() << ("Metric value '" + std::string(name) + "' not found in snapshot");
}
- CPPUNIT_ASSERT_EQUAL(value, int32_t(_metricValue_->getLongValue("value")));
+ EXPECT_EQ(value, int32_t(_metricValue_->getLongValue("value")));
}
-} // End of anonymous namespace
+}
-void SnapshotTest::testSnapshotTwoDays()
+struct SnapshotTest : public ::testing::Test {
+ time_t tick(MetricManager& mgr, time_t currentTime) {
+ return mgr.tick(mgr.getMetricLock(), currentTime);
+ }
+};
+
+TEST_F(SnapshotTest, test_snapshot_two_days)
{
- // Create load types
+ // Create load types
LoadTypeSet loadTypes;
loadTypes.push_back(LoadType(1, "foo"));
loadTypes.push_back(LoadType(2, "bar"));
@@ -226,14 +221,14 @@ void SnapshotTest::testSnapshotTwoDays()
}
mm.init("raw:consumer[1]\n"
"consumer[0].name \"log\"", threadPool, false);
- mm.tick(mm.getMetricLock(), timer->_timeInSecs * 1000);
+ tick(mm, timer->_timeInSecs * 1000);
for (uint32_t days=0; days<2; ++days) {
for (uint32_t hour=0; hour<24; ++hour) {
for (uint32_t fiveMin=0; fiveMin<12; ++fiveMin) {
set.incValues();
timer->_timeInSecs += 5 * 60;
- mm.tick(mm.getMetricLock(), timer->_timeInSecs * 1000);
+ tick(mm, timer->_timeInSecs * 1000);
}
}
}
@@ -257,7 +252,7 @@ void SnapshotTest::testSnapshotTwoDays()
*/
const MetricSnapshot* snap = 0;
- // active snapshot
+ // active snapshot
MetricLockGuard lockGuard(mm.getMetricLock());
snap = &mm.getActiveMetrics(lockGuard);
ASSERT_VALUE(0, *snap, "test.set1.set1.count1");
@@ -273,7 +268,7 @@ void SnapshotTest::testSnapshotTwoDays()
ASSERT_VALUE(0, *snap, "test.set1.loadSet.sum.countSum");
*/
- // 5 minute snapshot
+ // 5 minute snapshot
snap = &mm.getMetricSnapshot(lockGuard, 5 * 60);
ASSERT_VALUE(1, *snap, "test.set1.set1.count1");
ASSERT_VALUE(1, *snap, "test.set1.set1.loadCount.foo");
@@ -297,7 +292,7 @@ void SnapshotTest::testSnapshotTwoDays()
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.loadAverage.sum");
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.averageSum");
- // 1 hour snapshot
+ // 1 hour snapshot
snap = &mm.getMetricSnapshot(lockGuard, 60 * 60);
ASSERT_VALUE(12, *snap, "test.set1.set1.count1");
ASSERT_VALUE(12, *snap, "test.set1.set1.loadCount.foo");
@@ -321,7 +316,7 @@ void SnapshotTest::testSnapshotTwoDays()
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.loadAverage.sum");
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.averageSum");
- // 1 day snapshot
+ // 1 day snapshot
snap = &mm.getMetricSnapshot(lockGuard, 24 * 60 * 60);
ASSERT_VALUE(288, *snap, "test.set1.set1.count1");
ASSERT_VALUE(288, *snap, "test.set1.set1.loadCount.foo");
@@ -345,7 +340,7 @@ void SnapshotTest::testSnapshotTwoDays()
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.loadAverage.sum");
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.averageSum");
- // total snapshot (2 days currently, not testing weeks)
+ // total snapshot (2 days currently, not testing weeks)
snap = &mm.getTotalMetricSnapshot(lockGuard);
ASSERT_VALUE(576, *snap, "test.set1.set1.count1");
ASSERT_VALUE(576, *snap, "test.set1.set1.loadCount.foo");
@@ -370,4 +365,4 @@ void SnapshotTest::testSnapshotTwoDays()
ASSERT_VALUE(1, *snap, "test.set1.loadSet.sum.averageSum");
}
-} // metrics
+}
diff --git a/metrics/src/tests/valuemetrictest.cpp b/metrics/src/tests/valuemetrictest.cpp
index 5aa00e5ba0a..a64739f58c2 100644
--- a/metrics/src/tests/valuemetrictest.cpp
+++ b/metrics/src/tests/valuemetrictest.cpp
@@ -1,50 +1,28 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vdstestlib/cppunit/macros.h>
-#include <vespa/vespalib/objects/floatingpointtype.h>
-#include <vespa/vespalib/text/stringtokenizer.h>
+
#include <vespa/metrics/jsonwriter.h>
#include <vespa/metrics/metricmanager.h>
#include <vespa/metrics/valuemetric.h>
-#include <vespa/vespalib/util/exceptions.h>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/vespalib/objects/floatingpointtype.h>
#include <vespa/vespalib/stllike/asciistream.h>
-
+#include <vespa/vespalib/text/stringtokenizer.h>
+#include <vespa/vespalib/util/exceptions.h>
using vespalib::Double;
namespace metrics {
-struct ValueMetricTest : public CppUnit::TestFixture {
- void testDoubleValueMetric();
- void testDoubleValueMetricNotUpdatedOnNaN();
- void testDoubleValueMetricNotUpdatedOnInfinity();
- void testLongValueMetric();
- void testSmallAverage();
- void testAddValueBatch();
- void testJson();
-
- CPPUNIT_TEST_SUITE(ValueMetricTest);
- CPPUNIT_TEST(testDoubleValueMetric);
- CPPUNIT_TEST(testDoubleValueMetricNotUpdatedOnNaN);
- CPPUNIT_TEST(testDoubleValueMetricNotUpdatedOnInfinity);
- CPPUNIT_TEST(testLongValueMetric);
- CPPUNIT_TEST(testSmallAverage);
- CPPUNIT_TEST(testAddValueBatch);
- CPPUNIT_TEST(testJson);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(ValueMetricTest);
-
#define ASSERT_AVERAGE(metric, avg, min, max, count, last) \
- CPPUNIT_ASSERT_EQUAL_MSG("avg", Double(avg), Double(metric.getAverage())); \
- CPPUNIT_ASSERT_EQUAL_MSG("cnt", Double(count), Double(metric.getCount())); \
- CPPUNIT_ASSERT_EQUAL_MSG("last", Double(last), Double(metric.getLast())); \
+ EXPECT_EQ(Double(avg), Double(metric.getAverage())); \
+ EXPECT_EQ(Double(count), Double(metric.getCount())); \
+ EXPECT_EQ(Double(last), Double(metric.getLast())); \
if (metric.getCount() > 0) { \
- CPPUNIT_ASSERT_EQUAL_MSG("min", Double(min), Double(metric.getMinimum())); \
- CPPUNIT_ASSERT_EQUAL_MSG("max", Double(max), Double(metric.getMaximum())); \
+ EXPECT_EQ(Double(min), Double(metric.getMinimum())); \
+ EXPECT_EQ(Double(max), Double(metric.getMaximum())); \
}
-void ValueMetricTest::testDoubleValueMetric()
+TEST(ValueMetricTest, test_double_value_metric)
{
DoubleValueMetric m("test", {{"tag"}}, "description");
m.addValue(100);
@@ -70,62 +48,60 @@ void ValueMetricTest::testDoubleValueMetric()
std::string expected(
"test average=80 last=40 min=40 max=100 count=3 total=240");
- CPPUNIT_ASSERT_EQUAL(expected, m2.toString());
+ EXPECT_EQ(expected, m2.toString());
expected = "m2 average=140 last=100";
- CPPUNIT_ASSERT_EQUAL(expected, o.toString());
-
- CPPUNIT_ASSERT_EQUAL(Double(40), Double(m2.getDoubleValue("value")));
- CPPUNIT_ASSERT_EQUAL(Double(80), Double(m2.getDoubleValue("average")));
- CPPUNIT_ASSERT_EQUAL(Double(40), Double(m2.getDoubleValue("min")));
- CPPUNIT_ASSERT_EQUAL(Double(100), Double(m2.getDoubleValue("max")));
- CPPUNIT_ASSERT_EQUAL(Double(40), Double(m2.getDoubleValue("last")));
- CPPUNIT_ASSERT_EQUAL(Double(3), Double(m2.getDoubleValue("count")));
- CPPUNIT_ASSERT_EQUAL(Double(240), Double(m2.getDoubleValue("total")));
-
- CPPUNIT_ASSERT_EQUAL(int64_t(40), m2.getLongValue("value"));
- CPPUNIT_ASSERT_EQUAL(int64_t(80), m2.getLongValue("average"));
- CPPUNIT_ASSERT_EQUAL(int64_t(40), m2.getLongValue("min"));
- CPPUNIT_ASSERT_EQUAL(int64_t(100), m2.getLongValue("max"));
- CPPUNIT_ASSERT_EQUAL(int64_t(40), m2.getLongValue("last"));
- CPPUNIT_ASSERT_EQUAL(int64_t(3), m2.getLongValue("count"));
- CPPUNIT_ASSERT_EQUAL(int64_t(240), m2.getLongValue("total"));
+ EXPECT_EQ(expected, o.toString());
+
+ EXPECT_EQ(Double(40), Double(m2.getDoubleValue("value")));
+ EXPECT_EQ(Double(80), Double(m2.getDoubleValue("average")));
+ EXPECT_EQ(Double(40), Double(m2.getDoubleValue("min")));
+ EXPECT_EQ(Double(100), Double(m2.getDoubleValue("max")));
+ EXPECT_EQ(Double(40), Double(m2.getDoubleValue("last")));
+ EXPECT_EQ(Double(3), Double(m2.getDoubleValue("count")));
+ EXPECT_EQ(Double(240), Double(m2.getDoubleValue("total")));
+
+ EXPECT_EQ(int64_t(40), m2.getLongValue("value"));
+ EXPECT_EQ(int64_t(80), m2.getLongValue("average"));
+ EXPECT_EQ(int64_t(40), m2.getLongValue("min"));
+ EXPECT_EQ(int64_t(100), m2.getLongValue("max"));
+ EXPECT_EQ(int64_t(40), m2.getLongValue("last"));
+ EXPECT_EQ(int64_t(3), m2.getLongValue("count"));
+ EXPECT_EQ(int64_t(240), m2.getLongValue("total"));
}
-void
-ValueMetricTest::testDoubleValueMetricNotUpdatedOnNaN()
+TEST(ValueMetricTest, test_double_value_metric_not_updated_on_nan)
{
DoubleValueMetric m("test", {{"tag"}}, "description");
m.addValue(std::numeric_limits<double>::quiet_NaN());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.addAvgValueWithCount(std::numeric_limits<double>::quiet_NaN(), 123);
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.inc(std::numeric_limits<double>::quiet_NaN());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.dec(std::numeric_limits<double>::quiet_NaN());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
}
-void
-ValueMetricTest::testDoubleValueMetricNotUpdatedOnInfinity()
+TEST(ValueMetricTest, test_double_value_metric_not_updated_on_infinity)
{
DoubleValueMetric m("test", {{"tag"}}, "description");
m.addValue(std::numeric_limits<double>::infinity());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.addAvgValueWithCount(std::numeric_limits<double>::quiet_NaN(), 123);
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.inc(std::numeric_limits<double>::infinity());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
m.dec(std::numeric_limits<double>::infinity());
- CPPUNIT_ASSERT_EQUAL(std::string(), m.toString());
+ EXPECT_EQ(std::string(), m.toString());
}
-void ValueMetricTest::testLongValueMetric()
+TEST(ValueMetricTest, test_long_value_metric)
{
LongValueMetric m("test", {{"tag"}}, "description");
m.addValue(100);
@@ -151,28 +127,28 @@ void ValueMetricTest::testLongValueMetric()
std::string expected(
"test average=80.3333 last=41 min=41 max=100 count=3 total=241");
- CPPUNIT_ASSERT_EQUAL(expected, m2.toString());
+ EXPECT_EQ(expected, m2.toString());
expected = "m2 average=140.25 last=101";
- CPPUNIT_ASSERT_EQUAL(expected, o.toString());
-
- CPPUNIT_ASSERT_EQUAL(Double(41), Double(m2.getDoubleValue("value")));
- CPPUNIT_ASSERT_EQUAL(Double(241.0/3), Double(m2.getDoubleValue("average")));
- CPPUNIT_ASSERT_EQUAL(Double(41), Double(m2.getDoubleValue("min")));
- CPPUNIT_ASSERT_EQUAL(Double(100), Double(m2.getDoubleValue("max")));
- CPPUNIT_ASSERT_EQUAL(Double(41), Double(m2.getDoubleValue("last")));
- CPPUNIT_ASSERT_EQUAL(Double(3), Double(m2.getDoubleValue("count")));
- CPPUNIT_ASSERT_EQUAL(Double(241), Double(m2.getDoubleValue("total")));
-
- CPPUNIT_ASSERT_EQUAL(int64_t(41), m2.getLongValue("value"));
- CPPUNIT_ASSERT_EQUAL(int64_t(80), m2.getLongValue("average"));
- CPPUNIT_ASSERT_EQUAL(int64_t(41), m2.getLongValue("min"));
- CPPUNIT_ASSERT_EQUAL(int64_t(100), m2.getLongValue("max"));
- CPPUNIT_ASSERT_EQUAL(int64_t(41), m2.getLongValue("last"));
- CPPUNIT_ASSERT_EQUAL(int64_t(3), m2.getLongValue("count"));
- CPPUNIT_ASSERT_EQUAL(int64_t(241), m2.getLongValue("total"));
+ EXPECT_EQ(expected, o.toString());
+
+ EXPECT_EQ(Double(41), Double(m2.getDoubleValue("value")));
+ EXPECT_EQ(Double(241.0/3), Double(m2.getDoubleValue("average")));
+ EXPECT_EQ(Double(41), Double(m2.getDoubleValue("min")));
+ EXPECT_EQ(Double(100), Double(m2.getDoubleValue("max")));
+ EXPECT_EQ(Double(41), Double(m2.getDoubleValue("last")));
+ EXPECT_EQ(Double(3), Double(m2.getDoubleValue("count")));
+ EXPECT_EQ(Double(241), Double(m2.getDoubleValue("total")));
+
+ EXPECT_EQ(int64_t(41), m2.getLongValue("value"));
+ EXPECT_EQ(int64_t(80), m2.getLongValue("average"));
+ EXPECT_EQ(int64_t(41), m2.getLongValue("min"));
+ EXPECT_EQ(int64_t(100), m2.getLongValue("max"));
+ EXPECT_EQ(int64_t(41), m2.getLongValue("last"));
+ EXPECT_EQ(int64_t(3), m2.getLongValue("count"));
+ EXPECT_EQ(int64_t(241), m2.getLongValue("total"));
}
-void ValueMetricTest::testSmallAverage()
+TEST(ValueMetricTest, test_small_average)
{
DoubleValueMetric m("test", {{"tag"}}, "description");
m.addValue(0.0001);
@@ -181,11 +157,12 @@ void ValueMetricTest::testSmallAverage()
std::vector<Metric::UP> ownerList;
Metric::UP c(m.clone(ownerList, Metric::INACTIVE, 0, false));
std::string expect("test average=0.0002 last=0.0003 min=0.0001 max=0.0003 count=3 total=0.0006");
- CPPUNIT_ASSERT_EQUAL(expect, m.toString());
- CPPUNIT_ASSERT_EQUAL(expect, c->toString());
+ EXPECT_EQ(expect, m.toString());
+ EXPECT_EQ(expect, c->toString());
}
-void ValueMetricTest::testAddValueBatch() {
+TEST(ValueMetricTest, test_add_value_batch)
+{
DoubleValueMetric m("test", {{"tag"}}, "description");
m.addValueBatch(100, 3, 80, 120);
ASSERT_AVERAGE(m, 100, 80, 120, 3, 100);
@@ -194,33 +171,37 @@ void ValueMetricTest::testAddValueBatch() {
}
namespace {
- vespalib::string extractMetricJson(vespalib::stringref s) {
- vespalib::StringTokenizer st(s, "\n", "");
- for (uint32_t i = st.size() - 1; i < st.size(); --i) {
- if (st[i].find("\"name\":\"") != std::string::npos) {
- vespalib::asciistream as;
- as << "'\n";
- for (uint32_t j=i-1; j<st.size() - 2; ++j) {
- as << st[j].substr(4) << "\n";
- }
- as << "'";
- return as.str();
+
+vespalib::string extractMetricJson(vespalib::stringref s) {
+ vespalib::StringTokenizer st(s, "\n", "");
+ for (uint32_t i = st.size() - 1; i < st.size(); --i) {
+ if (st[i].find("\"name\":\"") != std::string::npos) {
+ vespalib::asciistream as;
+ as << "'\n";
+ for (uint32_t j=i-1; j<st.size() - 2; ++j) {
+ as << st[j].substr(4) << "\n";
}
+ as << "'";
+ return as.str();
}
- throw vespalib::IllegalArgumentException("Didn't find metric");
- }
- vespalib::string getJson(MetricManager& mm) {
- vespalib::asciistream as;
- vespalib::JsonStream stream(as, true);
- JsonWriter writer(stream);
- MetricLockGuard guard(mm.getMetricLock());
- mm.visit(guard, mm.getActiveMetrics(guard), writer, "");
- stream.finalize();
- return as.str();
}
+ throw vespalib::IllegalArgumentException("Didn't find metric");
+}
+
+vespalib::string getJson(MetricManager& mm) {
+ vespalib::asciistream as;
+ vespalib::JsonStream stream(as, true);
+ JsonWriter writer(stream);
+ MetricLockGuard guard(mm.getMetricLock());
+ mm.visit(guard, mm.getActiveMetrics(guard), writer, "");
+ stream.finalize();
+ return as.str();
}
-void ValueMetricTest::testJson() {
+}
+
+TEST(ValueMetricTest, test_json)
+{
MetricManager mm;
DoubleValueMetric m("test", {{"tag"}}, "description");
mm.registerMetric(mm.getMetricLock(), m);
@@ -243,7 +224,7 @@ void ValueMetricTest::testJson() {
" }\n"
"}\n'"
);
- CPPUNIT_ASSERT_EQUAL(expected, extractMetricJson(getJson(mm)));
+ EXPECT_EQ(expected, extractMetricJson(getJson(mm)));
m.addValue(100);
expected = "'\n"
"{\n"
@@ -262,7 +243,7 @@ void ValueMetricTest::testJson() {
" {\n"
" }\n"
"}\n'";
- CPPUNIT_ASSERT_EQUAL(expected, extractMetricJson(getJson(mm)));
+ EXPECT_EQ(expected, extractMetricJson(getJson(mm)));
m.addValue(500);
expected = "'\n"
"{\n"
@@ -281,7 +262,7 @@ void ValueMetricTest::testJson() {
" {\n"
" }\n"
"}\n'";
- CPPUNIT_ASSERT_EQUAL(expected, extractMetricJson(getJson(mm)));
+ EXPECT_EQ(expected, extractMetricJson(getJson(mm)));
}
-} // namespace metrics
+}