milvus/core/unittest/server/test_cache.cpp

279 lines
8.4 KiB
C++
Raw Normal View History

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include <gtest/gtest.h>
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
#include <fiu-control.h>
#include <fiu-local.h>
#include "utils/Error.h"
#include "wrapper/VecIndex.h"
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
#include "cache/CpuCacheMgr.h"
#include "cache/GpuCacheMgr.h"
namespace {
class InvalidCacheMgr : public milvus::cache::CacheMgr<milvus::cache::DataObjPtr> {
public:
InvalidCacheMgr() {
}
};
class LessItemCacheMgr : public milvus::cache::CacheMgr<milvus::cache::DataObjPtr> {
public:
LessItemCacheMgr() {
cache_ = std::make_shared<milvus::cache::Cache<milvus::cache::DataObjPtr>>(1UL << 12, 10);
}
};
class MockVecIndex : public milvus::engine::VecIndex {
public:
2019-11-05 05:35:24 +00:00
MockVecIndex(int64_t dim, int64_t total) : dimension_(dim), ntotal_(total) {
}
2019-11-05 05:35:24 +00:00
virtual milvus::Status
BuildAll(const int64_t& nb, const float* xb, const int64_t* ids, const milvus::engine::Config& cfg,
const int64_t& nt = 0, const float* xt = nullptr) {
return milvus::Status();
}
// milvus::engine::VecIndexPtr
// Clone() override {
// return milvus::engine::VecIndexPtr();
// }
2019-11-05 05:35:24 +00:00
int64_t
GetDeviceId() override {
return 0;
}
2019-11-05 05:35:24 +00:00
milvus::engine::IndexType
Tanimoto distance (#1016) * Add log to debug #678 * Rename nsg_mix to RNSG in C++ sdk #735 * [skip ci] change __function__ * clang-format * #766 If partition tag is similar, wrong partition is searched * #766 If partition tag is similar, wrong partition is searched * reorder changelog id * typo * define interface * Define interface (#832) * If partition tag is similar, wrong partition is searched (#825) * #766 If partition tag is similar, wrong partition is searched * #766 If partition tag is similar, wrong partition is searched * reorder changelog id * typo * define interface Attach files by dragging & dropping, selecting or pasting them. Co-authored-by: groot <yihua.mo@zilliz.com> * faiss & knowhere * faiss & knowhere (#842) * Add log to debug #678 * Rename nsg_mix to RNSG in C++ sdk #735 * [skip ci] change __function__ * clang-format * If partition tag is similar, wrong partition is searched (#825) * #766 If partition tag is similar, wrong partition is searched * #766 If partition tag is similar, wrong partition is searched * reorder changelog id * typo * faiss & knowhere Co-authored-by: groot <yihua.mo@zilliz.com> * support binary input * code lint * add wrapper interface * add knowhere unittest * sdk support binary * support using metric tanimoto and hamming * sdk binary insert/query example * fix bug * fix bug * update wrapper * format * Improve unittest and fix bugs * delete printresult * fix bug * #823 Support binary vector tanimoto metric * fix typo * dimension limit to 32768 * fix * dimension limit to 32768 * fix describe index bug * fix #886 * fix #889 * add jaccard cases * hamming dev-test case * change test_connect * Add tanimoto cases * change the output type of hamming * add abs * merge master * rearrange changelog id * modify feature description Co-authored-by: Yukikaze-CZR <48198922+Yukikaze-CZR@users.noreply.github.com> Co-authored-by: Tinkerrr <linxiaojun.cn@outlook.com>
2020-01-14 11:22:27 +00:00
GetType() const override {
return milvus::engine::IndexType::INVALID;
}
2019-11-05 05:35:24 +00:00
virtual milvus::Status
Add(const int64_t& nb, const float* xb, const int64_t* ids,
const milvus::engine::Config& cfg = milvus::engine::Config()) {
return milvus::Status();
}
2019-11-05 05:35:24 +00:00
virtual milvus::Status
Search(const int64_t& nq, const float* xq, float* dist, int64_t* ids,
const milvus::engine::Config& cfg = milvus::engine::Config()) {
return milvus::Status();
}
2019-11-05 05:35:24 +00:00
milvus::engine::VecIndexPtr
CopyToGpu(const int64_t& device_id, const milvus::engine::Config& cfg) override {
return nullptr;
}
2019-11-05 05:35:24 +00:00
milvus::engine::VecIndexPtr
CopyToCpu(const milvus::engine::Config& cfg) override {
return nullptr;
}
2019-11-05 05:35:24 +00:00
virtual int64_t
Dimension() {
return dimension_;
}
2019-11-05 05:35:24 +00:00
virtual int64_t
Count() {
return ntotal_;
}
2019-11-05 05:35:24 +00:00
virtual knowhere::BinarySet
Serialize() {
knowhere::BinarySet binset;
return binset;
}
2019-11-05 05:35:24 +00:00
virtual milvus::Status
Load(const knowhere::BinarySet& index_binary) {
return milvus::Status();
}
public:
int64_t dimension_ = 256;
int64_t ntotal_ = 0;
};
2019-11-05 05:35:24 +00:00
} // namespace
TEST(CacheTest, DUMMY_TEST) {
milvus::engine::Config cfg;
MockVecIndex mock_index(256, 1000);
mock_index.Dimension();
mock_index.Count();
mock_index.Add(1, nullptr, nullptr);
mock_index.BuildAll(1, nullptr, nullptr, cfg);
mock_index.Search(1, nullptr, nullptr, nullptr, cfg);
// mock_index.Clone();
mock_index.CopyToCpu(cfg);
mock_index.CopyToGpu(1, cfg);
mock_index.GetDeviceId();
mock_index.GetType();
knowhere::BinarySet index_binary;
mock_index.Load(index_binary);
mock_index.Serialize();
}
TEST(CacheTest, CPU_CACHE_TEST) {
auto cpu_mgr = milvus::cache::CpuCacheMgr::GetInstance();
const int64_t gbyte = 1024 * 1024 * 1024;
int64_t g_num = 16;
int64_t cap = g_num * gbyte;
cpu_mgr->SetCapacity(cap);
ASSERT_EQ(cpu_mgr->CacheCapacity(), cap);
uint64_t item_count = 20;
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
for (uint64_t i = 0; i < item_count + 1; i++) {
2019-11-05 05:35:24 +00:00
// each vector is 1k byte, total size less than 1G
milvus::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 1000000);
milvus::cache::DataObjPtr data_obj = std::static_pointer_cast<milvus::cache::DataObj>(mock_index);
cpu_mgr->InsertItem("index_" + std::to_string(i), data_obj);
}
ASSERT_LT(cpu_mgr->ItemCount(), g_num);
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
//insert null data
std::shared_ptr<milvus::cache::DataObj> null_data_obj = nullptr;
cpu_mgr->InsertItem("index_null", null_data_obj);
auto obj = cpu_mgr->GetIndex("index_0");
ASSERT_TRUE(obj == nullptr);
obj = cpu_mgr->GetIndex("index_" + std::to_string(item_count - 1));
ASSERT_TRUE(obj != nullptr);
{
std::string item = "index_15";
ASSERT_TRUE(cpu_mgr->ItemExists(item));
cpu_mgr->EraseItem(item);
ASSERT_FALSE(cpu_mgr->ItemExists(item));
}
{
g_num = 5;
cpu_mgr->SetCapacity(g_num * gbyte);
2019-11-05 05:35:24 +00:00
// each vector is 1k byte, total size less than 6G
milvus::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 6000000);
milvus::cache::DataObjPtr data_obj = std::static_pointer_cast<milvus::cache::DataObj>(mock_index);
cpu_mgr->InsertItem("index_6g", data_obj);
ASSERT_TRUE(cpu_mgr->ItemExists("index_6g"));
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
//insert aleady existed key
cpu_mgr->InsertItem("index_6g", data_obj);
}
cpu_mgr->PrintInfo();
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
cpu_mgr->ClearCache();
ASSERT_EQ(cpu_mgr->ItemCount(), 0);
// fiu_enable("CpuCacheMgr_CpuCacheMgr_ZeroCpucacheThreshold", 1, nullptr, 0);
// auto* cpu_cache_mgr = new milvus::cache::CpuCacheMgr();
// fiu_disable("CpuCacheMgr_CpuCacheMgr_ZeroCpucacheThreshold");
// delete cpu_cache_mgr;
}
2019-11-23 03:34:45 +00:00
#ifdef MILVUS_GPU_VERSION
TEST(CacheTest, GPU_CACHE_TEST) {
auto gpu_mgr = milvus::cache::GpuCacheMgr::GetInstance(0);
for (int i = 0; i < 20; i++) {
2019-11-05 05:35:24 +00:00
// each vector is 1k byte
milvus::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 1000);
milvus::cache::DataObjPtr data_obj = std::static_pointer_cast<milvus::cache::DataObj>(mock_index);
gpu_mgr->InsertItem("index_" + std::to_string(i), data_obj);
}
auto obj = gpu_mgr->GetItem("index_0");
gpu_mgr->ClearCache();
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
for (auto i = 0; i < 3; i++) {
// TODO(myh): use gpu index to mock
2019-11-05 05:35:24 +00:00
// each vector is 1k byte, total size less than 2G
milvus::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 2000000);
milvus::cache::DataObjPtr data_obj = std::static_pointer_cast<milvus::cache::DataObj>(mock_index);
std::cout << data_obj->Size() << std::endl;
gpu_mgr->InsertItem("index_" + std::to_string(i), data_obj);
}
gpu_mgr->ClearCache();
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
// fiu_enable("GpuCacheMgr_GpuCacheMgr_ZeroGpucacheThreshold", 1, nullptr, 0);
// auto* gpu_cache_mgr = new milvus::cache::GpuCacheMgr();
// fiu_disable("GpuCacheMgr_GpuCacheMgr_ZeroGpucacheThreshold");
// delete gpu_cache_mgr;
}
2019-11-23 03:34:45 +00:00
#endif
TEST(CacheTest, INVALID_TEST) {
{
InvalidCacheMgr mgr;
ASSERT_EQ(mgr.ItemCount(), 0);
ASSERT_FALSE(mgr.ItemExists("test"));
ASSERT_EQ(mgr.GetItem("test"), nullptr);
mgr.InsertItem("test", milvus::cache::DataObjPtr());
mgr.InsertItem("test", nullptr);
mgr.EraseItem("test");
mgr.PrintInfo();
mgr.ClearCache();
mgr.SetCapacity(100);
ASSERT_EQ(mgr.CacheCapacity(), 0);
ASSERT_EQ(mgr.CacheUsage(), 0);
}
{
LessItemCacheMgr mgr;
for (int i = 0; i < 20; i++) {
2019-11-05 05:35:24 +00:00
// each vector is 1k byte
milvus::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 2);
milvus::cache::DataObjPtr data_obj = std::static_pointer_cast<milvus::cache::DataObj>(mock_index);
mgr.InsertItem("index_" + std::to_string(i), data_obj);
}
ASSERT_EQ(mgr.GetItem("index_0"), nullptr);
}
}
Improve codecov (#1095) * Optimize config test. Dir src/config 99% lines covered * add unittest coverage * optimize cache&config unittest * code format * format * format code * fix merge conflict * cover src/utils unittest * '#831 fix exe_path judge error' * #831 fix exe_path judge error * add some unittest coverage * add some unittest coverage * improve coverage of src/wrapper * improve src/wrapper coverage * *test optimize db/meta unittest * fix bug * *test optimize mysqlMetaImpl unittest * *style: format code * import server& scheduler unittest coverage * handover next work * *test: add some test_meta test case * *format code * *fix: fix typo * feat(codecov): improve code coverage for src/db(#872) * feat(codecov): improve code coverage for src/db/engine(#872) * feat(codecov): improve code coverage(#872) * fix config unittest bug * feat(codecov): improve code coverage core/db/engine(#872) * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage core/knowhere * feat(codecov): improve code coverage * feat(codecov): fix cpu test some error * feat(codecov): improve code coverage * feat(codecov): rename some fiu * fix(db/meta): fix switch/case default action * feat(codecov): improve code coverage(#872) * fix error caused by merge code * format code * feat(codecov): improve code coverage & format code(#872) * feat(codecov): fix test error(#872) * feat(codecov): fix unittest test_mem(#872) * feat(codecov): fix unittest(#872) * feat(codecov): fix unittest for resource manager(#872) * feat(codecov): code format (#872) * feat(codecov): trigger ci(#872) * fix(RequestScheduler): remove a wrong sleep statement * test(test_rpc): fix rpc test * Fix format issue * Remove unused comments * Fix unit test error Co-authored-by: ABNER-1 <ABNER-1@users.noreply.github.com> Co-authored-by: Jin Hai <hai.jin@zilliz.com>
2020-02-11 15:03:29 +00:00
TEST(CacheTest, PARTIAL_LRU_TEST) {
constexpr int MAX_SIZE = 5;
milvus::cache::LRU<int, int> lru(MAX_SIZE);
lru.put(0, 2);
lru.put(0, 3);
ASSERT_EQ(lru.size(), 1);
for (int i = 1; i < MAX_SIZE; ++i) {
lru.put(i, 0);
}
ASSERT_EQ(lru.size(), MAX_SIZE);
lru.put(99, 0);
ASSERT_EQ(lru.size(), MAX_SIZE);
ASSERT_TRUE(lru.exists(99));
ASSERT_ANY_THROW(lru.get(-1));
}