aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/tests/protocolrepository/protocolrepository.cpp
blob: 20649d56d1329653e910e1ffd6a19c5f65f59ce4 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/messagebus/protocolrepository.h>
#include <vespa/vespalib/testkit/testapp.h>

using namespace mbus;

TEST_SETUP(Test);

class TestProtocol : public IProtocol {
private:
    const string _name;

public:

    TestProtocol(const string &name) noexcept
        : _name(name)
    { }

    const string & getName() const override { return _name; }

    IRoutingPolicy::UP createPolicy(const string &, const string &) const override {
        throw std::exception();
    }

    Blob encode(const vespalib::Version &, const Routable &) const override {
        throw std::exception();
    }

    Routable::UP decode(const vespalib::Version &, BlobRef ) const override {
        throw std::exception();
    }
};

int
Test::Main()
{
    TEST_INIT("protocolrepository_test");

    ProtocolRepository repo;
    IProtocol::SP prev;
    prev = repo.putProtocol(std::make_shared<TestProtocol>("foo"));
    ASSERT_FALSE(prev);

    IRoutingPolicy::SP policy = repo.getRoutingPolicy("foo", "bar", "baz");
    prev = repo.putProtocol(std::make_shared<TestProtocol>("foo"));
    ASSERT_TRUE(prev);
    ASSERT_NOT_EQUAL(prev.get(), repo.getProtocol("foo"));

    policy = repo.getRoutingPolicy("foo", "bar", "baz");
    ASSERT_FALSE(policy);

    TEST_DONE();
}