diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 13:52:11 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 13:59:33 +0000 |
commit | 408d4a4aa6bc5896a2ea73164ddb4cae780e6890 (patch) | |
tree | 85fd355ff75d619d57feb18993fdefa474e51111 | |
parent | 041c857aa774df3ac8ea1ae83390f36691c6b2d3 (diff) |
You must always reply with the same RPCRequest
-rw-r--r-- | config/src/tests/frt/frt.cpp | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/config/src/tests/frt/frt.cpp b/config/src/tests/frt/frt.cpp index 3eda573cb27..fd02b388f0b 100644 --- a/config/src/tests/frt/frt.cpp +++ b/config/src/tests/frt/frt.cpp @@ -32,6 +32,44 @@ using namespace config::protocol::v3; namespace { +struct Response { + vespalib::string defName; + vespalib::string defMd5; + vespalib::string configId; + vespalib::string configXxhash64; + int changed; + long generation; + StringVector payload; + vespalib::string ns; + void encodeResponse(FRT_RPCRequest * req) { + FRT_Values & ret = *req->GetReturn(); + + ret.AddString(defName.c_str()); + ret.AddString(""); + ret.AddString(defMd5.c_str()); + ret.AddString(configId.c_str()); + ret.AddString(configXxhash64.c_str()); + ret.AddInt32(changed); + ret.AddInt64(generation); + FRT_StringValue * payload_arr = ret.AddStringArray(payload.size()); + for (uint32_t i = 0; i < payload.size(); i++) { + ret.SetString(&payload_arr[i], payload[i].c_str()); + } + if (!ns.empty()) + ret.AddString(ns.c_str()); + req->SetError(FRTE_NO_ERROR); + } + Response(vespalib::stringref name, vespalib::stringref md5, + vespalib::stringref id, vespalib::stringref hash) + : defName(name), + defMd5(md5), + configId(id), + configXxhash64(hash), + changed(0), + generation(0) + {} +}; + struct RPCFixture { std::vector<FRT_RPCRequest *> requests; @@ -87,20 +125,23 @@ namespace { struct ConnectionMock : public Connection { int errorCode; duration timeout; - FRT_RPCRequest * ans; + std::unique_ptr<Response> ans; fnet::frt::StandaloneFRT server; FRT_Supervisor & supervisor; FNET_Scheduler scheduler; vespalib::string address; - ConnectionMock(FRT_RPCRequest * answer = nullptr); + ConnectionMock() : ConnectionMock(std::unique_ptr<Response>()) { } + ConnectionMock(std::unique_ptr<Response> answer); ~ConnectionMock(); FRT_RPCRequest * allocRPCRequest() override { return supervisor.AllocRPCRequest(); } void setError(int ec) override { errorCode = ec; } void invoke(FRT_RPCRequest * req, duration t, FRT_IRequestWait * waiter) override { timeout = t; - if (ans != nullptr) - waiter->RequestDone(ans); + if (ans != nullptr) { + ans->encodeResponse(req); + waiter->RequestDone(req); + } else waiter->RequestDone(req); } @@ -108,10 +149,10 @@ namespace { void setTransientDelay(duration delay) override { (void) delay; } }; - ConnectionMock::ConnectionMock(FRT_RPCRequest * answer) + ConnectionMock::ConnectionMock(std::unique_ptr<Response> answer) : errorCode(0), timeout(0ms), - ans(answer), + ans(std::move(answer)), server(), supervisor(server.supervisor()), address() @@ -129,7 +170,6 @@ namespace { void syncTransport() override { } }; - struct AgentResultFixture { bool notified; @@ -175,7 +215,7 @@ namespace { ConfigKey key; SourceFixture() : rpc(), - conn(rpc.createOKResponse("foo", "baz", "4", "boo")), + conn(std::make_unique<Response>("foo", "baz", "4", "boo")), key("foo", "bar", "4", "boo") { } |