// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include LOG_SETUP("attribute_populator_test"); using document::config_builder::DocumenttypesConfigBuilderHelper; using document::config_builder::Struct; using vespalib::ForegroundTaskExecutor; using vespalib::ForegroundThreadExecutor; using namespace document; using namespace proton; using namespace search; using namespace search::index; using search::test::DirectoryHandler; using AVBasicType = search::attribute::BasicType; using AVConfig = search::attribute::Config; const vespalib::string TEST_DIR = "testdir"; const uint64_t CREATE_SERIAL_NUM = 8u; std::unique_ptr makeDocTypeRepo() { DocumenttypesConfigBuilderHelper builder; builder.document(-645763131, "searchdocument", Struct("searchdocument.header"), Struct("searchdocument.body"). addField("a1", DataType::T_INT)); return std::make_unique(builder.config()); } struct DocContext { std::unique_ptr _repo; DocContext() : _repo(makeDocTypeRepo()) { } std::shared_ptr create(uint32_t id, int64_t fieldValue) { vespalib::string docId = vespalib::make_string("id:searchdocument:searchdocument::%u", id); auto doc = std::make_shared(*_repo->getDocumentType("searchdocument"), DocumentId(docId)); doc->setValue("a1", IntFieldValue(fieldValue)); return doc; } }; struct Fixture { DirectoryHandler _testDir; DummyFileHeaderContext _fileHeader; ForegroundTaskExecutor _attributeFieldWriter; ForegroundThreadExecutor _shared; HwInfo _hwInfo; AttributeManager::SP _mgr; std::unique_ptr _pop; DocContext _ctx; Fixture() : _testDir(TEST_DIR), _fileHeader(), _attributeFieldWriter(), _shared(), _hwInfo(), _mgr(std::make_shared(TEST_DIR, "test.subdb", TuneFileAttributes(), _fileHeader, std::make_shared(), _attributeFieldWriter, _shared, _hwInfo)), _pop(), _ctx() { _mgr->addAttribute({ "a1", AVConfig(AVBasicType::INT32)}, CREATE_SERIAL_NUM); _pop = std::make_unique(_mgr, 1, "test", CREATE_SERIAL_NUM); } AttributeGuard::UP getAttr() { return _mgr->getAttribute("a1"); } }; TEST_F("require that reprocess with document populates attribute", Fixture) { AttributeGuard::UP attr = f.getAttr(); EXPECT_EQUAL(1u, attr->get()->getNumDocs()); f._pop->handleExisting(5, f._ctx.create(0, 33)); EXPECT_EQUAL(6u, attr->get()->getNumDocs()); EXPECT_EQUAL(33, attr->get()->getInt(5)); EXPECT_EQUAL(0u, attr->get()->getStatus().getLastSyncToken()); f._pop->handleExisting(6, f._ctx.create(1, 44)); EXPECT_EQUAL(7u, attr->get()->getNumDocs()); EXPECT_EQUAL(44, attr->get()->getInt(6)); EXPECT_EQUAL(0u, attr->get()->getStatus().getLastSyncToken()); f._pop->done(); EXPECT_EQUAL(CREATE_SERIAL_NUM, attr->get()->getStatus().getLastSyncToken()); } TEST_MAIN() { std::filesystem::remove_all(std::filesystem::path(TEST_DIR)); TEST_RUN_ALL(); }