aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahoo-inc.com>2017-05-05 12:21:36 +0000
committerGeir Storli <geirst@yahoo-inc.com>2017-05-05 12:31:11 +0000
commitf7dd5647cb1cb6c4e0c1d5bc955dd049b910ccfa (patch)
treec428864e73de1e1747ea963fb098e9301c1428be /searchlib
parent941c8a3f6ca2374965c2d3055ff7ab289a958607 (diff)
Move StoreByBucket tests to separate test file.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp62
-rw-r--r--searchlib/src/tests/docstore/store_by_bucket/CMakeLists.txt8
-rw-r--r--searchlib/src/tests/docstore/store_by_bucket/FILES1
-rw-r--r--searchlib/src/tests/docstore/store_by_bucket/store_by_bucket_test.cpp83
5 files changed, 93 insertions, 62 deletions
diff --git a/searchlib/CMakeLists.txt b/searchlib/CMakeLists.txt
index 6bd98573faa..58d32020fb5 100644
--- a/searchlib/CMakeLists.txt
+++ b/searchlib/CMakeLists.txt
@@ -119,6 +119,7 @@ vespa_define_module(
src/tests/docstore/document_store_visitor
src/tests/docstore/lid_info
src/tests/docstore/logdatastore
+ src/tests/docstore/store_by_bucket
src/tests/engine/docsumapi
src/tests/engine/monitorapi
src/tests/engine/searchapi
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
index f24b08ac247..aa7cf03be31 100644
--- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
+++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
@@ -729,68 +729,6 @@ TEST("testBucketDensityComputer") {
EXPECT_EQUAL(0u, nonRecording.getNumBuckets());
}
-vespalib::string
-createPayload(BucketId b) {
- constexpr const char * BUF = "Buffer for testing Bucket drain order.";
- vespalib::asciistream os;
- os << BUF << " " << b;
- return os.str();
-}
-uint32_t userId(size_t i) { return i%100; }
-
-void
-add(StoreByBucket & sbb, size_t i) {
- constexpr size_t USED_BITS=5;
- vespalib::asciistream os;
- os << "id:a:b:n=" << userId(i) << ":" << i;
- document::DocumentId docId(os.str());
- BucketId b = docId.getGlobalId().convertToBucketId();
- EXPECT_EQUAL(userId(i), docId.getGlobalId().getLocationSpecificBits());
- b.setUsedBits(USED_BITS);
- vespalib::string s = createPayload(b);
- sbb.add(b, i%10, i, s.c_str(), s.size());
-}
-
-class VerifyBucketOrder : public StoreByBucket::IWrite {
-public:
- VerifyBucketOrder() : _lastLid(0), _lastBucketId(0), _uniqueUser(), _uniqueBucket() { }
- void write(BucketId bucketId, uint32_t chunkId, uint32_t lid, const void *buffer, size_t sz) override {
- (void) chunkId;
- EXPECT_LESS_EQUAL(_lastBucketId.toKey(), bucketId.toKey());
- if (_lastBucketId != bucketId) {
- EXPECT_TRUE(_uniqueBucket.find(bucketId.getRawId()) == _uniqueBucket.end());
- _uniqueBucket.insert(bucketId.getRawId());
- }
- if (userId(_lastLid) != userId(lid)) {
- EXPECT_TRUE(_uniqueUser.find(userId(lid)) == _uniqueUser.end());
- _uniqueUser.insert(userId(lid));
- }
- _lastLid = lid;
- _lastBucketId = bucketId;
- EXPECT_EQUAL(0, memcmp(buffer, createPayload(bucketId).c_str(), sz));
- }
-private:
- uint32_t _lastLid;
- BucketId _lastBucketId;
- vespalib::hash_set<uint32_t> _uniqueUser;
- vespalib::hash_set<uint64_t> _uniqueBucket;
-};
-
-TEST("test that StoreByBucket gives bucket by bucket and ordered within") {
- vespalib::MemoryDataStore backing;
- vespalib::ThreadStackExecutor executor(8, 128*1024);
- StoreByBucket sbb(backing, executor, CompressionConfig::LZ4);
- for (size_t i(1); i <=500; i++) {
- add(sbb, i);
- }
- for (size_t i(1000); i > 500; i--) {
- add(sbb, i);
- }
- EXPECT_EQUAL(32u, sbb.getBucketCount());
- EXPECT_EQUAL(1000u, sbb.getLidCount());
- VerifyBucketOrder vbo;
- sbb.drain(vbo);
-}
TEST_MAIN() {
DummyFileHeaderContext::setCreator("logdatastore_test");
diff --git a/searchlib/src/tests/docstore/store_by_bucket/CMakeLists.txt b/searchlib/src/tests/docstore/store_by_bucket/CMakeLists.txt
new file mode 100644
index 00000000000..dc35e7bf892
--- /dev/null
+++ b/searchlib/src/tests/docstore/store_by_bucket/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_store_by_bucket_test_app TEST
+ SOURCES
+ store_by_bucket_test.cpp
+ DEPENDS
+ searchlib
+)
+vespa_add_test(NAME searchlib_store_by_bucket_test_app COMMAND searchlib_store_by_bucket_test_app)
diff --git a/searchlib/src/tests/docstore/store_by_bucket/FILES b/searchlib/src/tests/docstore/store_by_bucket/FILES
new file mode 100644
index 00000000000..5c2c341aa80
--- /dev/null
+++ b/searchlib/src/tests/docstore/store_by_bucket/FILES
@@ -0,0 +1 @@
+store_by_bucket_test.cpp
diff --git a/searchlib/src/tests/docstore/store_by_bucket/store_by_bucket_test.cpp b/searchlib/src/tests/docstore/store_by_bucket/store_by_bucket_test.cpp
new file mode 100644
index 00000000000..279ee389b18
--- /dev/null
+++ b/searchlib/src/tests/docstore/store_by_bucket/store_by_bucket_test.cpp
@@ -0,0 +1,83 @@
+// Copyright 2017 Yahoo Inc. 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/document/bucket/bucketid.h>
+#include <vespa/document/base/documentid.h>
+#include <vespa/log/log.h>
+#include <vespa/searchlib/docstore/storebybucket.h>
+#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/vespalib/stllike/hash_set.h>
+#include <vespa/vespalib/util/threadstackexecutor.h>
+
+LOG_SETUP("store_by_bucket_test");
+
+using namespace search::docstore;
+using document::BucketId;
+using document::CompressionConfig;
+
+vespalib::string
+createPayload(BucketId b) {
+ constexpr const char * BUF = "Buffer for testing Bucket drain order.";
+ vespalib::asciistream os;
+ os << BUF << " " << b;
+ return os.str();
+}
+uint32_t userId(size_t i) { return i%100; }
+
+void
+add(StoreByBucket & sbb, size_t i) {
+ constexpr size_t USED_BITS=5;
+ vespalib::asciistream os;
+ os << "id:a:b:n=" << userId(i) << ":" << i;
+ document::DocumentId docId(os.str());
+ BucketId b = docId.getGlobalId().convertToBucketId();
+ EXPECT_EQUAL(userId(i), docId.getGlobalId().getLocationSpecificBits());
+ b.setUsedBits(USED_BITS);
+ vespalib::string s = createPayload(b);
+ sbb.add(b, i%10, i, s.c_str(), s.size());
+}
+
+class VerifyBucketOrder : public StoreByBucket::IWrite {
+public:
+ VerifyBucketOrder() : _lastLid(0), _lastBucketId(0), _uniqueUser(), _uniqueBucket() { }
+ void write(BucketId bucketId, uint32_t chunkId, uint32_t lid, const void *buffer, size_t sz) override {
+ (void) chunkId;
+ EXPECT_LESS_EQUAL(_lastBucketId.toKey(), bucketId.toKey());
+ if (_lastBucketId != bucketId) {
+ EXPECT_TRUE(_uniqueBucket.find(bucketId.getRawId()) == _uniqueBucket.end());
+ _uniqueBucket.insert(bucketId.getRawId());
+ }
+ if (userId(_lastLid) != userId(lid)) {
+ EXPECT_TRUE(_uniqueUser.find(userId(lid)) == _uniqueUser.end());
+ _uniqueUser.insert(userId(lid));
+ }
+ _lastLid = lid;
+ _lastBucketId = bucketId;
+ EXPECT_EQUAL(0, memcmp(buffer, createPayload(bucketId).c_str(), sz));
+ }
+private:
+ uint32_t _lastLid;
+ BucketId _lastBucketId;
+ vespalib::hash_set<uint32_t> _uniqueUser;
+ vespalib::hash_set<uint64_t> _uniqueBucket;
+};
+
+TEST("require that StoreByBucket gives bucket by bucket and ordered within")
+{
+ vespalib::MemoryDataStore backing;
+ vespalib::ThreadStackExecutor executor(8, 128*1024);
+ StoreByBucket sbb(backing, executor, CompressionConfig::LZ4);
+ for (size_t i(1); i <=500; i++) {
+ add(sbb, i);
+ }
+ for (size_t i(1000); i > 500; i--) {
+ add(sbb, i);
+ }
+ EXPECT_EQUAL(32u, sbb.getBucketCount());
+ EXPECT_EQUAL(1000u, sbb.getLidCount());
+ VerifyBucketOrder vbo;
+ sbb.drain(vbo);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }