Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite searchlib FileChunk unit test to gtest. #32256

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions searchlib/src/tests/docstore/file_chunk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ vespa_add_executable(searchlib_file_chunk_test_app TEST
file_chunk_test.cpp
DEPENDS
vespa_searchlib
GTest::gtest
)
vespa_add_test(NAME searchlib_file_chunk_test_app COMMAND searchlib_file_chunk_test_app)
58 changes: 28 additions & 30 deletions searchlib/src/tests/docstore/file_chunk/file_chunk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#include <vespa/searchlib/docstore/filechunk.h>
#include <vespa/searchlib/docstore/writeablefilechunk.h>
#include <vespa/searchlib/test/directory_handler.h>
#include <vespa/vespalib/test/insertion_operators.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/testkit/test_path.h>
#include <vespa/vespalib/util/cpu_usage.h>
#include <vespa/vespalib/util/compressionconfig.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <iomanip>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/testkit/test_master.hpp>

#include <vespa/log/log.h>

Expand Down Expand Up @@ -86,10 +85,10 @@ struct FixtureBase {
}
~FixtureBase();
void assertLidMap(const std::vector<uint32_t> &expLids) const {
EXPECT_EQUAL(expLids, lidObserver.lids);
EXPECT_EQ(expLids, lidObserver.lids);
}
void assertBucketizer(const std::vector<uint32_t> &expLids) const {
EXPECT_EQUAL(expLids, bucketizer.lids);
EXPECT_EQ(expLids, bucketizer.lids);
}
};

Expand Down Expand Up @@ -140,56 +139,56 @@ struct WriteFixture : public FixtureBase {

};

TEST_F("require that idx file without docIdLimit in header can be read by FileChunk",
ReadFixture(TEST_PATH("without_doc_id_limit"), false))
TEST(FileChunkTest, require_that_idx_file_without_docIdLimit_in_header_can_be_read_by_FileChunk)
{
EXPECT_EQUAL(std::numeric_limits<uint32_t>::max(), f.chunk.getDocIdLimit());
ReadFixture f(TEST_PATH("without_doc_id_limit"), false);
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), f.chunk.getDocIdLimit());
}

TEST_F("require that idx file without docIdLimit in header can be read by WriteableFileChunk",
WriteFixture(TEST_PATH("without_doc_id_limit"), 1000, false))
TEST(FileChunkTest, require_that_idx_file_without_docIdLimit_in_header_can_be_read_by_WriteableFileChunk)
{
EXPECT_EQUAL(std::numeric_limits<uint32_t>::max(), f.chunk.getDocIdLimit());
WriteFixture f(TEST_PATH("without_doc_id_limit"), 1000, false);
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), f.chunk.getDocIdLimit());
}

TEST("require that docIdLimit is written to and read from idx file header")
TEST(FileChunkTest, require_that_docIdLimit_is_written_to_and_read_from_idx_file_header)
{
{
WriteFixture f("tmp", 1000, false);
EXPECT_EQUAL(1000u, f.chunk.getDocIdLimit());
EXPECT_EQ(1000u, f.chunk.getDocIdLimit());
}
{
ReadFixture f("tmp", false);
f.updateLidMap(std::numeric_limits<uint32_t>::max()); // trigger reading of idx file header
EXPECT_EQUAL(1000u, f.chunk.getDocIdLimit());
EXPECT_EQ(1000u, f.chunk.getDocIdLimit());
}
{
WriteFixture f("tmp", 0);
EXPECT_EQUAL(1000u, f.chunk.getDocIdLimit());
EXPECT_EQ(1000u, f.chunk.getDocIdLimit());
}
}

TEST("require that numlids are updated") {
TEST(FileChunkTest, require_that_numlids_are_updated) {
{
WriteFixture f("tmp", 1000, false);
f.updateLidMap(1000);
EXPECT_EQUAL(0u, f.chunk.getNumLids());
EXPECT_EQ(0u, f.chunk.getNumLids());
f.append(1);
EXPECT_EQUAL(1u, f.chunk.getNumLids());
EXPECT_EQ(1u, f.chunk.getNumLids());
f.append(2);
f.append(3);
EXPECT_EQUAL(3u, f.chunk.getNumLids());
EXPECT_EQ(3u, f.chunk.getNumLids());
f.append(3);
EXPECT_EQUAL(4u, f.chunk.getNumLids());
EXPECT_EQ(4u, f.chunk.getNumLids());
f.flush();
}
{
WriteFixture f("tmp", 1000, true);
EXPECT_EQUAL(0u, f.chunk.getNumLids());
EXPECT_EQ(0u, f.chunk.getNumLids());
f.updateLidMap(1000);
EXPECT_EQUAL(4u, f.chunk.getNumLids());
EXPECT_EQ(4u, f.chunk.getNumLids());
f.append(7);
EXPECT_EQUAL(5u, f.chunk.getNumLids());
EXPECT_EQ(5u, f.chunk.getNumLids());
}
}

Expand All @@ -201,12 +200,12 @@ assertUpdateLidMap(FixtureType &f)
f.assertLidMap(expLids);
f.assertBucketizer(expLids);
size_t entrySize = 10 + 8;
EXPECT_EQUAL(9 * entrySize, f.chunk.getAddedBytes());
EXPECT_EQUAL(3u, f.chunk.getErasedCount());
EXPECT_EQUAL(3 * entrySize, f.chunk.getErasedBytes());
EXPECT_EQ(9 * entrySize, f.chunk.getAddedBytes());
EXPECT_EQ(3u, f.chunk.getErasedCount());
EXPECT_EQ(3 * entrySize, f.chunk.getErasedBytes());
}

TEST("require that entries with lid >= docIdLimit are skipped in updateLidMap()")
TEST(FileChunkTest, require_that_entries_with_lid_ge__docIdLimit_are_skipped_in_updateLidMap)
{
{
WriteFixture f("tmp", 0, false);
Expand All @@ -227,7 +226,7 @@ TEST("require that entries with lid >= docIdLimit are skipped in updateLidMap()"

using vespalib::compression::CompressionConfig;

TEST("require that operator == detects inequality") {
TEST(FileChunkTest, require_that_operator_eq_detects_inequality) {
using C = WriteableFileChunk::Config;
EXPECT_TRUE(C() == C());
EXPECT_TRUE(C({}, 1) == C({}, 1));
Expand All @@ -236,5 +235,4 @@ TEST("require that operator == detects inequality") {
EXPECT_FALSE(C({CompressionConfig::LZ4, 9, 60}, 2) == C({}, 2));
}

TEST_MAIN() { TEST_RUN_ALL(); }

GTEST_MAIN_RUN_ALL_TESTS()