diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /storage/src/tests/common/hostreporter |
Publish
Diffstat (limited to 'storage/src/tests/common/hostreporter')
9 files changed, 320 insertions, 0 deletions
diff --git a/storage/src/tests/common/hostreporter/CMakeLists.txt b/storage/src/tests/common/hostreporter/CMakeLists.txt new file mode 100644 index 00000000000..f0cb197c5e2 --- /dev/null +++ b/storage/src/tests/common/hostreporter/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_library(storage_testhostreporter + SOURCES + cpureportertest.cpp + memreportertest.cpp + networkreportertest.cpp + versionreportertest.cpp + diskreportertest.cpp + util.cpp + hostinfotest.cpp + DEPENDS + AFTER + storage_storageconfig +) diff --git a/storage/src/tests/common/hostreporter/cpureportertest.cpp b/storage/src/tests/common/hostreporter/cpureportertest.cpp new file mode 100644 index 00000000000..56a929c3aff --- /dev/null +++ b/storage/src/tests/common/hostreporter/cpureportertest.cpp @@ -0,0 +1,40 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/cpureporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.cpureporter"); + +namespace storage { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +} + +struct CpuReporterTest : public CppUnit::TestFixture +{ + void testCpuReporter(); + + CPPUNIT_TEST_SUITE(CpuReporterTest); + CPPUNIT_TEST(testCpuReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(CpuReporterTest); + +void +CpuReporterTest::testCpuReporter() +{ + CpuReporter cpuReporter; + vespalib::Slime slime; + util::reporterToSlime(cpuReporter, slime); + CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["context switches"].asDouble()); + CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble()); + CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble()); + CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["cputotal"]["user"].asDouble()); +} +} // storage diff --git a/storage/src/tests/common/hostreporter/diskreportertest.cpp b/storage/src/tests/common/hostreporter/diskreportertest.cpp new file mode 100644 index 00000000000..158a77c2e7e --- /dev/null +++ b/storage/src/tests/common/hostreporter/diskreportertest.cpp @@ -0,0 +1,33 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/diskreporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.diskreporter"); + +namespace storage { + +struct DiskReporterTest : public CppUnit::TestFixture +{ + void testDiskReporter(); + + CPPUNIT_TEST_SUITE(DiskReporterTest); + CPPUNIT_TEST(testDiskReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DiskReporterTest); + +void +DiskReporterTest::testDiskReporter() +{ + DiskReporter diskReporter; + vespalib::Slime slime; + util::reporterToSlime(diskReporter, slime); + CPPUNIT_ASSERT(0 < slime.get()["disk"].toString().size()); +} +} // storage diff --git a/storage/src/tests/common/hostreporter/hostinfotest.cpp b/storage/src/tests/common/hostreporter/hostinfotest.cpp new file mode 100644 index 00000000000..99954c19840 --- /dev/null +++ b/storage/src/tests/common/hostreporter/hostinfotest.cpp @@ -0,0 +1,60 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/hostinfo.h> +#include <vespa/storage/common/hostreporter/hostreporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.hostinforeporter"); + +namespace storage { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +using JsonFormat = vespalib::slime::JsonFormat; +using Memory = vespalib::slime::Memory; + +class DummyReporter: public HostReporter { +public: + void report(vespalib::JsonStream& jsonreport) override { + jsonreport << "dummy" << Object() << "foo" << "bar" << End(); + } +}; +} + +struct HostInfoReporterTest : public CppUnit::TestFixture +{ + void testHostInfoReporter(); + + CPPUNIT_TEST_SUITE(HostInfoReporterTest); + CPPUNIT_TEST(testHostInfoReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(HostInfoReporterTest); + +void +HostInfoReporterTest::testHostInfoReporter() +{ + HostInfo hostinfo; + DummyReporter dummyReporter; + hostinfo.registerReporter(&dummyReporter); + vespalib::asciistream json; + vespalib::JsonStream stream(json, true); + + stream << Object(); + hostinfo.printReport(stream); + stream << End(); + + std::string jsonData = json.str(); + vespalib::Slime slime; + JsonFormat::decode(Memory(jsonData), slime); + CPPUNIT_ASSERT(slime.get()["dummy"]["foo"].asString() == "bar"); + CPPUNIT_ASSERT(0 < slime.get()["network"]["lo"]["input"]["packets"].asLong()); + CPPUNIT_ASSERT(1.0 <= slime.get()["cpu"]["context switches"].asDouble()); +} +} // storage + diff --git a/storage/src/tests/common/hostreporter/memreportertest.cpp b/storage/src/tests/common/hostreporter/memreportertest.cpp new file mode 100644 index 00000000000..3eedfd48a3c --- /dev/null +++ b/storage/src/tests/common/hostreporter/memreportertest.cpp @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/memreporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.memreporter"); + +namespace storage { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +} + +struct MemReporterTest : public CppUnit::TestFixture +{ + void testMemReporter(); + + CPPUNIT_TEST_SUITE(MemReporterTest); + CPPUNIT_TEST(testMemReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MemReporterTest); + +void +MemReporterTest::testMemReporter() +{ + MemReporter memReporter; + vespalib::Slime slime; + util::reporterToSlime(memReporter, slime); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["total memory"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["free memory"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["disk cache"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["active memory"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["inactive memory"].asLong()); + CPPUNIT_ASSERT(0 <= slime.get()["memory"]["swap total"].asLong()); + CPPUNIT_ASSERT(0 <= slime.get()["memory"]["swap free"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["memory"]["dirty"].asLong()); +} +} // storage diff --git a/storage/src/tests/common/hostreporter/networkreportertest.cpp b/storage/src/tests/common/hostreporter/networkreportertest.cpp new file mode 100644 index 00000000000..cba5717adce --- /dev/null +++ b/storage/src/tests/common/hostreporter/networkreportertest.cpp @@ -0,0 +1,40 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/networkreporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.networkreporter"); + +namespace storage { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +} + +struct NetworkReporterTest : public CppUnit::TestFixture +{ + void testNetworkReporter(); + + CPPUNIT_TEST_SUITE(NetworkReporterTest); + CPPUNIT_TEST(testNetworkReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(NetworkReporterTest); + +void +NetworkReporterTest::testNetworkReporter() +{ + NetworkReporter networkReporter; + vespalib::Slime slime; + util::reporterToSlime(networkReporter, slime); + CPPUNIT_ASSERT(0 < slime.get()["network"]["lo"]["input"]["bytes"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["network"]["lo"]["input"]["packets"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["network"]["lo"]["output"]["bytes"].asLong()); + CPPUNIT_ASSERT(0 < slime.get()["network"]["lo"]["output"]["packets"].asLong()); +} +} // storage diff --git a/storage/src/tests/common/hostreporter/util.cpp b/storage/src/tests/common/hostreporter/util.cpp new file mode 100644 index 00000000000..37d5803070d --- /dev/null +++ b/storage/src/tests/common/hostreporter/util.cpp @@ -0,0 +1,34 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include "util.h" +#include <vespa/storage/common/hostreporter/hostreporter.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/util/jsonstream.h> + +namespace storage { +namespace util { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +using JsonFormat = vespalib::slime::JsonFormat; +using Memory = vespalib::slime::Memory; +} + +void +reporterToSlime(HostReporter &hostReporter, vespalib::Slime &slime) { + vespalib::asciistream json; + vespalib::JsonStream stream(json, true); + + stream << Object(); + hostReporter.report(stream); + stream << End(); + std::string jsonData = json.str(); + size_t parsedSize = JsonFormat::decode(Memory(jsonData), slime); + + if (jsonData.size() != parsedSize) { + CPPUNIT_FAIL("Sizes of jsonData mismatched, probably not json:\n" + jsonData); + } +} +} +} diff --git a/storage/src/tests/common/hostreporter/util.h b/storage/src/tests/common/hostreporter/util.h new file mode 100644 index 00000000000..e7fcf418bd3 --- /dev/null +++ b/storage/src/tests/common/hostreporter/util.h @@ -0,0 +1,16 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#ifndef VESPA_STORAGE_COMMON_UTIL +#define VESPA_STORAGE_COMMON_UTIL + +#include <vespa/storage/common/hostreporter/hostreporter.h> +#include <vespa/vespalib/data/slime/slime.h> + +namespace storage { +namespace util { + +void +reporterToSlime(HostReporter &hostReporter, vespalib::Slime &slime); +} +} + +#endif // VESPA_STORAGE_COMMON_UTIL diff --git a/storage/src/tests/common/hostreporter/versionreportertest.cpp b/storage/src/tests/common/hostreporter/versionreportertest.cpp new file mode 100644 index 00000000000..43c6e64b0de --- /dev/null +++ b/storage/src/tests/common/hostreporter/versionreportertest.cpp @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +#include <vespa/storage/common/hostreporter/versionreporter.h> +#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/jsonstream.h> +#include "util.h" + +LOG_SETUP(".test.versionreporter"); + +namespace storage { +namespace { +using Object = vespalib::JsonStream::Object; +using End = vespalib::JsonStream::End; +} + +struct VersionReporterTest : public CppUnit::TestFixture +{ + void testVersionReporter(); + + CPPUNIT_TEST_SUITE(VersionReporterTest); + CPPUNIT_TEST(testVersionReporter); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(VersionReporterTest); + +void +VersionReporterTest::testVersionReporter() +{ + VersionReporter versionReporter; + vespalib::Slime slime; + util::reporterToSlime(versionReporter, slime); + std::string version = slime.get()["vtag"]["version"].asString().make_string().c_str(); + CPPUNIT_ASSERT(version.length() > 2); + CPPUNIT_ASSERT(version.find(".") > 0); +} +} // storage |