summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2021-11-03 22:00:25 +0100
committerTor Egge <Tor.Egge@online.no>2021-11-03 22:00:25 +0100
commit8e996033594317202d92c5f9bf6141570fe7f6f0 (patch)
treedaee37ed45ad8d2fdc348d0b1b3bddf5e380e01c /searchcore/src/tests/proton
parent9c3f28fbbdbf5b8be36f994b38f4980ebe7c3e8d (diff)
Add DocumentInverterCollection.
Diffstat (limited to 'searchcore/src/tests/proton')
-rw-r--r--searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp12
-rw-r--r--searchcore/src/tests/proton/index/fusionrunner_test.cpp7
-rw-r--r--searchcore/src/tests/proton/index/indexmanager_test.cpp26
3 files changed, 31 insertions, 14 deletions
diff --git a/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp b/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
index 85c91884294..8314fa6bfb8 100644
--- a/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
+++ b/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
@@ -20,6 +20,8 @@
#include <vespa/searchlib/queryeval/fake_requestcontext.h>
#include <vespa/searchlib/queryeval/searchiterator.h>
#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/gate.h>
+#include <vespa/vespalib/util/destructor_callbacks.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <sstream>
@@ -59,6 +61,13 @@ using vespalib::string;
namespace {
+void commit_memory_index_and_wait(MemoryIndex &memory_index)
+{
+ vespalib::Gate gate;
+ memory_index.commit(std::make_shared<vespalib::GateCallback>(gate));
+ gate.await();
+}
+
class Test : public vespalib::TestApp {
const char *current_state;
void DumpState(bool) {
@@ -163,8 +172,7 @@ void Test::requireThatMemoryIndexCanBeDumpedAndSearched() {
doc = buildDocument(doc_builder, doc_id2, word2);
memory_index.insertDocument(doc_id2, *doc.get());
- memory_index.commit(std::shared_ptr<vespalib::IDestructorCallback>());
- indexFieldWriter->sync_all();
+ commit_memory_index_and_wait(memory_index);
testSearch(memory_index, word1, doc_id1);
testSearch(memory_index, word2, doc_id2);
diff --git a/searchcore/src/tests/proton/index/fusionrunner_test.cpp b/searchcore/src/tests/proton/index/fusionrunner_test.cpp
index ca10ff01a69..736bc4bae96 100644
--- a/searchcore/src/tests/proton/index/fusionrunner_test.cpp
+++ b/searchcore/src/tests/proton/index/fusionrunner_test.cpp
@@ -14,6 +14,8 @@
#include <vespa/searchlib/memoryindex/memory_index.h>
#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/test/index/mock_field_length_inspector.h>
+#include <vespa/vespalib/util/gate.h>
+#include <vespa/vespalib/util/destructor_callbacks.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <set>
@@ -156,8 +158,10 @@ void addDocument(DocBuilder & doc_builder, MemoryIndex &index, ISourceSelector &
uint8_t index_id, uint32_t docid, const string &word) {
Document::UP doc = buildDocument(doc_builder, docid, word);
index.insertDocument(docid, *doc);
- index.commit(std::shared_ptr<vespalib::IDestructorCallback>());
+ vespalib::Gate gate;
+ index.commit(std::make_shared<vespalib::GateCallback>(gate));
selector.setSource(docid, index_id);
+ gate.await();
}
void Test::createIndex(const string &dir, uint32_t id, bool fusion) {
@@ -182,7 +186,6 @@ void Test::createIndex(const string &dir, uint32_t id, bool fusion) {
addDocument(doc_builder, memory_index, *_selector, id, id + 1, "bar");
addDocument(doc_builder, memory_index, *_selector, id, id + 2, "baz");
addDocument(doc_builder, memory_index, *_selector, id, id + 3, "qux");
- _threadingService.indexFieldWriter().sync_all();
const uint32_t docIdLimit =
std::min(memory_index.getDocIdLimit(), _selector->getDocIdLimit());
diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp
index 84cf0e3655f..8e41323e461 100644
--- a/searchcore/src/tests/proton/index/indexmanager_test.cpp
+++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp
@@ -21,6 +21,8 @@
#include <vespa/searchlib/test/index/mock_field_length_inspector.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/io/fileutil.h>
+#include <vespa/vespalib/util/destructor_callbacks.h>
+#include <vespa/vespalib/util/gate.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <vespa/vespalib/util/time.h>
@@ -96,6 +98,12 @@ Document::UP buildDocument(DocBuilder &doc_builder, int id,
return doc_builder.endDocument();
}
+void push_documents_and_wait(search::memoryindex::DocumentInverter &inverter) {
+ vespalib::Gate gate;
+ inverter.pushDocuments(std::make_shared<vespalib::GateCallback>(gate));
+ gate.await();
+}
+
std::shared_ptr<vespalib::IDestructorCallback> emptyDestructorCallback;
struct IndexManagerTest : public ::testing::Test {
@@ -142,10 +150,11 @@ struct IndexManagerTest : public ::testing::Test {
Document::UP addDocument(uint32_t docid);
void resetIndexManager();
void removeDocument(uint32_t docId, SerialNum serialNum) {
+ vespalib::Gate gate;
runAsIndex([&]() { _index_manager->removeDocument(docId, serialNum);
- _index_manager->commit(serialNum, emptyDestructorCallback);
+ _index_manager->commit(serialNum, std::make_shared<vespalib::GateCallback>(gate));
});
- _writeService.indexFieldWriter().sync_all();
+ gate.await();
}
void removeDocument(uint32_t docId) {
SerialNum serialNum = ++_serial_num;
@@ -182,10 +191,11 @@ IndexManagerTest::addDocument(uint32_t id)
{
Document::UP doc = buildDocument(_builder, id, "foo");
SerialNum serialNum = ++_serial_num;
+ vespalib::Gate gate;
runAsIndex([&]() { _index_manager->putDocument(id, *doc, serialNum);
_index_manager->commit(serialNum,
- emptyDestructorCallback); });
- _writeService.indexFieldWriter().sync_all();
+ std::make_shared<vespalib::GateCallback>(gate)); });
+ gate.await();
return doc;
}
@@ -407,9 +417,7 @@ TEST_F(IndexManagerTest, require_that_flush_stats_are_calculated)
Document::UP doc = addDocument(docid);
inverter.invertDocument(docid, *doc);
- invertThreads->sync_all();
- inverter.pushDocuments(std::shared_ptr<vespalib::IDestructorCallback>());
- pushThreads->sync_all();
+ push_documents_and_wait(inverter);
index_size = fic.getMemoryUsage().allocatedBytes() - fixed_index_size;
/// Must account for both docid 0 being reserved and the extra after.
@@ -426,9 +434,7 @@ TEST_F(IndexManagerTest, require_that_flush_stats_are_calculated)
inverter.invertDocument(docid + 10, *doc);
doc = addDocument(docid + 100);
inverter.invertDocument(docid + 100, *doc);
- invertThreads->sync_all();
- inverter.pushDocuments(std::shared_ptr<vespalib::IDestructorCallback>());
- pushThreads->sync_all();
+ push_documents_and_wait(inverter);
index_size = fic.getMemoryUsage().allocatedBytes() - fixed_index_size;
/// Must account for both docid 0 being reserved and the extra after.
selector_size = (docid + 100 + 1) * sizeof(Source);