From 941c8a3f6ca2374965c2d3055ff7ab289a958607 Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Fri, 5 May 2017 11:54:54 +0000 Subject: Move chunk tests to separate test file. --- searchlib/src/tests/docstore/chunk/CMakeLists.txt | 8 +++ searchlib/src/tests/docstore/chunk/FILES | 1 + searchlib/src/tests/docstore/chunk/chunk_test.cpp | 71 ++++++++++++++++++++++ .../docstore/logdatastore/logdatastore_test.cpp | 51 ---------------- 4 files changed, 80 insertions(+), 51 deletions(-) create mode 100644 searchlib/src/tests/docstore/chunk/CMakeLists.txt create mode 100644 searchlib/src/tests/docstore/chunk/FILES create mode 100644 searchlib/src/tests/docstore/chunk/chunk_test.cpp (limited to 'searchlib/src/tests/docstore') diff --git a/searchlib/src/tests/docstore/chunk/CMakeLists.txt b/searchlib/src/tests/docstore/chunk/CMakeLists.txt new file mode 100644 index 00000000000..c5247f5467b --- /dev/null +++ b/searchlib/src/tests/docstore/chunk/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(searchlib_chunk_test_app TEST + SOURCES + chunk_test.cpp + DEPENDS + searchlib +) +vespa_add_test(NAME searchlib_chunk_test_app COMMAND searchlib_chunk_test_app) diff --git a/searchlib/src/tests/docstore/chunk/FILES b/searchlib/src/tests/docstore/chunk/FILES new file mode 100644 index 00000000000..8c4b64f0979 --- /dev/null +++ b/searchlib/src/tests/docstore/chunk/FILES @@ -0,0 +1 @@ +chunk_test.cpp diff --git a/searchlib/src/tests/docstore/chunk/chunk_test.cpp b/searchlib/src/tests/docstore/chunk/chunk_test.cpp new file mode 100644 index 00000000000..8b08fb278e3 --- /dev/null +++ b/searchlib/src/tests/docstore/chunk/chunk_test.cpp @@ -0,0 +1,71 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include + +#include +#include +#include +#include +#include +#include + +LOG_SETUP("chunk_test"); + +using namespace search; +using document::CompressionConfig; + +TEST("require that Chunk obey limits") +{ + Chunk c(0, Chunk::Config(256)); + EXPECT_TRUE(c.hasRoom(1000)); // At least 1 is allowed no matter what the size is. + c.append(1, "abc", 3); + EXPECT_TRUE(c.hasRoom(229)); + EXPECT_FALSE(c.hasRoom(230)); + c.append(2, "abc", 3); + EXPECT_TRUE(c.hasRoom(20)); +} + +TEST("require that Chunk can produce unique list") +{ + const char *d = "ABCDEF"; + Chunk c(0, Chunk::Config(100)); + c.append(1, d, 1); + c.append(2, d, 2); + c.append(3, d, 3); + c.append(2, d, 4); + c.append(1, d, 5); + EXPECT_EQUAL(5u, c.count()); + const Chunk::LidList & all = c.getLids(); + EXPECT_EQUAL(5u, all.size()); + Chunk::LidList unique = c.getUniqueLids(); + EXPECT_EQUAL(3u, unique.size()); + EXPECT_EQUAL(1u, unique[0].getLid()); + EXPECT_EQUAL(5u, unique[0].netSize()); + EXPECT_EQUAL(2u, unique[1].getLid()); + EXPECT_EQUAL(4u, unique[1].netSize()); + EXPECT_EQUAL(3u, unique[2].getLid()); + EXPECT_EQUAL(3u, unique[2].netSize()); +} + +void testChunkFormat(ChunkFormat &cf, size_t expectedLen, const vespalib::string &expectedContent) +{ + CompressionConfig cfg; + uint64_t MAGIC_CONTENT(0xabcdef9876543210); + cf.getBuffer() << MAGIC_CONTENT; + vespalib::DataBuffer buffer; + cf.pack(7, buffer, cfg); + EXPECT_EQUAL(expectedLen, buffer.getDataLen()); + std::ostringstream os; + os << vespalib::HexDump(buffer.getData(), buffer.getDataLen()); + EXPECT_EQUAL(expectedContent, os.str()); +} + +TEST("require that Chunk formats does not change between releases") +{ + ChunkFormatV1 v1(10); + testChunkFormat(v1, 26, "26 000000000010ABCDEF987654321000000000000000079CF5E79B"); + ChunkFormatV2 v2(10); + testChunkFormat(v2, 34, "34 015BA32DE7000000220000000010ABCDEF987654321000000000000000074D000694"); +} + +TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index c8fcdbc127b..f24b08ac247 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include using document::BucketId; @@ -690,56 +689,6 @@ TEST("requireThatFlushTimeIsAvailableAfterFlush") { EXPECT_GREATER_EQUAL(after.time(), store.getLastFlushTime().time()); } -TEST("requireThatChunksObeyLimits") { - Chunk c(0, Chunk::Config(256)); - EXPECT_TRUE(c.hasRoom(1000)); // At least 1 is allowed no matter what the size is. - c.append(1, "abc", 3); - EXPECT_TRUE(c.hasRoom(229)); - EXPECT_FALSE(c.hasRoom(230)); - c.append(2, "abc", 3); - EXPECT_TRUE(c.hasRoom(20)); -} - -TEST("requireThatChunkCanProduceUniqueList") { - const char *d = "ABCDEF"; - Chunk c(0, Chunk::Config(100)); - c.append(1, d, 1); - c.append(2, d, 2); - c.append(3, d, 3); - c.append(2, d, 4); - c.append(1, d, 5); - EXPECT_EQUAL(5u, c.count()); - const Chunk::LidList & all = c.getLids(); - EXPECT_EQUAL(5u, all.size()); - Chunk::LidList unique = c.getUniqueLids(); - EXPECT_EQUAL(3u, unique.size()); - EXPECT_EQUAL(1u, unique[0].getLid()); - EXPECT_EQUAL(5u, unique[0].netSize()); - EXPECT_EQUAL(2u, unique[1].getLid()); - EXPECT_EQUAL(4u, unique[1].netSize()); - EXPECT_EQUAL(3u, unique[2].getLid()); - EXPECT_EQUAL(3u, unique[2].netSize()); -} - -void testChunkFormat(ChunkFormat & cf, size_t expectedLen, const vespalib::string & expectedContent) -{ - CompressionConfig cfg; - uint64_t MAGIC_CONTENT(0xabcdef9876543210); - cf.getBuffer() << MAGIC_CONTENT; - vespalib::DataBuffer buffer; - cf.pack(7, buffer, cfg); - EXPECT_EQUAL(expectedLen, buffer.getDataLen()); - std::ostringstream os; - os << vespalib::HexDump(buffer.getData(), buffer.getDataLen()); - EXPECT_EQUAL(expectedContent, os.str()); -} - -TEST("requireThatChunkFormatsDoesNotChangeBetweenReleases") { - ChunkFormatV1 v1(10); - testChunkFormat(v1, 26, "26 000000000010ABCDEF987654321000000000000000079CF5E79B"); - ChunkFormatV2 v2(10); - testChunkFormat(v2, 34, "34 015BA32DE7000000220000000010ABCDEF987654321000000000000000074D000694"); -} class DummyBucketizer : public IBucketizer { -- cgit v1.2.3