diff options
author | Arne H Juul <arnej@yahooinc.com> | 2021-10-25 07:17:01 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2021-10-25 12:03:14 +0000 |
commit | ec0e803145a6dd8d0dd1757324ad38d4c6a78678 (patch) | |
tree | 9be80e56fc0648db1e747f09fed90ab039a34d98 /searchcore/src/tests/proton/summaryengine/summaryengine.cpp | |
parent | 80c901e774e8f03fa9918877b30ba878d89d208e (diff) |
remove old docsum_by_slime RPC protocol
Diffstat (limited to 'searchcore/src/tests/proton/summaryengine/summaryengine.cpp')
-rw-r--r-- | searchcore/src/tests/proton/summaryengine/summaryengine.cpp | 205 |
1 files changed, 1 insertions, 204 deletions
diff --git a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp index d942abd28c2..f82b4c9243f 100644 --- a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp +++ b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/data/slime/slime.h> #include <vespa/searchcore/proton/summaryengine/summaryengine.h> -#include <vespa/searchcore/proton/summaryengine/docsum_by_slime.h> #include <vespa/searchlib/engine/searchreply.h> #include <vespa/searchlib/util/rawbuf.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> @@ -220,209 +220,6 @@ TEST("requireThatCorrectHandlerIsUsed") { EXPECT_LESS(0.0, static_cast<metrics::DoubleAverageMetric *>(engine.getMetrics().getMetric("latency"))->getAverage()); } -using vespalib::Slime; - -const char *GID1 = "abcdefghijkl"; -const char *GID2 = "bcdefghijklm"; - -void -verify(vespalib::stringref exp, const Slime &slime) { - Memory expMemory(exp); - vespalib::Slime expSlime; - size_t used = vespalib::slime::JsonFormat::decode(expMemory, expSlime); - EXPECT_TRUE(used > 0); - EXPECT_EQUAL(expSlime, slime); -} - -Slime -createSlimeRequestLarger(size_t num, - const vespalib::string & sessionId = vespalib::string(), - const vespalib::string & ranking = vespalib::string(), - const vespalib::string & docType = vespalib::string()) -{ - Slime r; - Cursor &root = r.setObject(); - root.setString("class", "your-summary"); - if ( ! sessionId.empty()) { - root.setData("sessionid", sessionId); - } - if (!ranking.empty()) { - root.setString("ranking", ranking); - } - if (!docType.empty()) { - root.setString("doctype", docType); - } - Cursor &array = root.setArray("gids"); - for (size_t i(0); i < num; i++) { - array.addData(Memory(GID1, 12)); - array.addData(Memory(GID2, 12)); - } - return r; -} - -Slime -createSlimeRequest(const vespalib::string & sessionId = vespalib::string(), - const vespalib::string & ranking = vespalib::string(), - const vespalib::string & docType = vespalib::string()) { - return createSlimeRequestLarger(1, sessionId, ranking, docType); -} - -TEST("requireThatSlimeRequestIsConvertedCorrectly") { - vespalib::Slime slimeRequest = createSlimeRequest(); - TEST_DO(verify("{" - " class: 'your-summary'," - " gids: [" - " x6162636465666768696A6B6C," - " x62636465666768696A6B6C6D" - " ]" - "}", slimeRequest)); - DocsumRequest::UP r = DocsumBySlime::slimeToRequest(slimeRequest.get()); - EXPECT_EQUAL("your-summary", r->resultClassName); - EXPECT_FALSE(r->propertiesMap.cacheProperties().lookup("query").found()); - EXPECT_TRUE(r->sessionId.empty()); - EXPECT_TRUE(r->ranking.empty()); - EXPECT_EQUAL(2u, r->hits.size()); - EXPECT_EQUAL(GlobalId(GID1), r->hits[0].gid); - EXPECT_EQUAL(GlobalId(GID2), r->hits[1].gid); -} - -TEST("require that presence of sessionid affect both request.sessionid and enables cache") { - vespalib::Slime slimeRequest = createSlimeRequest("1.some.key.7", "my-rank-profile"); - TEST_DO(verify("{" - " class: 'your-summary'," - " sessionid: x312E736F6D652E6B65792E37," - " ranking: 'my-rank-profile'," - " gids: [" - " x6162636465666768696A6B6C," - " x62636465666768696A6B6C6D" - " ]" - "}", slimeRequest)); - DocsumRequest::UP r = DocsumBySlime::slimeToRequest(slimeRequest.get()); - EXPECT_EQUAL("your-summary", r->resultClassName); - EXPECT_EQUAL("my-rank-profile", r->ranking); - - EXPECT_EQUAL(0, strncmp("1.some.key.7", &r->sessionId[0],r->sessionId.size())); - EXPECT_TRUE(r->propertiesMap.cacheProperties().lookup("query").found()); - EXPECT_EQUAL(2u, r->hits.size()); - EXPECT_EQUAL(GlobalId(GID1), r->hits[0].gid); - EXPECT_EQUAL(GlobalId(GID2), r->hits[1].gid); -} - -TEST("require that 'doctype' affects DocTypeName in a good way...") { - vespalib::Slime slimeRequest = createSlimeRequest("1.some.key.7", "my-rank-profile", "my-document-type"); - TEST_DO(verify("{" - " class: 'your-summary'," - " sessionid: x312E736F6D652E6B65792E37," - " ranking: 'my-rank-profile'," - " doctype: 'my-document-type'," - " gids: [" - " x6162636465666768696A6B6C," - " x62636465666768696A6B6C6D" - " ]" - "}", slimeRequest)); - DocsumRequest::UP r = DocsumBySlime::slimeToRequest(slimeRequest.get()); - EXPECT_EQUAL("your-summary", r->resultClassName); - EXPECT_EQUAL("my-rank-profile", r->ranking); - - EXPECT_EQUAL(0, strncmp("1.some.key.7", &r->sessionId[0],r->sessionId.size())); - EXPECT_TRUE(r->propertiesMap.cacheProperties().lookup("query").found()); - EXPECT_TRUE(r->propertiesMap.matchProperties().lookup("documentdb.searchdoctype").found()); - EXPECT_EQUAL(1u, r->propertiesMap.matchProperties().lookup("documentdb.searchdoctype").size()); - EXPECT_EQUAL("my-document-type", r->propertiesMap.matchProperties().lookup("documentdb.searchdoctype").get()); - EXPECT_EQUAL(DocTypeName("my-document-type").getName(), DocTypeName(*r).getName()); - EXPECT_EQUAL(2u, r->hits.size()); - EXPECT_EQUAL(GlobalId(GID1), r->hits[0].gid); - EXPECT_EQUAL(GlobalId(GID2), r->hits[1].gid); -} - -class Server { -public: - Server(); - ~Server(); - -private: - SummaryEngine engine; - ISearchHandler::SP handler; -public: - DocsumBySlime docsumBySlime; - DocsumByRPC docsumByRPC; -}; - -Server::Server() - : engine(2), - handler(std::make_shared<MySearchHandler>("slime", "some other value")), - docsumBySlime(engine), - docsumByRPC(docsumBySlime) -{ - DocTypeName dtnvfoo("foo"); - engine.putSearchHandler(dtnvfoo, handler); -} - -Server::~Server() = default; - -TEST("requireThatSlimeInterfaceWorksFine") { - Server server; - vespalib::Slime slimeRequest = createSlimeRequest(); - vespalib::Slime::UP response = server.docsumBySlime.getDocsums(slimeRequest.get()); - TEST_DO(verify(getAnswer(2, "some other value"), *response)); -} - -void -verifyReply(size_t count, CompressionConfig::Type encoding, size_t orgSize, size_t compressedSize, - FRT_RPCRequest *request) { - FRT_Values &ret = *request->GetReturn(); - EXPECT_EQUAL(encoding, ret[0]._intval8); - EXPECT_EQUAL(orgSize, ret[1]._intval32); - EXPECT_EQUAL(compressedSize, ret[2]._data._len); - - DataBuffer uncompressed; - ConstBufferRef blob(ret[2]._data._buf, ret[2]._data._len); - vespalib::compression::decompress(CompressionConfig::toType(ret[0]._intval8), ret[1]._intval32, - blob, uncompressed, false); - EXPECT_EQUAL(orgSize, uncompressed.getDataLen()); - - vespalib::Slime summaries; - BinaryFormat::decode(Memory(uncompressed.getData(), uncompressed.getDataLen()), summaries); - TEST_DO(verify(getAnswer(count, "some other value"), summaries)); -} - -void -verifyRPC(size_t count, - CompressionConfig::Type requestCompression, size_t requestSize, size_t requestBlobSize, - CompressionConfig::Type replyCompression, size_t replySize, size_t replyBlobSize) { - Server server; - vespalib::Slime slimeRequest = createSlimeRequestLarger(count); - vespalib::SimpleBuffer buf; - BinaryFormat::encode(slimeRequest, buf); - EXPECT_EQUAL(requestSize, buf.get().size); - - CompressionConfig config(requestCompression, 9, 100); - DataBuffer compressed(const_cast<char *>(buf.get().data), buf.get().size); - CompressionConfig::Type type = vespalib::compression::compress(config, - ConstBufferRef(buf.get().data, buf.get().size), - compressed, true); - EXPECT_EQUAL(type, requestCompression); - - FRT_RPCRequest *request = new FRT_RPCRequest(); - FRT_Values &arg = *request->GetParams(); - arg.AddInt8(type); - arg.AddInt32(buf.get().size); - arg.AddData(compressed.getData(), compressed.getDataLen()); - EXPECT_EQUAL(requestBlobSize, compressed.getDataLen()); - - server.docsumByRPC.getDocsums(*request); - // note: createSlimeRequestLarger() inserts count * 2 gids - verifyReply(count*2, replyCompression, replySize, replyBlobSize, request); - - request->SubRef(); -} - -TEST("requireThatRPCInterfaceWorks") { - verifyRPC(1, CompressionConfig::NONE, 55, 55, CompressionConfig::NONE, 78, 78); - verifyRPC(100, CompressionConfig::NONE, 2631, 2631, CompressionConfig::LZ4, 5030, 1057); - verifyRPC(100, CompressionConfig::LZ4, 2631, 69, CompressionConfig::LZ4, 5030, 1057); -} - } TEST_MAIN() { TEST_RUN_ALL(); } |