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/distributor/messagesenderstub.cpp |
Publish
Diffstat (limited to 'storage/src/tests/distributor/messagesenderstub.cpp')
-rw-r--r-- | storage/src/tests/distributor/messagesenderstub.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/storage/src/tests/distributor/messagesenderstub.cpp b/storage/src/tests/distributor/messagesenderstub.cpp new file mode 100644 index 00000000000..88210a94848 --- /dev/null +++ b/storage/src/tests/distributor/messagesenderstub.cpp @@ -0,0 +1,88 @@ +// 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 <tests/distributor/messagesenderstub.h> +#include <tests/distributor/distributortestutil.h> + +namespace storage { + +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(); +} + +} + |