blob: 2dd3e28c35d023019bb23d4a4560c08399e5d7e7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#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/ireplyhandler.h>
#include <vespa/messagebus/routing/routingcontext.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/component/vtag.h>
using namespace mbus;
TEST_SETUP(Test);
int
Test::Main()
{
TEST_INIT("simpleprotocol_test");
vespalib::Version version = vespalib::Vtag::currentVersion;
SimpleProtocol protocol;
EXPECT_TRUE(protocol.getName() == "Simple");
EXPECT_EQUAL(152u, sizeof(Result));
EXPECT_EQUAL(136u, sizeof(Error));
EXPECT_EQUAL(56u, sizeof(Routable));
{
// test protocol
IRoutingPolicy::UP bogus = protocol.createPolicy("bogus", "");
EXPECT_FALSE(bogus);
}
TEST_FLUSH();
{
// test SimpleMessage
EXPECT_EQUAL(104u, sizeof(Message));
EXPECT_EQUAL(184u, sizeof(SimpleMessage));
auto msg = std::make_unique<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);
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
EXPECT_EQUAL(96u, sizeof(Reply));
EXPECT_EQUAL(160u, sizeof(SimpleReply));
auto reply = std::make_unique<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);
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();
}
|