diff options
Diffstat (limited to 'staging_vespalib/src/tests')
3 files changed, 79 insertions, 42 deletions
diff --git a/staging_vespalib/src/tests/metrics/CMakeLists.txt b/staging_vespalib/src/tests/metrics/CMakeLists.txt index 5319511e769..fc9a496c972 100644 --- a/staging_vespalib/src/tests/metrics/CMakeLists.txt +++ b/staging_vespalib/src/tests/metrics/CMakeLists.txt @@ -6,3 +6,11 @@ vespa_add_executable(staging_vespalib_metrics_test_app TEST staging_vespalib ) vespa_add_test(NAME staging_vespalib_metrics_test_app COMMAND staging_vespalib_metrics_test_app) + +vespa_add_executable(staging_vespalib_stablestore_test_app TEST + SOURCES + stable_store_test.cpp + DEPENDS + staging_vespalib +) +vespa_add_test(NAME staging_vespalib_stablestore_test_app COMMAND staging_vespalib_stablestore_test_app) diff --git a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp index 0adef8d353f..1bd10d90384 100644 --- a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp +++ b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/metrics/simple_metrics.h> #include <vespa/vespalib/metrics/simple_metrics_manager.h> -#include <vespa/vespalib/metrics/no_realloc_bunch.h> +#include <vespa/vespalib/metrics/stable_store.h> #include <vespa/vespalib/metrics/json_formatter.h> #include <stdio.h> #include <unistd.h> @@ -12,7 +12,7 @@ using namespace vespalib::metrics; TEST("require that simple metrics gauge merge works") { - MetricIdentifier id(42); + MetricIdentifier id(MetricName(42)); GaugeAggregator a(id), b(id), c(id); b.observedCount = 3; b.sumValue = 24.0; @@ -52,44 +52,6 @@ TEST("require that simple metrics gauge merge works") EXPECT_EQUAL(a.lastValue, 1.0); } -struct Foo { - int a; - char *p; - explicit Foo(int v) : a(v), p(nullptr) {} - bool operator==(const Foo &other) const { - return a == other.a; - } -}; - -TEST("require that no_realloc_bunch works") -{ - vespalib::NoReallocBunch<Foo> bunch; - bunch.add(Foo(1)); - bunch.add(Foo(2)); - bunch.add(Foo(3)); - bunch.add(Foo(5)); - bunch.add(Foo(8)); - bunch.add(Foo(13)); - bunch.add(Foo(21)); - bunch.add(Foo(34)); - bunch.add(Foo(55)); - bunch.add(Foo(89)); - - EXPECT_EQUAL(bunch.size(), 10u); - - int sum = 0; - - bunch.apply([&sum](const Foo& value) { sum += value.a; }); - EXPECT_EQUAL(231, sum); - - const Foo& val = bunch.lookup(8); - EXPECT_TRUE(Foo(55) == val); - - for (int i = 0; i < 20000; ++i) { - bunch.add(Foo(i)); - } - EXPECT_TRUE(Foo(19999) == bunch.lookup(20009)); -} TEST("use simple_metrics_collector") { @@ -132,9 +94,11 @@ TEST("use simple_metrics_collector") myGauge.sample(14.0, two); myGauge.sample(11.0, three); - // sleep(2); + for (int i = 0; i < 61; ++i) { + ((SimpleMetricsManager &)*manager).tick(); + } - Snapshot snap = manager->snapshot(); + Snapshot snap = manager->totalSnapshot(); fprintf(stdout, "snap begin: %15f\n", snap.startTime()); fprintf(stdout, "snap end: %15f\n", snap.endTime()); diff --git a/staging_vespalib/src/tests/metrics/stable_store_test.cpp b/staging_vespalib/src/tests/metrics/stable_store_test.cpp new file mode 100644 index 00000000000..03b6663cd64 --- /dev/null +++ b/staging_vespalib/src/tests/metrics/stable_store_test.cpp @@ -0,0 +1,65 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/metrics/simple_metrics.h> +#include <vespa/vespalib/metrics/simple_metrics_manager.h> +#include <vespa/vespalib/metrics/stable_store.h> +#include <vespa/vespalib/metrics/json_formatter.h> +#include <stdio.h> +#include <unistd.h> + +using namespace vespalib; +using namespace vespalib::metrics; + +struct Foo { + int a; + char *p; + explicit Foo(int v) : a(v), p(nullptr) {} + bool operator==(const Foo &other) const { + return a == other.a; + } +}; + +TEST("require that stable_store works") +{ + vespalib::StableStore<Foo> bunch; + bunch.add(Foo(1)); + bunch.add(Foo(2)); + bunch.add(Foo(3)); + bunch.add(Foo(5)); + bunch.add(Foo(8)); + bunch.add(Foo(13)); + bunch.add(Foo(21)); + bunch.add(Foo(34)); + bunch.add(Foo(55)); + bunch.add(Foo(89)); + + EXPECT_EQUAL(bunch.size(), 10u); + + int sum = 0; + + bunch.for_each([&sum](const Foo& value) { sum += value.a; }); + EXPECT_EQUAL(231, sum); + + std::vector<const Foo *> pointers; + bunch.for_each([&pointers](const Foo& value) + { pointers.push_back(&value); }); + EXPECT_EQUAL(1, pointers[0]->a); + EXPECT_EQUAL(2, pointers[1]->a); + EXPECT_EQUAL(55, pointers[8]->a); + EXPECT_EQUAL(89, pointers[9]->a); + + for (int i = 0; i < 20000; ++i) { + bunch.add(Foo(i)); + } + bunch.for_each([&sum](const Foo& value) { sum -= value.a; }); + EXPECT_EQUAL(-199990000, sum); + + std::vector<const Foo *> after; + bunch.for_each([&after](const Foo& value) + { if (after.size() < 10) after.push_back(&value); }); + + EXPECT_EQUAL(pointers[0], after[0]); + EXPECT_EQUAL(pointers[9], after[9]); +} + +TEST_MAIN() { TEST_RUN_ALL(); } |