1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/searchlib/attribute/bitvector_search_cache.h>
#include <vespa/searchlib/common/bitvector.h>
using namespace search;
using namespace search::attribute;
using BitVectorSP = BitVectorSearchCache::BitVectorSP;
using Entry = BitVectorSearchCache::Entry;
using EntrySP = std::shared_ptr<Entry>;
EntrySP
makeEntry()
{
return std::make_shared<Entry>(IDocumentMetaStoreContext::IReadGuard::SP(), BitVector::create(5), 10);
}
struct Fixture {
BitVectorSearchCache cache;
EntrySP entry1;
EntrySP entry2;
Fixture()
: cache(),
entry1(makeEntry()),
entry2(makeEntry())
{}
};
TEST_F("require that bit vectors can be inserted and retrieved", Fixture)
{
EXPECT_EQUAL(0u, f.cache.size());
f.cache.insert("foo", f.entry1);
f.cache.insert("bar", f.entry2);
EXPECT_EQUAL(2u, f.cache.size());
EXPECT_EQUAL(f.entry1, f.cache.find("foo"));
EXPECT_EQUAL(f.entry2, f.cache.find("bar"));
EXPECT_TRUE(f.cache.find("baz").get() == nullptr);
}
TEST_F("require that insert() doesn't replace existing bit vector", Fixture)
{
f.cache.insert("foo", f.entry1);
f.cache.insert("foo", f.entry2);
EXPECT_EQUAL(1u, f.cache.size());
EXPECT_EQUAL(f.entry1, f.cache.find("foo"));
}
TEST_F("require that cache can be cleared", Fixture)
{
f.cache.insert("foo", f.entry1);
f.cache.insert("bar", f.entry2);
EXPECT_EQUAL(2u, f.cache.size());
f.cache.clear();
EXPECT_EQUAL(0u, f.cache.size());
EXPECT_TRUE(f.cache.find("foo").get() == nullptr);
EXPECT_TRUE(f.cache.find("bar").get() == nullptr);
}
TEST_MAIN() { TEST_RUN_ALL(); }
|