summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/documentdb/document_scan_iterator
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /searchcore/src/tests/proton/documentdb/document_scan_iterator
Publish
Diffstat (limited to 'searchcore/src/tests/proton/documentdb/document_scan_iterator')
-rw-r--r--searchcore/src/tests/proton/documentdb/document_scan_iterator/.gitignore1
-rw-r--r--searchcore/src/tests/proton/documentdb/document_scan_iterator/CMakeLists.txt12
-rw-r--r--searchcore/src/tests/proton/documentdb/document_scan_iterator/DESC2
-rw-r--r--searchcore/src/tests/proton/documentdb/document_scan_iterator/FILES1
-rw-r--r--searchcore/src/tests/proton/documentdb/document_scan_iterator/document_scan_iterator_test.cpp102
5 files changed, 118 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/documentdb/document_scan_iterator/.gitignore b/searchcore/src/tests/proton/documentdb/document_scan_iterator/.gitignore
new file mode 100644
index 00000000000..6c961d2f232
--- /dev/null
+++ b/searchcore/src/tests/proton/documentdb/document_scan_iterator/.gitignore
@@ -0,0 +1 @@
+searchcore_document_scan_iterator_test_app
diff --git a/searchcore/src/tests/proton/documentdb/document_scan_iterator/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/document_scan_iterator/CMakeLists.txt
new file mode 100644
index 00000000000..1a342660f7c
--- /dev/null
+++ b/searchcore/src/tests/proton/documentdb/document_scan_iterator/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchcore_document_scan_iterator_test_app
+ SOURCES
+ document_scan_iterator_test.cpp
+ DEPENDS
+ searchcore_server
+ searchcore_feedoperation
+ searchcore_documentmetastore
+ searchcore_bucketdb
+ searchcore_pcommon
+)
+vespa_add_test(NAME searchcore_document_scan_iterator_test_app COMMAND searchcore_document_scan_iterator_test_app)
diff --git a/searchcore/src/tests/proton/documentdb/document_scan_iterator/DESC b/searchcore/src/tests/proton/documentdb/document_scan_iterator/DESC
new file mode 100644
index 00000000000..b5965bc2f2d
--- /dev/null
+++ b/searchcore/src/tests/proton/documentdb/document_scan_iterator/DESC
@@ -0,0 +1,2 @@
+Test for document scan iterator. Take a look at document_scan_iterator_test.cpp for details.
+
diff --git a/searchcore/src/tests/proton/documentdb/document_scan_iterator/FILES b/searchcore/src/tests/proton/documentdb/document_scan_iterator/FILES
new file mode 100644
index 00000000000..f1b6d86a774
--- /dev/null
+++ b/searchcore/src/tests/proton/documentdb/document_scan_iterator/FILES
@@ -0,0 +1 @@
+document_scan_iterator_test.cpp
diff --git a/searchcore/src/tests/proton/documentdb/document_scan_iterator/document_scan_iterator_test.cpp b/searchcore/src/tests/proton/documentdb/document_scan_iterator/document_scan_iterator_test.cpp
new file mode 100644
index 00000000000..8a05d46d22f
--- /dev/null
+++ b/searchcore/src/tests/proton/documentdb/document_scan_iterator/document_scan_iterator_test.cpp
@@ -0,0 +1,102 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("document_scan_iterator_test");
+
+#include <vespa/searchcore/proton/documentmetastore/documentmetastore.h>
+#include <vespa/searchcore/proton/server/document_scan_iterator.h>
+#include <vespa/vespalib/test/insertion_operators.h>
+#include <vespa/vespalib/testkit/testapp.h>
+
+using namespace document;
+using namespace proton;
+using namespace search;
+
+using vespalib::make_string;
+
+typedef DocumentMetaStore::Result DMSResult;
+typedef DocumentMetaStore::Timestamp Timestamp;
+typedef std::set<uint32_t> LidSet;
+typedef std::vector<uint32_t> LidVector;
+
+struct Fixture
+{
+ DocumentMetaStore _metaStore;
+ DocumentScanIterator _itr;
+ Fixture()
+ : _metaStore(std::make_shared<BucketDBOwner>()),
+ _itr(_metaStore)
+ {
+ _metaStore.constructFreeList();
+ }
+ Fixture &add(const LidVector &lids) {
+ for (auto lid : lids) {
+ add(lid);
+ }
+ return *this;
+ }
+ Fixture &add(uint32_t lid) {
+ DocumentId docId(make_string("userdoc:test:%u:%u", 1, lid));
+ const GlobalId &gid = docId.getGlobalId();
+ DMSResult res = _metaStore.inspect(gid);
+ ASSERT_EQUAL(lid, res._lid);
+ _metaStore.put(gid, gid.convertToBucketId(), Timestamp(lid), lid);
+ return *this;
+ }
+ LidSet scan(uint32_t count, uint32_t compactLidLimit, uint32_t maxDocsToScan = 10) {
+ LidSet retval;
+ for (uint32_t i = 0; i < count; ++i) {
+ retval.insert(next(compactLidLimit, maxDocsToScan, false));
+ EXPECT_TRUE(_itr.valid());
+ }
+ EXPECT_EQUAL(0u, next(compactLidLimit, maxDocsToScan, false));
+ EXPECT_FALSE(_itr.valid());
+ return retval;
+ }
+ uint32_t next(uint32_t compactLidLimit, uint32_t maxDocsToScan = 10, bool retry = false) {
+ return _itr.next(compactLidLimit, maxDocsToScan, retry).lid;
+ }
+};
+
+void
+assertLidSet(const LidSet &exp, const LidSet &act)
+{
+ EXPECT_EQUAL(exp, act);
+}
+
+TEST_F("require that an empty document meta store don't return any thing", Fixture)
+{
+ assertLidSet({}, f.scan(0, 4));
+}
+
+TEST_F("require that only lids > lid limit are returned", Fixture)
+{
+ f.add({1,2,3,4,5,6,7,8});
+ assertLidSet({5,6,7,8}, f.scan(4, 4));
+}
+
+TEST_F("require that max docs to scan (1) are taken into consideration", Fixture)
+{
+ f.add({1,2,3,4,5,6,7,8});
+ assertLidSet({0,5,6,7,8}, f.scan(8, 4, 1));
+}
+
+TEST_F("require that max docs to scan (2) are taken into consideration", Fixture)
+{
+ f.add({1,2,3,4,5,6,7,8});
+ // scan order is: 8, {2,4}, 7, {5,3}, {1,6} (5 scans total)
+ assertLidSet({0,7,8}, f.scan(5, 6, 2));
+}
+
+TEST_F("require that we start scan at previous doc if retry is set", Fixture)
+{
+ f.add({1,2,3,4,5,6,7,8});
+ uint32_t lid1 = f.next(4, 10, false);
+ uint32_t lid2 = f.next(4, 10, true);
+ EXPECT_EQUAL(lid1, lid2);
+}
+
+TEST_MAIN()
+{
+ TEST_RUN_ALL();
+}