diff options
author | Håvard Pettersen <havardpe@oath.com> | 2019-05-14 12:55:05 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2019-05-14 12:55:05 +0000 |
commit | 1503a9df2da8c06c8336e521811d2e589a1ce674 (patch) | |
tree | 3198e446513421954f3208b273c9e746b18f0591 /searchlib/src/tests/engine | |
parent | 3830d8e3ddfb430d09b2ee188a7325b57d11832a (diff) |
introduce online state in proto rpc adapter
this is to ensure we do not start server stuff until we are officially
online.
Diffstat (limited to 'searchlib/src/tests/engine')
-rw-r--r-- | searchlib/src/tests/engine/proto_rpc_adapter/proto_rpc_adapter_test.cpp | 84 |
1 files changed, 54 insertions, 30 deletions
diff --git a/searchlib/src/tests/engine/proto_rpc_adapter/proto_rpc_adapter_test.cpp b/searchlib/src/tests/engine/proto_rpc_adapter/proto_rpc_adapter_test.cpp index 6747e4e741e..89763f54f3d 100644 --- a/searchlib/src/tests/engine/proto_rpc_adapter/proto_rpc_adapter_test.cpp +++ b/searchlib/src/tests/engine/proto_rpc_adapter/proto_rpc_adapter_test.cpp @@ -92,46 +92,70 @@ TEST_F(ProtoRpcAdapterTest, require_that_plain_rpc_ping_works) { TEST_F(ProtoRpcAdapterTest, require_that_proto_rpc_search_works) { auto target = connect(); - auto *rpc = new FRT_RPCRequest(); - ProtoSearchRequest req; - req.set_offset(42); - ProtoRpcAdapter::encode_search_request(req, *rpc); - target->InvokeSync(rpc, 60.0); - ProtoSearchReply reply; - EXPECT_TRUE(ProtoRpcAdapter::decode_search_reply(*rpc, reply)); - EXPECT_EQ(reply.total_hit_count(), 42); - rpc->SubRef(); + for (bool online: {false, true, true}) { + auto *rpc = new FRT_RPCRequest(); + ProtoSearchRequest req; + req.set_offset(42); + ProtoRpcAdapter::encode_search_request(req, *rpc); + target->InvokeSync(rpc, 60.0); + if (online) { + ProtoSearchReply reply; + EXPECT_TRUE(ProtoRpcAdapter::decode_search_reply(*rpc, reply)); + EXPECT_EQ(reply.total_hit_count(), 42); + } else { + EXPECT_EQ(rpc->GetErrorCode(), FRTE_RPC_METHOD_FAILED); + EXPECT_EQ(std::string(rpc->GetErrorMessage()), std::string("Server not online")); + adapter.set_online(); + } + rpc->SubRef(); + } target->SubRef(); } TEST_F(ProtoRpcAdapterTest, require_that_proto_rpc_getDocsums_works) { auto target = connect(); - auto *rpc = new FRT_RPCRequest(); - ProtoDocsumRequest req; - req.set_rank_profile("mlr"); - ProtoRpcAdapter::encode_docsum_request(req, *rpc); - target->InvokeSync(rpc, 60.0); - ProtoDocsumReply reply; - EXPECT_TRUE(ProtoRpcAdapter::decode_docsum_reply(*rpc, reply)); - const auto &mem = reply.slime_summaries(); - Slime slime; - EXPECT_EQ(BinaryFormat::decode(Memory(mem.data(), mem.size()), slime), mem.size()); - EXPECT_EQ(slime.get()[0]["use_root_slime"].asBool(), true); - EXPECT_EQ(slime.get()[1]["ranking"].asString().make_string(), "mlr"); - rpc->SubRef(); + for (bool online: {false, true, true}) { + auto *rpc = new FRT_RPCRequest(); + ProtoDocsumRequest req; + req.set_rank_profile("mlr"); + ProtoRpcAdapter::encode_docsum_request(req, *rpc); + target->InvokeSync(rpc, 60.0); + if (online) { + ProtoDocsumReply reply; + EXPECT_TRUE(ProtoRpcAdapter::decode_docsum_reply(*rpc, reply)); + const auto &mem = reply.slime_summaries(); + Slime slime; + EXPECT_EQ(BinaryFormat::decode(Memory(mem.data(), mem.size()), slime), mem.size()); + EXPECT_EQ(slime.get()[0]["use_root_slime"].asBool(), true); + EXPECT_EQ(slime.get()[1]["ranking"].asString().make_string(), "mlr"); + } else { + EXPECT_EQ(rpc->GetErrorCode(), FRTE_RPC_METHOD_FAILED); + EXPECT_EQ(std::string(rpc->GetErrorMessage()), std::string("Server not online")); + adapter.set_online(); + } + rpc->SubRef(); + } target->SubRef(); } TEST_F(ProtoRpcAdapterTest, require_that_proto_rpc_ping_works) { auto target = connect(); - auto *rpc = new FRT_RPCRequest(); - ProtoMonitorRequest req; - ProtoRpcAdapter::encode_monitor_request(req, *rpc); - target->InvokeSync(rpc, 60.0); - ProtoMonitorReply reply; - EXPECT_TRUE(ProtoRpcAdapter::decode_monitor_reply(*rpc, reply)); - EXPECT_EQ(reply.active_docs(), 53); - rpc->SubRef(); + for (bool online: {false, true, true}) { + auto *rpc = new FRT_RPCRequest(); + ProtoMonitorRequest req; + ProtoRpcAdapter::encode_monitor_request(req, *rpc); + target->InvokeSync(rpc, 60.0); + if (online) { + ProtoMonitorReply reply; + EXPECT_TRUE(ProtoRpcAdapter::decode_monitor_reply(*rpc, reply)); + EXPECT_EQ(reply.active_docs(), 53); + } else { + EXPECT_EQ(rpc->GetErrorCode(), FRTE_RPC_METHOD_FAILED); + EXPECT_EQ(std::string(rpc->GetErrorMessage()), std::string("Server not online")); + adapter.set_online(); + } + rpc->SubRef(); + } target->SubRef(); } |