summaryrefslogtreecommitdiffstats
path: root/storage/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-10-14 17:53:06 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-10-14 17:57:29 +0000
commit433d1fccf19f4fd390b54ac7c149c17529a37e6a (patch)
treee31c4021dfc3571ed21849af02e703d00b564a21 /storage/src/tests
parent1ad0641192b439447750c49fee0ca6255d4601fd (diff)
GC unuse code and use std::mutex/std:condition_variable over vespalib::Monitor
Diffstat (limited to 'storage/src/tests')
-rw-r--r--storage/src/tests/storageserver/dummystoragelink.cpp181
-rw-r--r--storage/src/tests/storageserver/dummystoragelink.h115
2 files changed, 0 insertions, 296 deletions
diff --git a/storage/src/tests/storageserver/dummystoragelink.cpp b/storage/src/tests/storageserver/dummystoragelink.cpp
deleted file mode 100644
index ab7c413f2ea..00000000000
--- a/storage/src/tests/storageserver/dummystoragelink.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/storageframework/defaultimplementation/clock/realclock.h>
-#include <tests/common/dummystoragelink.h>
-#include <sys/time.h>
-
-namespace storage {
-
-DummyStorageLink* DummyStorageLink::_last(0);
-
-DummyStorageLink::DummyStorageLink()
- : StorageLink("Dummy storage link"),
- _commands(),
- _replies(),
- _injected(),
- _autoReply(false),
- _useDispatch(false),
- _ignore(false),
- _waitMonitor()
-{
- _last = this;
-}
-
-DummyStorageLink::~DummyStorageLink()
-{
- // Often a chain with dummy link on top is deleted in unit tests.
- // If they haven't been closed already, close them for a cleaner
- // shutdown
- if (getState() == OPENED) {
- close();
- flush();
- }
- closeNextLink();
- reset();
-}
-
-bool DummyStorageLink::onDown(const api::StorageMessage::SP& cmd)
-{
- if (_ignore) {
- return false;
- }
- if (_injected.size() > 0) {
- vespalib::LockGuard guard(_lock);
- sendUp(*_injected.begin());
- _injected.pop_front();
- } else if (_autoReply) {
- if (!cmd->getType().isReply()) {
- std::shared_ptr<api::StorageReply> reply(
- std::dynamic_pointer_cast<api::StorageCommand>(cmd)
- ->makeReply().release());
- reply->setResult(api::ReturnCode(
- api::ReturnCode::OK, "Automatically generated reply"));
- sendUp(reply);
- }
- }
- if (isBottom()) {
- vespalib::MonitorGuard lock(_waitMonitor);
- {
- vespalib::LockGuard guard(_lock);
- _commands.push_back(cmd);
- }
- lock.broadcast();
- return true;
- }
- return StorageLink::onDown(cmd);
-}
-
-bool DummyStorageLink::onUp(const api::StorageMessage::SP& reply) {
- if (isTop()) {
- vespalib::MonitorGuard lock(_waitMonitor);
- {
- vespalib::LockGuard guard(_lock);
- _replies.push_back(reply);
- }
- lock.broadcast();
- return true;
- }
- return StorageLink::onUp(reply);
-
-}
-
-void DummyStorageLink::injectReply(api::StorageReply* reply)
-{
- assert(reply);
- vespalib::LockGuard guard(_lock);
- _injected.push_back(std::shared_ptr<api::StorageReply>(reply));
-}
-
-void DummyStorageLink::reset() {
- vespalib::MonitorGuard lock(_waitMonitor);
- vespalib::LockGuard guard(_lock);
- _commands.clear();
- _replies.clear();
- _injected.clear();
-}
-
-void DummyStorageLink::waitForMessages(unsigned int msgCount, int timeout)
-{
- framework::defaultimplementation::RealClock clock;
- framework::MilliSecTime endTime(
- clock.getTimeInMillis() + framework::MilliSecTime(timeout * 1000));
- vespalib::MonitorGuard lock(_waitMonitor);
- while (_commands.size() + _replies.size() < msgCount) {
- if (timeout != 0 && clock.getTimeInMillis() > endTime) {
- std::ostringstream ost;
- ost << "Timed out waiting for " << msgCount << " messages to "
- << "arrive in dummy storage link. Only "
- << (_commands.size() + _replies.size()) << " messages seen "
- << "after timout of " << timeout << " seconds was reached.";
- throw vespalib::IllegalStateException(ost.str(), VESPA_STRLOC);
- }
- if (timeout >= 0) {
- lock.wait((endTime - clock.getTimeInMillis()).getTime());
- } else {
- lock.wait();
- }
- }
-}
-
-void DummyStorageLink::waitForMessage(const api::MessageType& type, int timeout)
-{
- framework::defaultimplementation::RealClock clock;
- framework::MilliSecTime endTime(
- clock.getTimeInMillis() + framework::MilliSecTime(timeout * 1000));
- vespalib::MonitorGuard lock(_waitMonitor);
- while (true) {
- for (uint32_t i=0; i<_commands.size(); ++i) {
- if (_commands[i]->getType() == type) return;
- }
- for (uint32_t i=0; i<_replies.size(); ++i) {
- if (_replies[i]->getType() == type) return;
- }
- if (timeout != 0 && clock.getTimeInMillis() > endTime) {
- std::ostringstream ost;
- ost << "Timed out waiting for " << type << " message to "
- << "arrive in dummy storage link. Only "
- << (_commands.size() + _replies.size()) << " messages seen "
- << "after timout of " << timeout << " seconds was reached.";
- if (_commands.size() == 1) {
- ost << " Found command of type " << _commands[0]->getType();
- }
- if (_replies.size() == 1) {
- ost << " Found command of type " << _replies[0]->getType();
- }
- throw vespalib::IllegalStateException(ost.str(), VESPA_STRLOC);
- }
- if (timeout >= 0) {
- lock.wait((endTime - clock.getTimeInMillis()).getTime());
- } else {
- lock.wait();
- }
- }
-}
-
-api::StorageMessage::SP
-DummyStorageLink::getAndRemoveMessage(const api::MessageType& type)
-{
- vespalib::MonitorGuard lock(_waitMonitor);
- for (std::vector<api::StorageMessage::SP>::iterator it = _commands.begin();
- it != _commands.end(); ++it)
- {
- if ((*it)->getType() == type) {
- api::StorageMessage::SP result(*it);
- _commands.erase(it);
- return result;
- }
- }
- for (std::vector<api::StorageMessage::SP>::iterator it = _replies.begin();
- it != _replies.end(); ++it)
- {
- if ((*it)->getType() == type) {
- api::StorageMessage::SP result(*it);
- _replies.erase(it);
- return result;
- }
- }
- std::ostringstream ost;
- ost << "No message of type " << type << " found.";
- throw vespalib::IllegalStateException(ost.str(), VESPA_STRLOC);
-}
-
-} // storage
diff --git a/storage/src/tests/storageserver/dummystoragelink.h b/storage/src/tests/storageserver/dummystoragelink.h
deleted file mode 100644
index 3902e1db19c..00000000000
--- a/storage/src/tests/storageserver/dummystoragelink.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/vespalib/util/sync.h>
-#include <list>
-#include <sstream>
-#include <vespa/storageapi/messageapi/storagecommand.h>
-#include <string>
-#include <vector>
-#include <vespa/storage/common/storagelink.h>
-#include <vespa/storage/common/bucketmessages.h>
-#include <vespa/storageapi/message/internal.h>
-
-class FastOS_ThreadPool;
-
-namespace storage {
-
-class DummyStorageLink : public StorageLink {
-
- mutable vespalib::Lock _lock; // to protect below containers:
- std::vector<api::StorageMessage::SP> _commands;
- std::vector<api::StorageMessage::SP> _replies;
- std::list<api::StorageMessage::SP> _injected;
-
- bool _autoReply;
- bool _useDispatch;
- bool _ignore;
- static DummyStorageLink* _last;
- vespalib::Monitor _waitMonitor;
-
-public:
- DummyStorageLink();
- ~DummyStorageLink();
-
- bool onDown(const api::StorageMessage::SP&);
- bool onUp(const api::StorageMessage::SP&);
-
- void addOnTopOfChain(StorageLink& link) {
- link.addTestLinkOnTop(this);
- }
-
- void print(std::ostream& ost, bool verbose, const std::string& indent) const
- {
- (void) verbose;
- ost << indent << "DummyStorageLink("
- << "autoreply = " << (_autoReply ? "on" : "off")
- << ", dispatch = " << (_useDispatch ? "on" : "off")
- << ", " << _commands.size() << " commands"
- << ", " << _replies.size() << " replies";
- if (_injected.size() > 0)
- ost << ", " << _injected.size() << " injected";
- ost << ")";
- }
-
- void injectReply(api::StorageReply* reply);
- void reset();
- void setAutoreply(bool autoReply) { _autoReply = autoReply; }
- void setIgnore(bool ignore) { _ignore = ignore; }
- // Timeout is given in seconds
- void waitForMessages(unsigned int msgCount = 1, int timeout = -1);
- // Wait for a single message of a given type
- void waitForMessage(const api::MessageType&, int timeout = -1);
-
- api::StorageMessage::SP getCommand(size_t i) const {
- vespalib::LockGuard guard(_lock);
- api::StorageMessage::SP ret = _commands[i];
- return ret;
- }
- api::StorageMessage::SP getReply(size_t i) const {
- vespalib::LockGuard guard(_lock);
- api::StorageMessage::SP ret = _replies[i];
- return ret;
- }
- size_t getNumCommands() const {
- vespalib::LockGuard guard(_lock);
- return _commands.size();
- }
- size_t getNumReplies() const {
- vespalib::LockGuard guard(_lock);
- return _replies.size();
- }
-
- const std::vector<api::StorageMessage::SP>& getCommands() const
- { return _commands; }
- const std::vector<api::StorageMessage::SP>& getReplies() const
- { return _replies; }
-
- std::vector<api::StorageMessage::SP> getCommandsOnce() {
- vespalib::MonitorGuard lock(_waitMonitor);
- std::vector<api::StorageMessage::SP> retval;
- {
- vespalib::LockGuard guard(_lock);
- retval.swap(_commands);
- }
- return retval;
- }
-
- std::vector<api::StorageMessage::SP> getRepliesOnce() {
- vespalib::MonitorGuard lock(_waitMonitor);
- std::vector<api::StorageMessage::SP> retval;
- {
- vespalib::LockGuard guard(_lock);
- retval.swap(_replies);
- }
- return retval;
- }
-
- api::StorageMessage::SP getAndRemoveMessage(const api::MessageType&);
-
- static DummyStorageLink* getLast() { return _last; }
-};
-
-}
-