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 /messagebus/src/tests/timeout |
Publish
Diffstat (limited to 'messagebus/src/tests/timeout')
-rw-r--r-- | messagebus/src/tests/timeout/.gitignore | 4 | ||||
-rw-r--r-- | messagebus/src/tests/timeout/CMakeLists.txt | 9 | ||||
-rw-r--r-- | messagebus/src/tests/timeout/DESC | 1 | ||||
-rw-r--r-- | messagebus/src/tests/timeout/FILES | 1 | ||||
-rw-r--r-- | messagebus/src/tests/timeout/timeout.cpp | 83 |
5 files changed, 98 insertions, 0 deletions
diff --git a/messagebus/src/tests/timeout/.gitignore b/messagebus/src/tests/timeout/.gitignore new file mode 100644 index 00000000000..c63e63d1685 --- /dev/null +++ b/messagebus/src/tests/timeout/.gitignore @@ -0,0 +1,4 @@ +.depend +Makefile +timeout_test +messagebus_timeout_test_app diff --git a/messagebus/src/tests/timeout/CMakeLists.txt b/messagebus/src/tests/timeout/CMakeLists.txt new file mode 100644 index 00000000000..f50b81ff03f --- /dev/null +++ b/messagebus/src/tests/timeout/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_timeout_test_app + SOURCES + timeout.cpp + DEPENDS + messagebus_messagebus-test + messagebus +) +vespa_add_test(NAME messagebus_timeout_test_app COMMAND messagebus_timeout_test_app) diff --git a/messagebus/src/tests/timeout/DESC b/messagebus/src/tests/timeout/DESC new file mode 100644 index 00000000000..c90169db16e --- /dev/null +++ b/messagebus/src/tests/timeout/DESC @@ -0,0 +1 @@ +timeout test. Take a look at timeout.cpp for details. diff --git a/messagebus/src/tests/timeout/FILES b/messagebus/src/tests/timeout/FILES new file mode 100644 index 00000000000..b36cdeb4ddf --- /dev/null +++ b/messagebus/src/tests/timeout/FILES @@ -0,0 +1 @@ +timeout.cpp diff --git a/messagebus/src/tests/timeout/timeout.cpp b/messagebus/src/tests/timeout/timeout.cpp new file mode 100644 index 00000000000..8d6b1739776 --- /dev/null +++ b/messagebus/src/tests/timeout/timeout.cpp @@ -0,0 +1,83 @@ +// 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("timeout_test"); +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/messagebus/errorcode.h> +#include <vespa/messagebus/emptyreply.h> +#include <vespa/messagebus/sourcesession.h> +#include <vespa/messagebus/sourcesessionparams.h> +#include <vespa/messagebus/destinationsession.h> +#include <vespa/messagebus/network/identity.h> +#include <vespa/messagebus/testlib/receptor.h> +#include <vespa/messagebus/testlib/simplemessage.h> +#include <vespa/messagebus/testlib/slobrok.h> +#include <vespa/messagebus/testlib/testserver.h> + +using namespace mbus; + +class Test : public vespalib::TestApp { +public: + int Main(); + void testZeroTimeout(); + void testMessageExpires(); +}; + +TEST_APPHOOK(Test); + +int +Test::Main() +{ + TEST_INIT("timeout_test"); + + testZeroTimeout(); TEST_FLUSH(); + testMessageExpires(); TEST_FLUSH(); + + TEST_DONE(); +} + +void +Test::testZeroTimeout() +{ + Slobrok slobrok; + TestServer srcServer(Identity("src"), RoutingSpec(), slobrok); + TestServer dstServer(Identity("dst"), RoutingSpec(), slobrok); + + Receptor srcHandler; + SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(0)); + Receptor dstHandler; + DestinationSession::UP dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler); + + ASSERT_TRUE(srcServer.waitSlobrok("dst/session", 1)); + ASSERT_TRUE(srcSession->send(Message::UP(new SimpleMessage("msg")), "dst/session", true).isAccepted()); + + Reply::UP reply = srcHandler.getReply(); + ASSERT_TRUE(reply.get() != NULL); + EXPECT_EQUAL(1u, reply->getNumErrors()); + EXPECT_EQUAL((uint32_t)ErrorCode::TIMEOUT, reply->getError(0).getCode()); +} + +void +Test::testMessageExpires() +{ + Slobrok slobrok; + TestServer srcServer(Identity("src"), RoutingSpec(), slobrok); + TestServer dstServer(Identity("dst"), RoutingSpec(), slobrok); + + Receptor srcHandler, dstHandler; + SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(1)); + DestinationSession::UP dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler); + + ASSERT_TRUE(srcServer.waitSlobrok("dst/session", 1)); + ASSERT_TRUE(srcSession->send(Message::UP(new SimpleMessage("msg")), "dst/session", true).isAccepted()); + + Reply::UP reply = srcHandler.getReply(); + ASSERT_TRUE(reply.get() != NULL); + EXPECT_EQUAL(1u, reply->getNumErrors()); + EXPECT_EQUAL((uint32_t)ErrorCode::TIMEOUT, reply->getError(0).getCode()); + + Message::UP msg = dstHandler.getMessage(1); + if (msg.get() != NULL) { + msg->discard(); + } +} |