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/simpleprotocol |
Publish
Diffstat (limited to 'messagebus/src/tests/simpleprotocol')
-rw-r--r-- | messagebus/src/tests/simpleprotocol/.gitignore | 4 | ||||
-rw-r--r-- | messagebus/src/tests/simpleprotocol/CMakeLists.txt | 9 | ||||
-rw-r--r-- | messagebus/src/tests/simpleprotocol/DESC | 3 | ||||
-rw-r--r-- | messagebus/src/tests/simpleprotocol/FILES | 1 | ||||
-rw-r--r-- | messagebus/src/tests/simpleprotocol/simpleprotocol.cpp | 72 |
5 files changed, 89 insertions, 0 deletions
diff --git a/messagebus/src/tests/simpleprotocol/.gitignore b/messagebus/src/tests/simpleprotocol/.gitignore new file mode 100644 index 00000000000..8a096b651d4 --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/.gitignore @@ -0,0 +1,4 @@ +.depend +Makefile +simpleprotocol_test +messagebus_simpleprotocol_test_app diff --git a/messagebus/src/tests/simpleprotocol/CMakeLists.txt b/messagebus/src/tests/simpleprotocol/CMakeLists.txt new file mode 100644 index 00000000000..4b4e777ea57 --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/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_simpleprotocol_test_app + SOURCES + simpleprotocol.cpp + DEPENDS + messagebus_messagebus-test + messagebus +) +vespa_add_test(NAME messagebus_simpleprotocol_test_app COMMAND messagebus_simpleprotocol_test_app) diff --git a/messagebus/src/tests/simpleprotocol/DESC b/messagebus/src/tests/simpleprotocol/DESC new file mode 100644 index 00000000000..91d0fa36c57 --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/DESC @@ -0,0 +1,3 @@ +Small test of the simple protocol defined in the test library. The +protocol will be used to test other messagebus features, including +cross-language compatibility. diff --git a/messagebus/src/tests/simpleprotocol/FILES b/messagebus/src/tests/simpleprotocol/FILES new file mode 100644 index 00000000000..f3c58f7d66e --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/FILES @@ -0,0 +1 @@ +simpleprotocol.cpp diff --git a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp new file mode 100644 index 00000000000..eaf609a2be1 --- /dev/null +++ b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp @@ -0,0 +1,72 @@ +// 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("simpleprotocol_test"); + +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/messagebus/errorcode.h> +#include <vespa/messagebus/ireplyhandler.h> +#include <vespa/messagebus/network/identity.h> +#include <vespa/messagebus/routing/routingcontext.h> +#include <vespa/messagebus/testlib/receptor.h> +#include <vespa/messagebus/testlib/simpleprotocol.h> +#include <vespa/messagebus/testlib/simplemessage.h> +#include <vespa/messagebus/testlib/simplereply.h> +#include <vespa/messagebus/testlib/slobrok.h> +#include <vespa/messagebus/testlib/testserver.h> +#include <vespa/messagebus/vtag.h> + +using namespace mbus; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("simpleprotocol_test"); + + vespalib::Version version = Vtag::currentVersion; + SimpleProtocol protocol; + EXPECT_TRUE(protocol.getName() == "Simple"); + + { + // test protocol + IRoutingPolicy::UP bogus = protocol.createPolicy("bogus", ""); + EXPECT_TRUE(bogus.get() == 0); + } + TEST_FLUSH(); + { + // test SimpleMessage + Message::UP msg(new SimpleMessage("test")); + EXPECT_TRUE(!msg->isReply()); + EXPECT_TRUE(msg->getProtocol() == SimpleProtocol::NAME); + EXPECT_TRUE(msg->getType() == SimpleProtocol::MESSAGE); + EXPECT_TRUE(static_cast<SimpleMessage&>(*msg).getValue() == "test"); + Blob b = protocol.encode(version, *msg); + EXPECT_TRUE(b.size() > 0); + Routable::UP tmp = protocol.decode(version, BlobRef(b)); + ASSERT_TRUE(tmp.get() != 0); + EXPECT_TRUE(!tmp->isReply()); + EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); + EXPECT_TRUE(tmp->getType() == SimpleProtocol::MESSAGE); + EXPECT_TRUE(static_cast<SimpleMessage&>(*tmp).getValue() == "test"); + } + TEST_FLUSH(); + { + // test SimpleReply + Reply::UP reply(new SimpleReply("reply")); + EXPECT_TRUE(reply->isReply()); + EXPECT_TRUE(reply->getProtocol() == SimpleProtocol::NAME); + EXPECT_TRUE(reply->getType() == SimpleProtocol::REPLY); + EXPECT_TRUE(static_cast<SimpleReply&>(*reply).getValue() == "reply"); + Blob b = protocol.encode(version, *reply); + EXPECT_TRUE(b.size() > 0); + Routable::UP tmp = protocol.decode(version, BlobRef(b)); + ASSERT_TRUE(tmp.get() != 0); + EXPECT_TRUE(tmp->isReply()); + EXPECT_TRUE(tmp->getProtocol() == SimpleProtocol::NAME); + EXPECT_TRUE(tmp->getType() == SimpleProtocol::REPLY); + EXPECT_TRUE(static_cast<SimpleReply&>(*tmp).getValue() == "reply"); + } + TEST_DONE(); +} |