diff options
Diffstat (limited to 'config/src/tests/frt/frt.cpp')
-rw-r--r-- | config/src/tests/frt/frt.cpp | 85 |
1 files changed, 33 insertions, 52 deletions
diff --git a/config/src/tests/frt/frt.cpp b/config/src/tests/frt/frt.cpp index 5cfa125051a..3eda573cb27 100644 --- a/config/src/tests/frt/frt.cpp +++ b/config/src/tests/frt/frt.cpp @@ -32,45 +32,6 @@ 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) const { - 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, - int changed_in=0, long generation_in=0) - : defName(name), - defMd5(md5), - configId(id), - configXxhash64(hash), - changed(changed_in), - generation(generation_in) - {} -}; - struct RPCFixture { std::vector<FRT_RPCRequest *> requests; @@ -86,10 +47,32 @@ struct Response { requests.push_back(req); return req; } - FRT_RPCRequest * createOKRequest(const Response & response) + FRT_RPCRequest * createOKResponse(const vespalib::string & defName="", + const vespalib::string & defMd5="", + const vespalib::string & configId="", + const vespalib::string & configXxhash64="", + int changed=0, + long generation=0, + const StringVector & payload = StringVector(), + const vespalib::string & ns = "") { FRT_RPCRequest * req = new FRT_RPCRequest(); - response.encodeResponse(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); requests.push_back(req); return req; } @@ -104,23 +87,20 @@ struct Response { struct ConnectionMock : public Connection { int errorCode; duration timeout; - std::unique_ptr<Response> ans; + FRT_RPCRequest * ans; fnet::frt::StandaloneFRT server; FRT_Supervisor & supervisor; FNET_Scheduler scheduler; vespalib::string address; - ConnectionMock() : ConnectionMock(std::unique_ptr<Response>()) { } - ConnectionMock(std::unique_ptr<Response> answer); + ConnectionMock(FRT_RPCRequest * answer = nullptr); ~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) { - ans->encodeResponse(req); - waiter->RequestDone(req); - } + if (ans != nullptr) + waiter->RequestDone(ans); else waiter->RequestDone(req); } @@ -128,10 +108,10 @@ struct Response { void setTransientDelay(duration delay) override { (void) delay; } }; - ConnectionMock::ConnectionMock(std::unique_ptr<Response> answer) + ConnectionMock::ConnectionMock(FRT_RPCRequest * answer) : errorCode(0), timeout(0ms), - ans(std::move(answer)), + ans(answer), server(), supervisor(server.supervisor()), address() @@ -149,6 +129,7 @@ struct Response { void syncTransport() override { } }; + struct AgentResultFixture { bool notified; @@ -194,7 +175,7 @@ struct Response { ConfigKey key; SourceFixture() : rpc(), - conn(std::make_unique<Response>("foo", "baz", "4", "boo")), + conn(rpc.createOKResponse("foo", "baz", "4", "boo")), key("foo", "bar", "4", "boo") { } @@ -234,7 +215,7 @@ TEST_F("require that response containing errors does not validate", RPCFixture() } TEST_F("require that response contains all values", RPCFixture()) { - FRTConfigResponseV3 ok(f1.createOKRequest(Response("foo", "baz", "bim", "boo", 12, 15))); + FRTConfigResponseV3 ok(f1.createOKResponse("foo", "baz", "bim", "boo", 12, 15)); ASSERT_FALSE(ok.validateResponse()); ASSERT_FALSE(ok.hasValidResponse()); } |