adding test for reload on restart

This commit is contained in:
krunal 2023-07-19 20:43:38 +05:30
parent d2e8b437b6
commit 97c7400689
2 changed files with 63 additions and 5 deletions

View File

@ -4,13 +4,11 @@
#include <collection_manager.h>
#include <core_api.h>
#include "core_api_utils.h"
#include "stopwords_manager.h"
class CoreAPIUtilsTest : public ::testing::Test {
protected:
Store *store;
CollectionManager & collectionManager = CollectionManager::get_instance();
StopwordsManager& stopwordsManager = StopwordsManager::get_instance();
std::atomic<bool> quit = false;
std::vector<std::string> query_fields;
@ -24,8 +22,6 @@ protected:
store = new Store(state_dir_path);
collectionManager.init(store, 1.0, "auth_key", quit);
collectionManager.load(8, 1000);
stopwordsManager.init(store);
}
virtual void SetUp() {

View File

@ -379,4 +379,66 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) {
ASSERT_STREQ("{\"message\": \"Parameter `stopwords` is required as string array value\"}", res->body.c_str());
collectionManager.drop_collection("coll1");
}
}
TEST_F(StopwordsManagerTest, ReloadStopwordsOnRestart) {
nlohmann::json schema = R"({
"name": "coll1",
"fields": [
{"name": "title", "type": "string" },
{"name": "points", "type": "int32" }
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection *coll1 = op.get();
auto stopword_value = R"(
{"stopwords": ["Pop", "Indie", "Rock", "Metal", "Folk"], "locale": "en"}
)"_json;
std::shared_ptr<http_req> req = std::make_shared<http_req>();
std::shared_ptr<http_res> res = std::make_shared<http_res>(nullptr);
req->params["collection"] = "coll1";
req->params["name"] = "genre";
req->body = stopword_value.dump();
auto result = put_upsert_stopword(req, res);
if(!result) {
LOG(ERROR) << res->body;
FAIL();
}
auto stopword_config = stopwordsManager.get_stopwords();
ASSERT_TRUE(stopword_config.find("genre") != stopword_config.end());
ASSERT_EQ(5, stopword_config["genre"].size());
ASSERT_TRUE(stopword_config["genre"].find("pop") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("indie") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("rock") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("metal") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("folk") != stopword_config["genre"].end());
//dispose collection manager and reload all stopwords
collectionManager.dispose();
delete store;
stopword_config.clear();
std::string state_dir_path = "/tmp/typesense_test/stopwords_manager";
system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());
store = new Store(state_dir_path);
collectionManager.init(store, 1.0, "auth_key", quit);
collectionManager.load(8, 1000);
stopword_config = stopwordsManager.get_stopwords();
ASSERT_TRUE(stopword_config.find("genre") != stopword_config.end());
ASSERT_EQ(5, stopword_config["genre"].size());
ASSERT_TRUE(stopword_config["genre"].find("pop") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("indie") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("rock") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("metal") != stopword_config["genre"].end());
ASSERT_TRUE(stopword_config["genre"].find("folk") != stopword_config["genre"].end());
}