diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 15:17:18 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 15:17:18 +0000 |
commit | 1b144ad08f66639425c2d689f92fa8426eb4968b (patch) | |
tree | 8b73f36c188af862ae7e793d1f551c00b19f7b64 | |
parent | f2242995a019ec23640e98976ff7a3937913e403 (diff) |
Reduce code duplication and improve comments.
-rw-r--r-- | config/src/tests/frt/frt.cpp | 37 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtsource.cpp | 5 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtsource.h | 2 |
3 files changed, 11 insertions, 33 deletions
diff --git a/config/src/tests/frt/frt.cpp b/config/src/tests/frt/frt.cpp index fd02b388f0b..5cfa125051a 100644 --- a/config/src/tests/frt/frt.cpp +++ b/config/src/tests/frt/frt.cpp @@ -41,7 +41,7 @@ struct Response { long generation; StringVector payload; vespalib::string ns; - void encodeResponse(FRT_RPCRequest * req) { + void encodeResponse(FRT_RPCRequest * req) const { FRT_Values & ret = *req->GetReturn(); ret.AddString(defName.c_str()); @@ -60,13 +60,14 @@ struct Response { req->SetError(FRTE_NO_ERROR); } Response(vespalib::stringref name, vespalib::stringref md5, - vespalib::stringref id, vespalib::stringref hash) + vespalib::stringref id, vespalib::stringref hash, + int changed_in=0, long generation_in=0) : defName(name), defMd5(md5), configId(id), configXxhash64(hash), - changed(0), - generation(0) + changed(changed_in), + generation(generation_in) {} }; @@ -85,32 +86,10 @@ struct Response { requests.push_back(req); return req; } - 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 * createOKRequest(const Response & response) { FRT_RPCRequest * req = new FRT_RPCRequest(); - 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.encodeResponse(req); requests.push_back(req); return req; } @@ -255,7 +234,7 @@ TEST_F("require that response containing errors does not validate", RPCFixture() } TEST_F("require that response contains all values", RPCFixture()) { - FRTConfigResponseV3 ok(f1.createOKResponse("foo", "baz", "bim", "boo", 12, 15)); + FRTConfigResponseV3 ok(f1.createOKRequest(Response("foo", "baz", "bim", "boo", 12, 15))); ASSERT_FALSE(ok.validateResponse()); ASSERT_FALSE(ok.hasValidResponse()); } diff --git a/config/src/vespa/config/frt/frtsource.cpp b/config/src/vespa/config/frt/frtsource.cpp index d58be3c2ae4..11839ac0b50 100644 --- a/config/src/vespa/config/frt/frtsource.cpp +++ b/config/src/vespa/config/frt/frtsource.cpp @@ -83,10 +83,9 @@ FRTSource::RequestDone(FRT_RPCRequest * request) } std::shared_ptr<FRTConfigRequest> configRequest; { + std::lock_guard guard(_lock); auto found = _inflight.find(request); - if (found == _inflight.end()) { - assert(false); - } + assert(found != _inflight.end()); configRequest = found->second; } // If this was error from FRT side and nothing to do with config, notify diff --git a/config/src/vespa/config/frt/frtsource.h b/config/src/vespa/config/frt/frtsource.h index 5c878730db2..104b7318d8d 100644 --- a/config/src/vespa/config/frt/frtsource.h +++ b/config/src/vespa/config/frt/frtsource.h @@ -34,7 +34,7 @@ private: const FRTConfigRequestFactory & _requestFactory; std::unique_ptr<ConfigAgent> _agent; const ConfigKey _key; - std::mutex _lock; // Protects _requests, _task and _closed + std::mutex _lock; // Protects _inflight, _task and _closed std::condition_variable _cond; RequestMap _inflight; std::unique_ptr<FNET_Task> _task; |