diff options
author | Henning Baldersheim <balder@oath.com> | 2018-10-04 19:40:38 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-10-04 21:04:02 +0200 |
commit | 3f2b1a9230fbab12f2e8b5afcf1e0ad72f3d872a (patch) | |
tree | d442890dd2a84bd325eeb0465d7a11789cdf2900 /documentapi | |
parent | faa5b86be61ef5f3791f31d5da0d17ce2e807691 (diff) |
Remove the costly and unnecessary setSlobrokId interface.
Diffstat (limited to 'documentapi')
-rw-r--r-- | documentapi/src/tests/policies/testframe.cpp | 59 | ||||
-rw-r--r-- | documentapi/src/tests/policies/testframe.h | 26 |
2 files changed, 28 insertions, 57 deletions
diff --git a/documentapi/src/tests/policies/testframe.cpp b/documentapi/src/tests/policies/testframe.cpp index d99d99b9ec0..4cdc5d4ba14 100644 --- a/documentapi/src/tests/policies/testframe.cpp +++ b/documentapi/src/tests/policies/testframe.cpp @@ -20,14 +20,9 @@ private: string _address; public: - MyServiceAddress(const string &address) : - _address(address) { - // empty - } + MyServiceAddress(const string &address) : _address(address) {} - const string &getAddress() { - return _address; - } + const string &getAddress() { return _address; } }; class MyNetwork : public mbus::RPCNetwork { @@ -37,13 +32,12 @@ private: public: MyNetwork(const mbus::RPCNetworkParams ¶ms) : mbus::RPCNetwork(params), - _nodes() { - // empty - } + _nodes() + { } bool allocServiceAddress(mbus::RoutingNode &recipient) override { string hop = recipient.getRoute().getHop(0).toString(); - recipient.setServiceAddress(mbus::IServiceAddress::UP(new MyServiceAddress(hop))); + recipient.setServiceAddress(std::make_unique<MyServiceAddress>(hop)); return true; } @@ -63,18 +57,14 @@ public: TestFrame::TestFrame(const std::shared_ptr<const DocumentTypeRepo> &repo, const string &ident) : _identity(ident), - _slobrok(new mbus::Slobrok()), + _slobrok(std::make_shared<mbus::Slobrok>()), _set(), - _net(new MyNetwork(mbus::RPCNetworkParams() - .setIdentity(mbus::Identity(ident)) - .setSlobrokConfig(_slobrok->config()))), - _mbus(new mbus::MessageBus(*_net, mbus::MessageBusParams() - .addProtocol(mbus::IProtocol::SP(new DocumentProtocol(_set, repo))))), + _net(std::make_shared<MyNetwork>(mbus::RPCNetworkParams(_slobrok->config()).setIdentity(mbus::Identity(ident)))), + _mbus(std::make_shared<mbus::MessageBus>(*_net, mbus::MessageBusParams().addProtocol(std::make_shared<DocumentProtocol>(_set, repo)))), _msg(), _hop(mbus::HopSpec("foo", "bar")), _handler() { - // empty } TestFrame::TestFrame(TestFrame &frame) : @@ -87,13 +77,9 @@ TestFrame::TestFrame(TestFrame &frame) : _hop(mbus::HopSpec("baz", "cox")), _handler() { - // empty } -TestFrame::~TestFrame() -{ - // empty -} +TestFrame::~TestFrame() = default; void TestFrame::setHop(const mbus::HopSpec &hop) @@ -107,7 +93,7 @@ TestFrame::select(std::vector<mbus::RoutingNode*> &selected, uint32_t numExpecte { _msg->setRoute(mbus::Route::parse(_hop.getName())); _msg->pushHandler(*this); - mbus::SendProxy &proxy = *(new mbus::SendProxy(*_mbus, *_net, NULL)); // deletes self + mbus::SendProxy &proxy = *(new mbus::SendProxy(*_mbus, *_net, nullptr)); // deletes self proxy.handleMessage(std::move(_msg)); static_cast<MyNetwork&>(*_net).removeNodes(selected); @@ -125,21 +111,18 @@ TestFrame::testSelect(const std::vector<string> &expected) if (!select(selected, expected.size())) { LOG(error, "Failed to select recipients."); for (size_t i = 0; i < selected.size(); ++i) { - LOG(error, "Selected: %s", - selected[i]->getRoute().toString().c_str()); + LOG(error, "Selected: %s", selected[i]->getRoute().toString().c_str()); } return false; } - for (std::vector<mbus::RoutingNode*>::iterator it = selected.begin(); - it != selected.end(); ++it) - { - string route = (*it)->getRoute().toString(); + for (mbus::RoutingNode* node : selected) { + string route = node->getRoute().toString(); if (find(expected.begin(), expected.end(), route) == expected.end()) { LOG(error, "Recipient '%s' not selected.", route.c_str()); } - (*it)->handleReply(mbus::Reply::UP(new mbus::EmptyReply())); + node->handleReply(std::make_unique<mbus::EmptyReply>()); } - if (_handler.getReply(600).get() == NULL) { + if (_handler.getReply(600).get() == nullptr) { LOG(error, "Reply not propagated to handler."); return false; } @@ -168,25 +151,23 @@ TestFrame::testMerge(const ReplyMap &replies, return false; } - for (std::vector<mbus::RoutingNode*>::iterator it = selected.begin(); - it != selected.end(); ++it) - { - string route = (*it)->getRoute().toString(); + for (mbus::RoutingNode* node : selected) { + string route = node->getRoute().toString(); ReplyMap::const_iterator mip = replies.find(route); if (mip == replies.end()) { LOG(error, "Recipient '%s' not expected.", route.c_str()); return false; } - mbus::Reply::UP ret(new mbus::SimpleReply(route)); + auto ret = std::make_unique<mbus::SimpleReply>(route); if (mip->second != mbus::ErrorCode::NONE) { ret->addError(mbus::Error(mip->second, route)); } - (*it)->handleReply(std::move(ret)); + node->handleReply(std::move(ret)); } mbus::Reply::UP reply = _handler.getReply(600); - if (reply.get() == NULL) { + if (reply.get() == nullptr) { LOG(error, "Reply not propagated to handler."); return false; } diff --git a/documentapi/src/tests/policies/testframe.h b/documentapi/src/tests/policies/testframe.h index cc5101905a1..4f4dfa7e2a8 100644 --- a/documentapi/src/tests/policies/testframe.h +++ b/documentapi/src/tests/policies/testframe.h @@ -13,16 +13,14 @@ using documentapi::string; class TestFrame : public mbus::IReplyHandler { private: - string _identity; + string _identity; std::shared_ptr<mbus::Slobrok> _slobrok; - documentapi::LoadTypeSet _set; + documentapi::LoadTypeSet _set; std::shared_ptr<mbus::INetwork> _net; std::shared_ptr<mbus::MessageBus> _mbus; - mbus::Message::UP _msg; - mbus::HopSpec _hop; - mbus::Receptor _handler; - - TestFrame &operator=(const TestFrame &); // hide + mbus::Message::UP _msg; + mbus::HopSpec _hop; + mbus::Receptor _handler; public: /** @@ -38,6 +36,8 @@ public: TestFrame(const std::shared_ptr<const document::DocumentTypeRepo> &repo, const string &ident = "anonymous"); + TestFrame &operator=(const TestFrame &) = delete; + /** * Create a test frame running on the same slobrok and mbus as another. * @@ -45,10 +45,7 @@ public: */ TestFrame(TestFrame &frame); - /** - * Cleans up allocated resources. - */ - virtual ~TestFrame(); + ~TestFrame() override; /** * Routes the contained message based on the current setup, and returns the leaf send contexts. @@ -137,13 +134,6 @@ public: const string &getIdentity() { return _identity; } /** - * Returns the private slobrok server. - * - * @return The slobrok. - */ - mbus::Slobrok &getSlobrok() { return *_slobrok; } - - /** * Returns the private message bus. * * @return The bus. |