blob: 7e3a36fc93e970f557c112c66027332fead3fdc8 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "testserver.h"
#include "simpleprotocol.h"
#include "slobrok.h"
#include "slobrokstate.h"
#include <vespa/vespalib/component/vtag.h>
#include <thread>
namespace mbus {
VersionedRPCNetwork::VersionedRPCNetwork(const RPCNetworkParams ¶ms) :
RPCNetwork(params),
_version(vespalib::Vtag::currentVersion)
{}
VersionedRPCNetwork::~VersionedRPCNetwork() = default;
void
VersionedRPCNetwork::setVersion(const vespalib::Version &version)
{
_version = version;
flushTargetPool();
}
TestServer::TestServer(const Identity &ident,
const RoutingSpec &spec,
const Slobrok &slobrok,
IProtocol::SP protocol) :
net(RPCNetworkParams(slobrok.config()).setIdentity(ident)),
mb(net, ProtocolSet().add(std::make_shared<SimpleProtocol>()).add(protocol))
{
mb.setupRouting(spec);
}
TestServer::TestServer(const MessageBusParams &mbusParams,
const RPCNetworkParams &netParams) :
net(netParams),
mb(net, mbusParams)
{}
TestServer::~TestServer() = default;
bool
TestServer::waitSlobrok(const string &pattern, uint32_t cnt)
{
return waitState(SlobrokState().add(pattern, cnt));
}
bool
TestServer::waitState(const SlobrokState &slobrokState)
{
for (uint32_t i = 0; i < 12000; ++i) {
bool done = true;
for (SlobrokState::ITR itr = slobrokState.begin();
itr != slobrokState.end(); ++itr)
{
slobrok::api::IMirrorAPI::SpecList res = net.getMirror().lookup(itr->first);
if (res.size() != itr->second) {
done = false;
}
}
if (done) {
return true;
}
std::this_thread::sleep_for(10ms);
}
return false;
}
}
|