diff options
Diffstat (limited to 'searchcore/src/tests')
8 files changed, 214 insertions, 331 deletions
diff --git a/searchcore/src/tests/proton/attribute/CMakeLists.txt b/searchcore/src/tests/proton/attribute/CMakeLists.txt index 911268bd92a..88b30df608f 100644 --- a/searchcore/src/tests/proton/attribute/CMakeLists.txt +++ b/searchcore/src/tests/proton/attribute/CMakeLists.txt @@ -21,6 +21,7 @@ vespa_add_executable(searchcore_attributeflush_test_app TEST searchcore_attribute searchcore_flushengine searchcore_pcommon + GTest::gtest ) vespa_add_test(NAME searchcore_attributeflush_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/attributeflush_test.sh DEPENDS searchcore_attributeflush_test_app) diff --git a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp index a621451bf3b..6969032535c 100644 --- a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp +++ b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp @@ -14,7 +14,7 @@ #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/test/directory_handler.h> #include <vespa/searchcommon/attribute/config.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/foreground_thread_executor.h> #include <vespa/vespalib/util/foregroundtaskexecutor.h> #include <vespa/vespalib/util/idestructorcallback.h> @@ -209,46 +209,6 @@ AVConfig getInt32ArrayConfig() return AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY); } -class Test : public vespalib::TestApp -{ -private: - void - requireThatUpdaterAndFlusherCanRunConcurrently(); - - void - requireThatFlushableAttributeReportsMemoryUsage(); - - void - requireThatFlushableAttributeManagesSyncTokenInfo(); - - void - requireThatFlushTargetsCanBeRetrieved(); - - void - requireThatCleanUpIsPerformedAfterFlush(); - - void - requireThatFlushStatsAreUpdated(); - - void - requireThatOnlyOneFlusherCanRunAtTheSameTime(); - - void - requireThatLastFlushTimeIsReported(); - - void - requireThatShrinkWorks(); - - void requireThatFlushedAttributeCanBeLoaded(const HwInfo &hwInfo); - void requireThatFlushedAttributeCanBeLoaded(); - - void requireThatFlushFailurePreventsSyncTokenUpdate(); -public: - int - Main() override; -}; - - const string test_dir = "flush"; struct BaseFixture @@ -325,9 +285,7 @@ struct Fixture : public BaseFixture, public AttributeManagerFixture Fixture::~Fixture() = default; - -void -Test::requireThatUpdaterAndFlusherCanRunConcurrently() +TEST(AttributeFlushTest, require_that_updater_and_flusher_can_run_concurrently) { Fixture f; AttributeManager &am = f._m; @@ -352,14 +310,12 @@ Test::requireThatUpdaterAndFlusherCanRunConcurrently() AttributeFactory::createAttribute(baseFileName, getInt32Config()); EXPECT_TRUE(attr->load()); - EXPECT_EQUAL((uint32_t)snap.syncToken + 1, attr->getNumDocs()); + EXPECT_EQ((uint32_t)snap.syncToken + 1, attr->getNumDocs()); } } } - -void -Test::requireThatFlushableAttributeReportsMemoryUsage() +TEST(AttributeFlushTest, require_that_flushable_attribute_reports_memory_usage) { Fixture f; AttributeManager &am = f._m; @@ -368,16 +324,14 @@ Test::requireThatFlushableAttributeReportsMemoryUsage() av->commit(); IFlushTarget::SP fa = am.getFlushable("a2"); EXPECT_TRUE(av->getStatus().getAllocated() >= 100u * sizeof(int32_t)); - EXPECT_EQUAL(av->getStatus().getUsed(), - fa->getApproxMemoryGain().getBefore()+0lu); + EXPECT_EQ(av->getStatus().getUsed(), + fa->getApproxMemoryGain().getBefore()+0lu); // attributes stay in memory - EXPECT_EQUAL(fa->getApproxMemoryGain().getBefore(), - fa->getApproxMemoryGain().getAfter()); + EXPECT_EQ(fa->getApproxMemoryGain().getBefore(), + fa->getApproxMemoryGain().getAfter()); } - -void -Test::requireThatFlushableAttributeManagesSyncTokenInfo() +TEST(AttributeFlushTest, require_that_flushable_attribute_manages_sync_token_info) { Fixture f; AttributeManager &am = f._m; @@ -386,49 +340,45 @@ Test::requireThatFlushableAttributeManagesSyncTokenInfo() IFlushTarget::SP fa = am.getFlushable("a3"); IndexMetaInfo info("flush/a3"); - EXPECT_EQUAL(0u, fa->getFlushedSerialNum()); + EXPECT_EQ(0u, fa->getFlushedSerialNum()); EXPECT_TRUE(fa->initFlush(0, std::make_shared<search::FlushToken>()).get() == NULL); EXPECT_TRUE(!info.load()); av->commit(CommitParam(10)); // last sync token = 10 - EXPECT_EQUAL(0u, fa->getFlushedSerialNum()); + EXPECT_EQ(0u, fa->getFlushedSerialNum()); EXPECT_TRUE(fa->initFlush(10, std::make_shared<search::FlushToken>()).get() != NULL); fa->initFlush(10, std::make_shared<search::FlushToken>())->run(); - EXPECT_EQUAL(10u, fa->getFlushedSerialNum()); + EXPECT_EQ(10u, fa->getFlushedSerialNum()); EXPECT_TRUE(info.load()); - EXPECT_EQUAL(1u, info.snapshots().size()); + EXPECT_EQ(1u, info.snapshots().size()); EXPECT_TRUE(info.snapshots()[0].valid); - EXPECT_EQUAL(10u, info.snapshots()[0].syncToken); + EXPECT_EQ(10u, info.snapshots()[0].syncToken); av->commit(CommitParam(20)); // last sync token = 20 - EXPECT_EQUAL(10u, fa->getFlushedSerialNum()); + EXPECT_EQ(10u, fa->getFlushedSerialNum()); fa->initFlush(20, std::make_shared<search::FlushToken>())->run(); - EXPECT_EQUAL(20u, fa->getFlushedSerialNum()); + EXPECT_EQ(20u, fa->getFlushedSerialNum()); EXPECT_TRUE(info.load()); - EXPECT_EQUAL(1u, info.snapshots().size()); // snapshot 10 removed + EXPECT_EQ(1u, info.snapshots().size()); // snapshot 10 removed EXPECT_TRUE(info.snapshots()[0].valid); - EXPECT_EQUAL(20u, info.snapshots()[0].syncToken); + EXPECT_EQ(20u, info.snapshots()[0].syncToken); } - -void -Test::requireThatFlushTargetsCanBeRetrieved() +TEST(AttributeFlushTest, require_that_flush_targets_can_be_retrieved) { Fixture f; AttributeManager &am = f._m; f.addAttribute("a4"); f.addAttribute("a5"); std::vector<IFlushTarget::SP> ftl = am.getFlushTargets(); - EXPECT_EQUAL(4u, ftl.size()); - EXPECT_EQUAL(am.getFlushable("a4").get(), ftl[0].get()); - EXPECT_EQUAL(am.getShrinker("a4").get(), ftl[1].get()); - EXPECT_EQUAL(am.getFlushable("a5").get(), ftl[2].get()); - EXPECT_EQUAL(am.getShrinker("a5").get(), ftl[3].get()); + EXPECT_EQ(4u, ftl.size()); + EXPECT_EQ(am.getFlushable("a4").get(), ftl[0].get()); + EXPECT_EQ(am.getShrinker("a4").get(), ftl[1].get()); + EXPECT_EQ(am.getFlushable("a5").get(), ftl[2].get()); + EXPECT_EQ(am.getShrinker("a5").get(), ftl[3].get()); } - -void -Test::requireThatCleanUpIsPerformedAfterFlush() +TEST(AttributeFlushTest, require_that_cleanup_is_performed_after_flush) { Fixture f; AttributeVector::SP av = f.addAttribute("a6"); @@ -454,16 +404,14 @@ Test::requireThatCleanUpIsPerformedAfterFlush() fa.initFlush(30, std::make_shared<search::FlushToken>())->run(); EXPECT_TRUE(info.load()); - EXPECT_EQUAL(1u, info.snapshots().size()); // snapshots 10 & 20 removed + EXPECT_EQ(1u, info.snapshots().size()); // snapshots 10 & 20 removed EXPECT_TRUE(info.snapshots()[0].valid); - EXPECT_EQUAL(30u, info.snapshots()[0].syncToken); + EXPECT_EQ(30u, info.snapshots()[0].syncToken); EXPECT_FALSE(fs::exists(fs::path(snap10))); EXPECT_FALSE(fs::exists(fs::path(snap20))); } - -void -Test::requireThatFlushStatsAreUpdated() +TEST(AttributeFlushTest, require_that_flush_stats_are_updated) { Fixture f; AttributeManager &am = f._m; @@ -473,13 +421,11 @@ Test::requireThatFlushStatsAreUpdated() IFlushTarget::SP ft = am.getFlushable("a7"); ft->initFlush(101, std::make_shared<search::FlushToken>())->run(); FlushStats stats = ft->getLastFlushStats(); - EXPECT_EQUAL("flush/a7/snapshot-101", stats.getPath()); - EXPECT_EQUAL(8u, stats.getPathElementsToLog()); + EXPECT_EQ("flush/a7/snapshot-101", stats.getPath()); + EXPECT_EQ(8u, stats.getPathElementsToLog()); } - -void -Test::requireThatOnlyOneFlusherCanRunAtTheSameTime() +TEST(AttributeFlushTest, require_that_only_one_flusher_can_run_at_the_same_time) { Fixture f; AttributeManager &am = f._m; @@ -504,15 +450,13 @@ Test::requireThatOnlyOneFlusherCanRunAtTheSameTime() ASSERT_TRUE(info.load()); LOG(info, "Found %zu snapshots", info.snapshots().size()); for (size_t i = 0; i < info.snapshots().size(); ++i) { - EXPECT_EQUAL(true, info.snapshots()[i].valid); + EXPECT_EQ(true, info.snapshots()[i].valid); } IndexMetaInfo::Snapshot best = info.getBestSnapshot(); - EXPECT_EQUAL(true, best.valid); + EXPECT_EQ(true, best.valid); } - -void -Test::requireThatLastFlushTimeIsReported() +TEST(AttributeFlushTest, require_that_last_flush_time_is_reported) { using seconds = std::chrono::seconds; BaseFixture f; @@ -521,38 +465,36 @@ Test::requireThatLastFlushTimeIsReported() AttributeManagerFixture amf(f); AttributeManager &am = amf._m; AttributeVector::SP av = amf.addAttribute("a9"); - EXPECT_EQUAL(vespalib::system_time(), am.getFlushable("a9")->getLastFlushTime()); + EXPECT_EQ(vespalib::system_time(), am.getFlushable("a9")->getLastFlushTime()); } { // no snapshot flushed yet AttributeManagerFixture amf(f); AttributeManager &am = amf._m; AttributeVector::SP av = amf.addAttribute("a9"); IFlushTarget::SP ft = am.getFlushable("a9"); - EXPECT_EQUAL(vespalib::system_time(), ft->getLastFlushTime()); + EXPECT_EQ(vespalib::system_time(), ft->getLastFlushTime()); ft->initFlush(200, std::make_shared<search::FlushToken>())->run(); EXPECT_TRUE(FastOS_File::Stat("flush/a9/snapshot-200", &stat)); - EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime()); + EXPECT_EQ(stat._modifiedTime, ft->getLastFlushTime()); } { // snapshot flushed AttributeManagerFixture amf(f); AttributeManager &am = amf._m; amf.addAttribute("a9"); IFlushTarget::SP ft = am.getFlushable("a9"); - EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime()); + EXPECT_EQ(stat._modifiedTime, ft->getLastFlushTime()); { // updated flush time after nothing to flush std::this_thread::sleep_for(1100ms); std::chrono::seconds now = duration_cast<seconds>(vespalib::system_clock::now().time_since_epoch()); Executor::Task::UP task = ft->initFlush(200, std::make_shared<search::FlushToken>()); EXPECT_FALSE(task); - EXPECT_LESS(stat._modifiedTime, ft->getLastFlushTime()); - EXPECT_APPROX(now.count(), duration_cast<seconds>(ft->getLastFlushTime().time_since_epoch()).count(), 3); + EXPECT_LT(stat._modifiedTime, ft->getLastFlushTime()); + EXPECT_NEAR(now.count(), duration_cast<seconds>(ft->getLastFlushTime().time_since_epoch()).count(), 3); } } } - -void -Test::requireThatShrinkWorks() +TEST(AttributeFlushTest, require_that_shrink_works) { Fixture f; AttributeManager &am = f._m; @@ -562,32 +504,32 @@ Test::requireThatShrinkWorks() av->addDocs(1000 - av->getNumDocs()); av->commit(CommitParam(50)); IFlushTarget::SP ft = am.getShrinker("a10"); - EXPECT_EQUAL(ft->getApproxMemoryGain().getBefore(), - ft->getApproxMemoryGain().getAfter()); + EXPECT_EQ(ft->getApproxMemoryGain().getBefore(), + ft->getApproxMemoryGain().getAfter()); AttributeGuard::UP g = am.getAttribute("a10"); EXPECT_FALSE(av->wantShrinkLidSpace()); EXPECT_FALSE(av->canShrinkLidSpace()); - EXPECT_EQUAL(1000u, av->getNumDocs()); - EXPECT_EQUAL(1000u, av->getCommittedDocIdLimit()); + EXPECT_EQ(1000u, av->getNumDocs()); + EXPECT_EQ(1000u, av->getCommittedDocIdLimit()); av->compactLidSpace(100); EXPECT_TRUE(av->wantShrinkLidSpace()); EXPECT_FALSE(av->canShrinkLidSpace()); - EXPECT_EQUAL(1000u, av->getNumDocs()); - EXPECT_EQUAL(100u, av->getCommittedDocIdLimit()); + EXPECT_EQ(1000u, av->getNumDocs()); + EXPECT_EQ(100u, av->getCommittedDocIdLimit()); aw.heartBeat(51, IDestructorCallback::SP()); EXPECT_TRUE(av->wantShrinkLidSpace()); EXPECT_FALSE(av->canShrinkLidSpace()); - EXPECT_EQUAL(ft->getApproxMemoryGain().getBefore(), - ft->getApproxMemoryGain().getAfter()); + EXPECT_EQ(ft->getApproxMemoryGain().getBefore(), + ft->getApproxMemoryGain().getAfter()); g.reset(); aw.heartBeat(52, IDestructorCallback::SP()); EXPECT_TRUE(av->wantShrinkLidSpace()); EXPECT_TRUE(av->canShrinkLidSpace()); EXPECT_TRUE(ft->getApproxMemoryGain().getBefore() > ft->getApproxMemoryGain().getAfter()); - EXPECT_EQUAL(1000u, av->getNumDocs()); - EXPECT_EQUAL(100u, av->getCommittedDocIdLimit()); - EXPECT_EQUAL(createSerialNum - 1, ft->getFlushedSerialNum()); + EXPECT_EQ(1000u, av->getNumDocs()); + EXPECT_EQ(100u, av->getCommittedDocIdLimit()); + EXPECT_EQ(createSerialNum - 1, ft->getFlushedSerialNum()); vespalib::ThreadStackExecutor exec(1); vespalib::Executor::Task::UP task = ft->initFlush(53, std::make_shared<search::FlushToken>()); exec.execute(std::move(task)); @@ -595,15 +537,16 @@ Test::requireThatShrinkWorks() exec.shutdown(); EXPECT_FALSE(av->wantShrinkLidSpace()); EXPECT_FALSE(av->canShrinkLidSpace()); - EXPECT_EQUAL(ft->getApproxMemoryGain().getBefore(), - ft->getApproxMemoryGain().getAfter()); - EXPECT_EQUAL(100u, av->getNumDocs()); - EXPECT_EQUAL(100u, av->getCommittedDocIdLimit()); + EXPECT_EQ(ft->getApproxMemoryGain().getBefore(), + ft->getApproxMemoryGain().getAfter()); + EXPECT_EQ(100u, av->getNumDocs()); + EXPECT_EQ(100u, av->getCommittedDocIdLimit()); } void -Test::requireThatFlushedAttributeCanBeLoaded(const HwInfo &hwInfo) +require_that_flushed_attribute_can_be_loaded(const HwInfo &hwInfo, const vespalib::string& label) { + SCOPED_TRACE(label); constexpr uint32_t numDocs = 100; BaseFixture f(hwInfo); vespalib::string attrName(hwInfo.disk().slow() ? "a11slow" : "a11fast"); @@ -612,9 +555,9 @@ Test::requireThatFlushedAttributeCanBeLoaded(const HwInfo &hwInfo) AttributeManager &am = amf._m; AttributeVector::SP av = amf.addPostingAttribute(attrName); IntegerAttribute & ia = static_cast<IntegerAttribute &>(*av); - EXPECT_EQUAL(1u, av->getNumDocs()); + EXPECT_EQ(1u, av->getNumDocs()); av->addDocs(numDocs); - EXPECT_EQUAL(numDocs + 1, av->getNumDocs()); + EXPECT_EQ(numDocs + 1, av->getNumDocs()); for (uint32_t i = 0; i < numDocs; ++i) { ia.update(i + 1, i + 43); } @@ -625,61 +568,44 @@ Test::requireThatFlushedAttributeCanBeLoaded(const HwInfo &hwInfo) { AttributeManagerFixture amf(f); AttributeVector::SP av = amf.addPostingAttribute(attrName); - EXPECT_EQUAL(numDocs + 1, av->getNumDocs()); + EXPECT_EQ(numDocs + 1, av->getNumDocs()); for (uint32_t i = 0; i < numDocs; ++i) { - EXPECT_EQUAL(i + 43, av->getInt(i + 1)); + EXPECT_EQ(i + 43, av->getInt(i + 1)); } } } -void -Test::requireThatFlushedAttributeCanBeLoaded() +TEST(AttributeFlushTest, require_that_flushed_attribute_can_be_loaded) { - TEST_DO(requireThatFlushedAttributeCanBeLoaded(HwInfo(HwInfo::Disk(0, false, false), HwInfo::Memory(0), HwInfo::Cpu(0)))); - TEST_DO(requireThatFlushedAttributeCanBeLoaded(HwInfo(HwInfo::Disk(0, true, false), HwInfo::Memory(0), HwInfo::Cpu(0)))); + require_that_flushed_attribute_can_be_loaded(HwInfo(HwInfo::Disk(0, false, false), HwInfo::Memory(0), HwInfo::Cpu(0)), "fast-disk"); + require_that_flushed_attribute_can_be_loaded(HwInfo(HwInfo::Disk(0, true, false), HwInfo::Memory(0), HwInfo::Cpu(0)), "slow-disk"); } -void -Test::requireThatFlushFailurePreventsSyncTokenUpdate() +TEST(AttributeFlushTest, require_that_flush_failure_prevents_sync_token_update) { BaseFixture f; AttributeManagerFixture amf(f); auto &am = amf._m; auto av = amf.addIntArrayPostingAttribute("a12"); - EXPECT_EQUAL(1u, av->getNumDocs()); + EXPECT_EQ(1u, av->getNumDocs()); auto flush_target = am.getFlushable("a12"); - EXPECT_EQUAL(0u, flush_target->getFlushedSerialNum()); + EXPECT_EQ(0u, flush_target->getFlushedSerialNum()); auto flush_task = flush_target->initFlush(200, std::make_shared<search::FlushToken>()); // Trigger flush failure av->getEnumStoreBase()->inc_compaction_count(); flush_task->run(); - EXPECT_EQUAL(0u, flush_target->getFlushedSerialNum()); + EXPECT_EQ(0u, flush_target->getFlushedSerialNum()); +} + } int -Test::Main() +main(int argc, char* argv[]) { - TEST_INIT("attributeflush_test"); - - if (_argc > 0) { - DummyFileHeaderContext::setCreator(_argv[0]); + ::testing::InitGoogleTest(&argc, argv); + if (argc > 0) { + DummyFileHeaderContext::setCreator(argv[0]); } - fs::remove_all(fs::path(test_dir)); - TEST_DO(requireThatUpdaterAndFlusherCanRunConcurrently()); - TEST_DO(requireThatFlushableAttributeReportsMemoryUsage()); - TEST_DO(requireThatFlushableAttributeManagesSyncTokenInfo()); - TEST_DO(requireThatFlushTargetsCanBeRetrieved()); - TEST_DO(requireThatCleanUpIsPerformedAfterFlush()); - TEST_DO(requireThatFlushStatsAreUpdated()); - TEST_DO(requireThatOnlyOneFlusherCanRunAtTheSameTime()); - TEST_DO(requireThatLastFlushTimeIsReported()); - TEST_DO(requireThatShrinkWorks()); - TEST_DO(requireThatFlushedAttributeCanBeLoaded()); - TEST_DO(requireThatFlushFailurePreventsSyncTokenUpdate()); - - TEST_DONE(); + fs::remove_all(fs::path(proton::test_dir)); + return RUN_ALL_TESTS(); } - -} - -TEST_APPHOOK(proton::Test); diff --git a/searchcore/src/tests/proton/feed_and_search/feed_and_search_test.cpp b/searchcore/src/tests/proton/feed_and_search/feed_and_search_test.cpp index 0936f05b222..ff740dd8801 100644 --- a/searchcore/src/tests/proton/feed_and_search/feed_and_search_test.cpp +++ b/searchcore/src/tests/proton/feed_and_search/feed_and_search_test.cpp @@ -23,15 +23,12 @@ #include <vespa/searchlib/queryeval/blueprint.h> #include <vespa/searchlib/queryeval/fake_requestcontext.h> #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/gate.h> #include <vespa/vespalib/util/destructor_callbacks.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <sstream> -#include <vespa/log/log.h> -LOG_SETUP("feed_and_search_test"); - using document::DataType; using document::Document; using document::FieldValue; @@ -75,38 +72,6 @@ void commit_memory_index_and_wait(MemoryIndex &memory_index) gate.await(); } -class Test : public vespalib::TestApp { - const char *current_state; - void DumpState(bool) { - fprintf(stderr, "%s: ERROR: in %s\n", __FILE__, current_state); - } - - void requireThatMemoryIndexCanBeDumpedAndSearched(); - - void testSearch(Searchable &source, - const string &term, uint32_t doc_id); - -public: - int Main() override; -}; - -#define TEST_CALL(func) \ - current_state = #func; \ - func(); - -int -Test::Main() -{ - TEST_INIT("feed_and_search_test"); - - if (_argc > 0) { - DummyFileHeaderContext::setCreator(_argv[0]); - } - TEST_CALL(requireThatMemoryIndexCanBeDumpedAndSearched); - - TEST_DONE(); -} - const string field_name = "string_field"; const string noise = "noise"; const string word1 = "foo"; @@ -123,7 +88,8 @@ Document::UP buildDocument(DocBuilder & doc_builder, int id, const string &word) } // Performs a search using a Searchable. -void Test::testSearch(Searchable &source, const string &term, uint32_t doc_id) +void +testSearch(Searchable &source, const string &term, uint32_t doc_id) { FakeRequestContext requestContext; uint32_t fieldId = 0; @@ -139,12 +105,12 @@ void Test::testSearch(Searchable &source, const string &term, uint32_t doc_id) search_iterator->initFullRange(); ASSERT_TRUE(search_iterator.get()); ASSERT_TRUE(search_iterator->seek(doc_id)); - EXPECT_EQUAL(doc_id, search_iterator->getDocId()); + EXPECT_EQ(doc_id, search_iterator->getDocId()); search_iterator->unpack(doc_id); FieldPositionsIterator it = match_data->resolveTermField(handle)->getIterator(); ASSERT_TRUE(it.valid()); - EXPECT_EQUAL(1u, it.size()); - EXPECT_EQUAL(1u, it.getPosition()); // All hits are at pos 1 in this index + EXPECT_EQ(1u, it.size()); + EXPECT_EQ(1u, it.getPosition()); // All hits are at pos 1 in this index EXPECT_TRUE(!search_iterator->seek(doc_id + 1)); EXPECT_TRUE(search_iterator->isAtEnd()); @@ -155,7 +121,8 @@ VESPA_THREAD_STACK_TAG(write_executor) // Creates a memory index, inserts documents, performs a few // searches, dumps the index to disk, and performs the searches // again. -void Test::requireThatMemoryIndexCanBeDumpedAndSearched() { +TEST(FeedAndSearchTest, require_that_memory_index_can_be_dumped_and_searched) +{ vespalib::ThreadStackExecutor sharedExecutor(2); auto indexFieldInverter = vespalib::SequencedTaskExecutor::create(invert_executor, 2); auto indexFieldWriter = vespalib::SequencedTaskExecutor::create(write_executor, 2); @@ -239,4 +206,12 @@ void Test::requireThatMemoryIndexCanBeDumpedAndSearched() { } } // namespace -TEST_APPHOOK(Test); +int +main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + if (argc > 0) { + DummyFileHeaderContext::setCreator(argv[0]); + } + return RUN_ALL_TESTS(); +} diff --git a/searchcore/src/tests/proton/feedtoken/CMakeLists.txt b/searchcore/src/tests/proton/feedtoken/CMakeLists.txt index 1a13e46eb41..8ddb3831c97 100644 --- a/searchcore/src/tests/proton/feedtoken/CMakeLists.txt +++ b/searchcore/src/tests/proton/feedtoken/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(searchcore_feedtoken_test_app TEST DEPENDS searchcore_pcommon searchcore_proton_metrics + GTest::gtest ) vespa_add_test(NAME searchcore_feedtoken_test_app COMMAND searchcore_feedtoken_test_app) diff --git a/searchcore/src/tests/proton/feedtoken/feedtoken_test.cpp b/searchcore/src/tests/proton/feedtoken/feedtoken_test.cpp index c3c67e74c70..d3eb7d08821 100644 --- a/searchcore/src/tests/proton/feedtoken/feedtoken_test.cpp +++ b/searchcore/src/tests/proton/feedtoken/feedtoken_test.cpp @@ -1,6 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchcore/proton/common/feedtoken.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/util/exceptions.h> using namespace proton; @@ -21,47 +21,24 @@ public: size_t getReceivedCount() const { return _receivedCount; } }; -class Test : public vespalib::TestApp { -private: - void testAck(); - void testFail(); - void testHandover(); - -public: - int Main() override { - TEST_INIT("feedtoken_test"); - - testAck(); TEST_FLUSH(); - testFail(); TEST_FLUSH(); - testHandover(); TEST_FLUSH(); - - TEST_DONE(); - } -}; - -TEST_APPHOOK(Test); - -void -Test::testAck() +TEST(FeedTokenTest, test_ack) { LocalTransport transport; { FeedToken token = feedtoken::make(transport); } - EXPECT_EQUAL(1u, transport.getReceivedCount()); + EXPECT_EQ(1u, transport.getReceivedCount()); } -void -Test::testFail() +TEST(FeedTokenTest, test_fail) { LocalTransport transport; FeedToken token = feedtoken::make(transport); token->fail(); - EXPECT_EQUAL(1u, transport.getReceivedCount()); + EXPECT_EQ(1u, transport.getReceivedCount()); } -void -Test::testHandover() +TEST(FeedTokenTest, test_handover) { struct MyHandover { static FeedToken handover(FeedToken token) { @@ -75,7 +52,7 @@ Test::testHandover() FeedToken token = feedtoken::make(transport); token = MyHandover::handover(token); } - EXPECT_EQUAL(1u, transport.getReceivedCount()); + EXPECT_EQ(1u, transport.getReceivedCount()); } - +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchcore/src/tests/proton/index/CMakeLists.txt b/searchcore/src/tests/proton/index/CMakeLists.txt index 40e3d8e7b79..c1cc6155a52 100644 --- a/searchcore/src/tests/proton/index/CMakeLists.txt +++ b/searchcore/src/tests/proton/index/CMakeLists.txt @@ -22,6 +22,7 @@ vespa_add_executable(searchcore_fusionrunner_test_app TEST searchcore_server searchcore_index searchcore_pcommon + GTest::gtest ) vespa_add_test(NAME searchcore_fusionrunner_test_app @@ -32,6 +33,7 @@ vespa_add_executable(searchcore_diskindexcleaner_test_app TEST diskindexcleaner_test.cpp DEPENDS searchcore_index + GTest::gtest ) vespa_add_test(NAME searchcore_diskindexcleaner_test_app diff --git a/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp b/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp index 745d9c6a983..1aa79e11a57 100644 --- a/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp +++ b/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp @@ -3,53 +3,44 @@ #include <vespa/searchcorespi/index/disk_indexes.h> #include <vespa/searchcorespi/index/diskindexcleaner.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/fastos/file.h> #include <algorithm> #include <filesystem> -#include <vespa/log/log.h> -LOG_SETUP("diskindexcleaner_test"); - using std::string; using std::vector; using namespace searchcorespi::index; namespace { -class Test : public vespalib::TestApp { - void requireThatAllIndexesOlderThanLastFusionIsRemoved(); - void requireThatIndexesInUseAreNotRemoved(); - void requireThatInvalidFlushIndexesAreRemoved(); - void requireThatInvalidFusionIndexesAreRemoved(); - void requireThatRemoveDontTouchNewIndexes(); - -public: - int Main() override; -}; - const string index_dir = "diskindexcleaner_test_data"; void removeTestData() { std::filesystem::remove_all(std::filesystem::path(index_dir)); } -int -Test::Main() -{ - TEST_INIT("diskindexcleaner_test"); - - TEST_DO(removeTestData()); +class DiskIndexCleanerTest : public ::testing::Test { +protected: + DiskIndexCleanerTest(); + ~DiskIndexCleanerTest() override; + void SetUp() override; + void TearDown() override; +}; - TEST_DO(requireThatAllIndexesOlderThanLastFusionIsRemoved()); - TEST_DO(requireThatIndexesInUseAreNotRemoved()); - TEST_DO(requireThatInvalidFlushIndexesAreRemoved()); - TEST_DO(requireThatInvalidFusionIndexesAreRemoved()); - TEST_DO(requireThatRemoveDontTouchNewIndexes()); +DiskIndexCleanerTest::DiskIndexCleanerTest() = default; +DiskIndexCleanerTest::~DiskIndexCleanerTest() = default; - TEST_DO(removeTestData()); +void +DiskIndexCleanerTest::SetUp() +{ + removeTestData(); +} - TEST_DONE(); +void +DiskIndexCleanerTest::TearDown() +{ + removeTestData(); } void createIndex(const string &name) { @@ -87,18 +78,20 @@ void createIndexes() { createIndex("index.flush.4"); } -void Test::requireThatAllIndexesOlderThanLastFusionIsRemoved() { +TEST_F(DiskIndexCleanerTest, require_that_all_indexes_older_than_last_fusion_is_removed) +{ createIndexes(); DiskIndexes disk_indexes; DiskIndexCleaner::clean(index_dir, disk_indexes); vector<string> indexes = readIndexes(); - EXPECT_EQUAL(3u, indexes.size()); + EXPECT_EQ(3u, indexes.size()); EXPECT_TRUE(contains(indexes, "index.fusion.2")); EXPECT_TRUE(contains(indexes, "index.flush.3")); EXPECT_TRUE(contains(indexes, "index.flush.4")); } -void Test::requireThatIndexesInUseAreNotRemoved() { +TEST_F(DiskIndexCleanerTest, require_that_indexes_in_use_are_not_removed) +{ createIndexes(); DiskIndexes disk_indexes; disk_indexes.setActive(index_dir + "/index.fusion.1", 0); @@ -116,37 +109,40 @@ void Test::requireThatIndexesInUseAreNotRemoved() { EXPECT_TRUE(!contains(indexes, "index.flush.2")); } -void Test::requireThatInvalidFlushIndexesAreRemoved() { +TEST_F(DiskIndexCleanerTest, require_that_invalid_flush_indexes_are_removed) +{ createIndexes(); std::filesystem::remove(std::filesystem::path(index_dir + "/index.flush.4/serial.dat")); DiskIndexes disk_indexes; DiskIndexCleaner::clean(index_dir, disk_indexes); vector<string> indexes = readIndexes(); - EXPECT_EQUAL(2u, indexes.size()); + EXPECT_EQ(2u, indexes.size()); EXPECT_TRUE(contains(indexes, "index.fusion.2")); EXPECT_TRUE(contains(indexes, "index.flush.3")); } -void Test::requireThatInvalidFusionIndexesAreRemoved() { +TEST_F(DiskIndexCleanerTest, require_that_invalid_fusion_indexes_are_removed) +{ createIndexes(); std::filesystem::remove(std::filesystem::path(index_dir + "/index.fusion.2/serial.dat")); DiskIndexes disk_indexes; DiskIndexCleaner::clean(index_dir, disk_indexes); vector<string> indexes = readIndexes(); - EXPECT_EQUAL(4u, indexes.size()); + EXPECT_EQ(4u, indexes.size()); EXPECT_TRUE(contains(indexes, "index.fusion.1")); EXPECT_TRUE(contains(indexes, "index.flush.2")); EXPECT_TRUE(contains(indexes, "index.flush.3")); EXPECT_TRUE(contains(indexes, "index.flush.4")); } -void Test::requireThatRemoveDontTouchNewIndexes() { +TEST_F(DiskIndexCleanerTest, require_that_remove_doesnt_touch_new_indexes) +{ createIndexes(); std::filesystem::remove(std::filesystem::path(index_dir + "/index.flush.4/serial.dat")); DiskIndexes disk_indexes; DiskIndexCleaner::removeOldIndexes(index_dir, disk_indexes); vector<string> indexes = readIndexes(); - EXPECT_EQUAL(3u, indexes.size()); + EXPECT_EQ(3u, indexes.size()); EXPECT_TRUE(contains(indexes, "index.fusion.2")); EXPECT_TRUE(contains(indexes, "index.flush.3")); EXPECT_TRUE(contains(indexes, "index.flush.4")); @@ -154,4 +150,4 @@ void Test::requireThatRemoveDontTouchNewIndexes() { } // namespace -TEST_APPHOOK(Test); +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchcore/src/tests/proton/index/fusionrunner_test.cpp b/searchcore/src/tests/proton/index/fusionrunner_test.cpp index a58d7540d7c..dd6e8fa1c4c 100644 --- a/searchcore/src/tests/proton/index/fusionrunner_test.cpp +++ b/searchcore/src/tests/proton/index/fusionrunner_test.cpp @@ -22,7 +22,7 @@ #include <vespa/searchlib/queryeval/blueprint.h> #include <vespa/vespalib/util/gate.h> #include <vespa/vespalib/util/destructor_callbacks.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/stllike/asciistream.h> #include <filesystem> #include <set> @@ -66,12 +66,8 @@ using namespace proton; namespace { -#define TEST_CALL(func) \ - setUp(); \ - func; \ - tearDown() - -class Test : public vespalib::TestApp { +class FusionRunnerTest : public ::testing::Test { +protected: std::unique_ptr<FusionRunner> _fusion_runner; FixedSourceSelector::UP _selector; FusionSpec _fusion_spec; @@ -79,8 +75,10 @@ class Test : public vespalib::TestApp { TransportAndExecutorService _service; IndexManager::MaintainerOperations _ops; - void setUp(); - void tearDown(); + FusionRunnerTest(); + ~FusionRunnerTest() override; + void SetUp() override; + void TearDown() override; void createIndex(const string &dir, uint32_t id, bool fusion = false); void checkResults(uint32_t fusion_id, const uint32_t *ids, size_t size); @@ -92,41 +90,19 @@ class Test : public vespalib::TestApp { void requireThatOldFusionIndexCanBePartOfNewFusion(); void requireThatSelectorsCanBeRebased(); void requireThatFusionCanBeStopped(); - -public: - Test(); - ~Test() override; - int Main() override; }; -Test::Test() - : _fusion_runner(), +FusionRunnerTest::FusionRunnerTest() + : ::testing::Test(), + _fusion_runner(), _selector(), _fusion_spec(), _fileHeaderContext(), _service(1), _ops(_fileHeaderContext,TuneFileIndexManager(), 0, _service.write()) { } -Test::~Test() = default; - -int -Test::Main() -{ - TEST_INIT("fusionrunner_test"); - if (_argc > 0) { - DummyFileHeaderContext::setCreator(_argv[0]); - } - TEST_CALL(requireThatNoDiskIndexesGiveId0()); - TEST_CALL(requireThatOneDiskIndexCausesCopy()); - TEST_CALL(requireThatTwoDiskIndexesCauseFusion()); - TEST_CALL(requireThatFusionCanRunOnMultipleDiskIndexes()); - TEST_CALL(requireThatOldFusionIndexCanBePartOfNewFusion()); - TEST_CALL(requireThatSelectorsCanBeRebased()); - TEST_CALL(requireThatFusionCanBeStopped()); - - TEST_DONE(); -} +FusionRunnerTest::~FusionRunnerTest() = default; const string base_dir = "fusion_test_data"; const string field_name = "field_name"; @@ -142,7 +118,9 @@ getSchema() return SchemaBuilder(db).add_all_indexes().build(); } -void Test::setUp() { +void +FusionRunnerTest::SetUp() +{ std::filesystem::remove_all(std::filesystem::path(base_dir)); _fusion_runner = std::make_unique<FusionRunner>(base_dir, getSchema(), TuneFileAttributes(), _fileHeaderContext); const string selector_base = base_dir + "/index.flush.0/selector"; @@ -150,12 +128,16 @@ void Test::setUp() { _fusion_spec = FusionSpec(); } -void Test::tearDown() { +void +FusionRunnerTest::TearDown() +{ std::filesystem::remove_all(std::filesystem::path(base_dir)); - _selector.reset(nullptr); + _selector.reset(); } -Document::UP buildDocument(DocBuilder & doc_builder, int id, const string &word) { +Document::UP +buildDocument(DocBuilder & doc_builder, int id, const string &word) +{ vespalib::asciistream ost; ost << "id:ns:searchdocument::" << id; auto doc = doc_builder.make_document(ost.str()); @@ -163,8 +145,10 @@ Document::UP buildDocument(DocBuilder & doc_builder, int id, const string &word) return doc; } -void addDocument(DocBuilder & doc_builder, MemoryIndex &index, ISourceSelector &selector, - uint8_t index_id, uint32_t docid, const string &word) { +void +addDocument(DocBuilder & doc_builder, MemoryIndex &index, ISourceSelector &selector, + uint8_t index_id, uint32_t docid, const string &word) +{ Document::UP doc = buildDocument(doc_builder, docid, word); index.insertDocument(docid, *doc, {}); vespalib::Gate gate; @@ -173,7 +157,9 @@ void addDocument(DocBuilder & doc_builder, MemoryIndex &index, ISourceSelector & gate.await(); } -void Test::createIndex(const string &dir, uint32_t id, bool fusion) { +void +FusionRunnerTest::createIndex(const string &dir, uint32_t id, bool fusion) +{ std::filesystem::create_directory(std::filesystem::path(dir)); vespalib::asciistream ost; if (fusion) { @@ -209,7 +195,9 @@ void Test::createIndex(const string &dir, uint32_t id, bool fusion) { _selector->extractSaveInfo(index_dir + "/selector")->save(tuneFileAttributes, _fileHeaderContext); } -set<uint32_t> readFusionIds(const string &dir) { +set<uint32_t> +readFusionIds(const string &dir) +{ set<uint32_t> ids; const vespalib::string prefix("index.fusion."); std::filesystem::directory_iterator dir_scan(dir); @@ -225,13 +213,17 @@ set<uint32_t> readFusionIds(const string &dir) { return ids; } -vespalib::string getFusionIndexName(uint32_t fusion_id) { +vespalib::string +getFusionIndexName(uint32_t fusion_id) +{ vespalib::asciistream ost; ost << base_dir << "/index.fusion." << fusion_id; return ost.str(); } -void Test::checkResults(uint32_t fusion_id, const uint32_t *ids, size_t size) { +void +FusionRunnerTest::checkResults(uint32_t fusion_id, const uint32_t *ids, size_t size) +{ FakeRequestContext requestContext; DiskIndex disk_index(getFusionIndexName(fusion_id)); ASSERT_TRUE(disk_index.setup(TuneFileSearch())); @@ -256,66 +248,72 @@ void Test::checkResults(uint32_t fusion_id, const uint32_t *ids, size_t size) { } } -void Test::requireThatNoDiskIndexesGiveId0() { +TEST_F(FusionRunnerTest, require_that_no_disk_indexes_give_id_0) +{ uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); - EXPECT_EQUAL(0u, fusion_id); + EXPECT_EQ(0u, fusion_id); } -void Test::requireThatOneDiskIndexCausesCopy() { +TEST_F(FusionRunnerTest, rquire_that_one_disk_index_causes_copy) +{ createIndex(base_dir, disk_id[0]); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); - EXPECT_EQUAL(disk_id[0], fusion_id); + EXPECT_EQ(disk_id[0], fusion_id); set<uint32_t> fusion_ids = readFusionIds(base_dir); ASSERT_TRUE(!fusion_ids.empty()); - EXPECT_EQUAL(1u, fusion_ids.size()); - EXPECT_EQUAL(fusion_id, *fusion_ids.begin()); + EXPECT_EQ(1u, fusion_ids.size()); + EXPECT_EQ(fusion_id, *fusion_ids.begin()); checkResults(fusion_id, disk_id, 1); } -void Test::requireThatTwoDiskIndexesCauseFusion() { +TEST_F(FusionRunnerTest, require_that_two_disk_indexes_cause_fusion) +{ createIndex(base_dir, disk_id[0]); createIndex(base_dir, disk_id[1]); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); - EXPECT_EQUAL(disk_id[1], fusion_id); + EXPECT_EQ(disk_id[1], fusion_id); set<uint32_t> fusion_ids = readFusionIds(base_dir); ASSERT_TRUE(!fusion_ids.empty()); - EXPECT_EQUAL(1u, fusion_ids.size()); - EXPECT_EQUAL(fusion_id, *fusion_ids.begin()); + EXPECT_EQ(1u, fusion_ids.size()); + EXPECT_EQ(fusion_id, *fusion_ids.begin()); checkResults(fusion_id, disk_id, 2); } -void Test::requireThatFusionCanRunOnMultipleDiskIndexes() { +TEST_F(FusionRunnerTest, require_that_fusion_can_run_on_multiple_disk_indexes) +{ createIndex(base_dir, disk_id[0]); createIndex(base_dir, disk_id[1]); createIndex(base_dir, disk_id[2]); createIndex(base_dir, disk_id[3]); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); - EXPECT_EQUAL(disk_id[3], fusion_id); + EXPECT_EQ(disk_id[3], fusion_id); set<uint32_t> fusion_ids = readFusionIds(base_dir); ASSERT_TRUE(!fusion_ids.empty()); - EXPECT_EQUAL(1u, fusion_ids.size()); - EXPECT_EQUAL(fusion_id, *fusion_ids.begin()); + EXPECT_EQ(1u, fusion_ids.size()); + EXPECT_EQ(fusion_id, *fusion_ids.begin()); checkResults(fusion_id, disk_id, 4); } -void Test::requireThatOldFusionIndexCanBePartOfNewFusion() { +TEST_F(FusionRunnerTest, require_that_old_fusion_index_can_be_part_of_new_fusion) +{ createIndex(base_dir, disk_id[0], true); createIndex(base_dir, disk_id[1]); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); - EXPECT_EQUAL(disk_id[1], fusion_id); + EXPECT_EQ(disk_id[1], fusion_id); set<uint32_t> fusion_ids = readFusionIds(base_dir); ASSERT_TRUE(!fusion_ids.empty()); - EXPECT_EQUAL(2u, fusion_ids.size()); - EXPECT_EQUAL(disk_id[0], *fusion_ids.begin()); - EXPECT_EQUAL(fusion_id, *(++fusion_ids.begin())); + EXPECT_EQ(2u, fusion_ids.size()); + EXPECT_EQ(disk_id[0], *fusion_ids.begin()); + EXPECT_EQ(fusion_id, *(++fusion_ids.begin())); checkResults(fusion_id, disk_id, 2); } -void Test::requireThatSelectorsCanBeRebased() { +TEST_F(FusionRunnerTest, require_that_selectors_can_be_rebased) +{ createIndex(base_dir, disk_id[0]); createIndex(base_dir, disk_id[1]); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, std::make_shared<search::FlushToken>()); @@ -328,17 +326,24 @@ void Test::requireThatSelectorsCanBeRebased() { checkResults(fusion_id, disk_id, 3); } -void -Test::requireThatFusionCanBeStopped() +TEST_F(FusionRunnerTest, require_that_fusion_can_be_stopped) { createIndex(base_dir, disk_id[0]); createIndex(base_dir, disk_id[1]); auto flush_token = std::make_shared<search::FlushToken>(); flush_token->request_stop(); uint32_t fusion_id = _fusion_runner->fuse(_fusion_spec, 0u, _ops, flush_token); - EXPECT_EQUAL(0u, fusion_id); + EXPECT_EQ(0u, fusion_id); } } // namespace -TEST_APPHOOK(Test); +int +main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + if (argc > 0) { + DummyFileHeaderContext::setCreator(argv[0]); + } + return RUN_ALL_TESTS(); +} |