diff options
Diffstat (limited to 'storage/src/tests/common')
-rw-r--r-- | storage/src/tests/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | storage/src/tests/common/hostreporter/CMakeLists.txt | 5 | ||||
-rw-r--r-- | storage/src/tests/common/hostreporter/hostinfotest.cpp | 29 | ||||
-rw-r--r-- | storage/src/tests/common/hostreporter/util.cpp | 9 | ||||
-rw-r--r-- | storage/src/tests/common/hostreporter/versionreportertest.cpp | 31 | ||||
-rw-r--r-- | storage/src/tests/common/message_sender_stub.cpp | 91 | ||||
-rw-r--r-- | storage/src/tests/common/message_sender_stub.h | 47 | ||||
-rw-r--r-- | storage/src/tests/common/metricstest.cpp | 15 | ||||
-rw-r--r-- | storage/src/tests/common/testhelper.h | 17 | ||||
-rw-r--r-- | storage/src/tests/common/teststorageapp.cpp | 12 |
10 files changed, 179 insertions, 78 deletions
diff --git a/storage/src/tests/common/CMakeLists.txt b/storage/src/tests/common/CMakeLists.txt index 075dc263be9..1922d13ca61 100644 --- a/storage/src/tests/common/CMakeLists.txt +++ b/storage/src/tests/common/CMakeLists.txt @@ -2,6 +2,7 @@ vespa_add_library(storage_testcommon TEST SOURCES dummystoragelink.cpp + message_sender_stub.cpp testhelper.cpp testnodestateupdater.cpp teststorageapp.cpp diff --git a/storage/src/tests/common/hostreporter/CMakeLists.txt b/storage/src/tests/common/hostreporter/CMakeLists.txt index 7a4a23ba7aa..2fcb159cb08 100644 --- a/storage/src/tests/common/hostreporter/CMakeLists.txt +++ b/storage/src/tests/common/hostreporter/CMakeLists.txt @@ -1,9 +1,7 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(storage_testhostreporter TEST SOURCES - hostinfotest.cpp util.cpp - versionreportertest.cpp DEPENDS storage ) @@ -11,8 +9,11 @@ vespa_add_library(storage_testhostreporter TEST vespa_add_executable(storage_hostreporter_gtest_runner_app TEST SOURCES gtest_runner.cpp + hostinfotest.cpp + versionreportertest.cpp DEPENDS storage + storage_testhostreporter gtest ) diff --git a/storage/src/tests/common/hostreporter/hostinfotest.cpp b/storage/src/tests/common/hostreporter/hostinfotest.cpp index 418884c2a38..467149154ee 100644 --- a/storage/src/tests/common/hostreporter/hostinfotest.cpp +++ b/storage/src/tests/common/hostreporter/hostinfotest.cpp @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "util.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/stllike/asciistream.h> #include <vespa/vespalib/util/jsonstream.h> -#include "util.h" +#include <vespa/vespalib/gtest/gtest.h> + +using namespace ::testing; namespace storage { namespace { + using Object = vespalib::JsonStream::Object; using End = vespalib::JsonStream::End; using JsonFormat = vespalib::slime::JsonFormat; @@ -21,22 +24,10 @@ public: 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() -{ +TEST(HostInfoReporterTest, host_info_reporter) { HostInfo hostinfo; DummyReporter dummyReporter; hostinfo.registerReporter(&dummyReporter); @@ -50,8 +41,8 @@ HostInfoReporterTest::testHostInfoReporter() std::string jsonData = json.str(); vespalib::Slime slime; JsonFormat::decode(Memory(jsonData), slime); - CPPUNIT_ASSERT(slime.get()["dummy"]["foo"].asString() == "bar"); - CPPUNIT_ASSERT(!slime.get()["vtag"]["version"].asString().make_string().empty()); + EXPECT_EQ(slime.get()["dummy"]["foo"].asString(), "bar"); + EXPECT_FALSE(slime.get()["vtag"]["version"].asString().make_string().empty()); } -} // storage +} // storage diff --git a/storage/src/tests/common/hostreporter/util.cpp b/storage/src/tests/common/hostreporter/util.cpp index e0563a431e6..02e66b1dcc7 100644 --- a/storage/src/tests/common/hostreporter/util.cpp +++ b/storage/src/tests/common/hostreporter/util.cpp @@ -2,12 +2,11 @@ #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> #include <vespa/vespalib/stllike/asciistream.h> -namespace storage { -namespace util { +namespace storage::util { + namespace { using Object = vespalib::JsonStream::Object; using End = vespalib::JsonStream::End; @@ -27,8 +26,8 @@ reporterToSlime(HostReporter &hostReporter, vespalib::Slime &slime) { size_t parsed = JsonFormat::decode(Memory(jsonData), slime); if (parsed == 0) { - CPPUNIT_FAIL("jsonData is not json:\n" + jsonData); + throw std::runtime_error("jsonData is not json:\n" + jsonData); } } -} + } diff --git a/storage/src/tests/common/hostreporter/versionreportertest.cpp b/storage/src/tests/common/hostreporter/versionreportertest.cpp index dd58493f540..ee8fe2a5ff3 100644 --- a/storage/src/tests/common/hostreporter/versionreportertest.cpp +++ b/storage/src/tests/common/hostreporter/versionreportertest.cpp @@ -1,38 +1,29 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> + +#include "util.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" +#include <vespa/vespalib/gtest/gtest.h> +#include <gmock/gmock.h> -LOG_SETUP(".test.versionreporter"); +using namespace ::testing; 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() -{ +TEST(VersionReporterTest, version_reporter) { 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); + EXPECT_GT(version.size(), 2); + EXPECT_THAT(version, HasSubstr(".")); } + } // storage diff --git a/storage/src/tests/common/message_sender_stub.cpp b/storage/src/tests/common/message_sender_stub.cpp new file mode 100644 index 00000000000..c127f9071e5 --- /dev/null +++ b/storage/src/tests/common/message_sender_stub.cpp @@ -0,0 +1,91 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "message_sender_stub.h" +#include <vespa/storageapi/messageapi/storagecommand.h> +#include <vespa/storageapi/messageapi/storagereply.h> +#include <string> +#include <sstream> +#include <stdexcept> + +namespace storage { + +MessageSenderStub::MessageSenderStub() = default; +MessageSenderStub::~MessageSenderStub() = default; + +std::string +MessageSenderStub::getLastCommand(bool verbose) const +{ + if (commands.empty()) { + throw std::logic_error("Expected command where there was none"); + } + return dumpMessage(*commands[commands.size() - 1], true, verbose); +} + +std::string +MessageSenderStub::dumpMessage(const api::StorageMessage& msg, + bool includeAddress, + bool verbose) const +{ + std::ostringstream ost; + + if (verbose) { + ost << msg; + } else { + ost << msg.getType().getName(); + } + + if (includeAddress && msg.getAddress()) { + ost << " => " << msg.getAddress()->getIndex(); + } + if (verbose && msg.getType().isReply()) { + ost << " " << dynamic_cast<const api::StorageReply&>(msg).getResult(); + } + + return ost.str(); +} + +std::string +MessageSenderStub::getCommands(bool includeAddress, bool verbose, uint32_t fromIdx) const +{ + std::ostringstream ost; + + for (uint32_t i = fromIdx; i < commands.size(); i++) { + if (i != fromIdx) { + ost << ","; + } + + ost << dumpMessage(*commands[i], includeAddress, verbose); + } + + return ost.str(); +} + +std::string +MessageSenderStub::getLastReply(bool verbose) const +{ + if (replies.empty()) { + throw std::logic_error("Expected reply where there was none"); + } + + return dumpMessage(*replies.back(), + true, + verbose); + +} + +std::string +MessageSenderStub::getReplies(bool includeAddress, bool verbose) const +{ + std::ostringstream ost; + for (uint32_t i = 0; i < replies.size(); i++) { + if (i != 0) { + ost << ","; + } + + ost << dumpMessage(*replies[i], includeAddress, verbose); + } + + return ost.str(); +} + +} diff --git a/storage/src/tests/common/message_sender_stub.h b/storage/src/tests/common/message_sender_stub.h new file mode 100644 index 00000000000..73b1fcff9f4 --- /dev/null +++ b/storage/src/tests/common/message_sender_stub.h @@ -0,0 +1,47 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/storage/common/messagesender.h> +#include <vector> + +namespace storage { + +struct MessageSenderStub : MessageSender { + std::vector<std::shared_ptr<api::StorageCommand>> commands; + std::vector<std::shared_ptr<api::StorageReply>> replies; + + MessageSenderStub(); + ~MessageSenderStub() override; + + void clear() { + commands.clear(); + replies.clear(); + } + + void sendCommand(const std::shared_ptr<api::StorageCommand>& cmd) override { + commands.push_back(cmd); + } + + void sendReply(const std::shared_ptr<api::StorageReply>& reply) override { + replies.push_back(reply); + } + + std::string getLastCommand(bool verbose = true) const; + + std::string getCommands(bool includeAddress = false, + bool verbose = false, + uint32_t fromIndex = 0) const; + + std::string getLastReply(bool verbose = true) const; + + std::string getReplies(bool includeAddress = false, + bool verbose = false) const; + + std::string dumpMessage(const api::StorageMessage& msg, + bool includeAddress, + bool verbose) const; +}; + + +} diff --git a/storage/src/tests/common/metricstest.cpp b/storage/src/tests/common/metricstest.cpp index 9a9f05d500e..d1421845b81 100644 --- a/storage/src/tests/common/metricstest.cpp +++ b/storage/src/tests/common/metricstest.cpp @@ -14,6 +14,7 @@ #include <vespa/config/common/exceptions.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/gtest/gtest.h> +#include <gmock/gmock.h> #include <thread> #include <vespa/log/log.h> @@ -211,16 +212,12 @@ TEST_F(MetricsTest, filestor_metrics) { std::ostringstream ost; framework::HttpUrlPath path("metrics?interval=-1&format=text"); bool retVal = _metricsConsumer->reportStatus(ost, path); - CPPUNIT_ASSERT_MESSAGE("_metricsConsumer->reportStatus failed", retVal); + ASSERT_TRUE(retVal) << "_metricsConsumer->reportStatus failed"; std::string s = ost.str(); - CPPUNIT_ASSERT_MESSAGE("No get statistics in:\n" + s, - s.find("vds.filestor.alldisks.allthreads.get.sum.count count=240") != std::string::npos); - CPPUNIT_ASSERT_MESSAGE("No put statistics in:\n" + s, - s.find("vds.filestor.alldisks.allthreads.put.sum.count count=200") != std::string::npos); - CPPUNIT_ASSERT_MESSAGE("No remove statistics in:\n" + s, - s.find("vds.filestor.alldisks.allthreads.remove.sum.count count=120") != std::string::npos); - CPPUNIT_ASSERT_MESSAGE("No removenotfound stats in:\n" + s, - s.find("vds.filestor.alldisks.allthreads.remove.sum.not_found count=20") != std::string::npos); + EXPECT_THAT(s, HasSubstr("vds.filestor.alldisks.allthreads.get.sum.count count=240")); + EXPECT_THAT(s, HasSubstr("vds.filestor.alldisks.allthreads.put.sum.count count=200")); + EXPECT_THAT(s, HasSubstr("vds.filestor.alldisks.allthreads.remove.sum.count count=120")); + EXPECT_THAT(s, HasSubstr("vds.filestor.alldisks.allthreads.remove.sum.not_found count=20")); } #define ASSERT_METRIC(interval, metric, count) \ diff --git a/storage/src/tests/common/testhelper.h b/storage/src/tests/common/testhelper.h index 1bcc53dfe12..cc7f503e028 100644 --- a/storage/src/tests/common/testhelper.h +++ b/storage/src/tests/common/testhelper.h @@ -1,25 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include <vespa/messagebus/testlib/slobrok.h> #include <vespa/vdstestlib/cppunit/dirconfig.h> -#include <vespa/vdstestlib/cppunit/macros.h> - - #include <fstream> -#include <vespa/messagebus/testlib/slobrok.h> #include <sstream> -#define ASSERT_REPLY_COUNT(count, dummylink) \ - { \ - std::ostringstream msgost; \ - if ((dummylink).getNumReplies() != count) { \ - for (uint32_t ijx=0; ijx<(dummylink).getNumReplies(); ++ijx) { \ - msgost << (dummylink).getReply(ijx)->toString(true) << "\n"; \ - } \ - } \ - CPPUNIT_ASSERT_EQUAL_MSG(msgost.str(), size_t(count), \ - (dummylink).getNumReplies()); \ - } - namespace storage { void addFileConfig(vdstestlib::DirConfig& dc, diff --git a/storage/src/tests/common/teststorageapp.cpp b/storage/src/tests/common/teststorageapp.cpp index a720cd191e4..dd89082d3e7 100644 --- a/storage/src/tests/common/teststorageapp.cpp +++ b/storage/src/tests/common/teststorageapp.cpp @@ -7,7 +7,6 @@ #include <vespa/config-load-type.h> #include <vespa/config-fleetcontroller.h> #include <vespa/persistence/dummyimpl/dummypersistence.h> -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/config/config.h> @@ -122,7 +121,7 @@ TestStorageApp::waitUntilInitialized( error << " "; initializer->reportStatus(error, framework::HttpUrlPath("")); LOG(error, "%s", error.str().c_str()); - CPPUNIT_FAIL(error.str().c_str()); + throw std::runtime_error(error.str()); } } } @@ -170,9 +169,9 @@ TestServiceLayerApp::TestServiceLayerApp(DiskCount dc, NodeIndex index, lib::NodeState ns(*_nodeStateUpdater.getReportedNodeState()); ns.setDiskCount(dc); _nodeStateUpdater.setReportedNodeState(ns); - // Tests should know how many disks they want to use. If testing auto - // detection, you should not need this utility. - CPPUNIT_ASSERT(dc > 0); + // Tests should know how many disks they want to use. If testing auto + // detection, you should not need this utility. + assert(dc > 0); } TestServiceLayerApp::~TestServiceLayerApp() {} @@ -190,8 +189,7 @@ TestServiceLayerApp::setPersistenceProvider( spi::PersistenceProvider::UP provider) { _partitions = provider->getPartitionStates().getList(); - CPPUNIT_ASSERT_EQUAL(spi::PartitionId(_compReg.getDiskCount()), - _partitions.size()); + assert(spi::PartitionId(_compReg.getDiskCount()) == _partitions.size()); _persistenceProvider = std::move(provider); } |