diff options
author | Arnstein Ressem <aressem@gmail.com> | 2016-09-14 08:45:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-14 08:45:26 +0200 |
commit | 4b194fbcf79d5af1731d960ce4abbc2574ba397d (patch) | |
tree | 49934000a4d61790615c7c7b71cbe415478c073d /messagebus_test/src/tests/error/cpp-server.cpp | |
parent | 4bf517333b0616ce3e7947c28afb378cd10fe5c9 (diff) |
Revert "Revert "Aressem/move messagebus test tests to separate module""
Diffstat (limited to 'messagebus_test/src/tests/error/cpp-server.cpp')
-rw-r--r-- | messagebus_test/src/tests/error/cpp-server.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/messagebus_test/src/tests/error/cpp-server.cpp b/messagebus_test/src/tests/error/cpp-server.cpp new file mode 100644 index 00000000000..2eb929f6ca9 --- /dev/null +++ b/messagebus_test/src/tests/error/cpp-server.cpp @@ -0,0 +1,73 @@ +// 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> +LOG_SETUP("cpp-server"); +#include <vespa/messagebus/messagebus.h> +#include <vespa/messagebus/destinationsession.h> +#include <vespa/messagebus/testlib/simplemessage.h> +#include <vespa/messagebus/testlib/simplereply.h> +#include <vespa/messagebus/testlib/simpleprotocol.h> +#include <vespa/messagebus/rpcmessagebus.h> +#include <vespa/messagebus/iprotocol.h> +#include <vespa/messagebus/protocolset.h> +#include <vespa/messagebus/emptyreply.h> +#include <vespa/messagebus/error.h> +#include <vespa/messagebus/errorcode.h> + +using namespace mbus; + +class Server : public IMessageHandler +{ +private: + DestinationSession::UP _session; +public: + Server(MessageBus &bus); + ~Server(); + void handleMessage(Message::UP msg); +}; + +Server::Server(MessageBus &bus) + : _session(bus.createDestinationSession("session", true, *this)) +{ + fprintf(stderr, "cpp server started\n"); +} + +Server::~Server() +{ + _session.reset(); +} + +void +Server::handleMessage(Message::UP msg) { + Reply::UP reply(new EmptyReply()); + msg->swapState(*reply); + reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 1, "ERR 1")); + reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 2, "ERR 2")); + _session->reply(std::move(reply)); +} + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams() + .setIdentity(Identity("server/cpp")) + .setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + Server server(mb.getMessageBus()); + while (true) { + FastOS_Thread::Sleep(1000); + } + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} |