summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/attribute/attribute_populator
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/attribute/attribute_populator
Publish
Diffstat (limited to 'searchcore/src/tests/proton/attribute/attribute_populator')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_populator/.gitignore1
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_populator/CMakeLists.txt9
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_populator/DESC1
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_populator/FILES1
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_populator/attribute_populator_test.cpp98
5 files changed, 110 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_populator/.gitignore b/searchcore/src/tests/proton/attribute/attribute_populator/.gitignore
new file mode 100644
index 00000000000..2400fd559e6
--- /dev/null
+++ b/searchcore/src/tests/proton/attribute/attribute_populator/.gitignore
@@ -0,0 +1 @@
+searchcore_attribute_populator_test_app
diff --git a/searchcore/src/tests/proton/attribute/attribute_populator/CMakeLists.txt b/searchcore/src/tests/proton/attribute/attribute_populator/CMakeLists.txt
new file mode 100644
index 00000000000..064759b88d1
--- /dev/null
+++ b/searchcore/src/tests/proton/attribute/attribute_populator/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchcore_attribute_populator_test_app
+ SOURCES
+ attribute_populator_test.cpp
+ DEPENDS
+ searchcore_attribute
+ searchcore_pcommon
+)
+vespa_add_test(NAME searchcore_attribute_populator_test_app COMMAND searchcore_attribute_populator_test_app)
diff --git a/searchcore/src/tests/proton/attribute/attribute_populator/DESC b/searchcore/src/tests/proton/attribute/attribute_populator/DESC
new file mode 100644
index 00000000000..5ef9dcb2709
--- /dev/null
+++ b/searchcore/src/tests/proton/attribute/attribute_populator/DESC
@@ -0,0 +1 @@
+attribute_populator test. Take a look at attribute_populator_test.cpp for details.
diff --git a/searchcore/src/tests/proton/attribute/attribute_populator/FILES b/searchcore/src/tests/proton/attribute/attribute_populator/FILES
new file mode 100644
index 00000000000..b6bf0bf8458
--- /dev/null
+++ b/searchcore/src/tests/proton/attribute/attribute_populator/FILES
@@ -0,0 +1 @@
+attribute_populator_test.cpp
diff --git a/searchcore/src/tests/proton/attribute/attribute_populator/attribute_populator_test.cpp b/searchcore/src/tests/proton/attribute/attribute_populator/attribute_populator_test.cpp
new file mode 100644
index 00000000000..36e50249b89
--- /dev/null
+++ b/searchcore/src/tests/proton/attribute/attribute_populator/attribute_populator_test.cpp
@@ -0,0 +1,98 @@
+// 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("attribute_populator_test");
+#include <vespa/vespalib/testkit/testapp.h>
+
+#include <vespa/searchcommon/common/schema.h>
+#include <vespa/searchcore/proton/attribute/attributemanager.h>
+#include <vespa/searchcore/proton/attribute/attribute_populator.h>
+#include <vespa/searchcore/proton/test/test.h>
+#include <vespa/searchlib/index/docbuilder.h>
+#include <vespa/searchlib/index/dummyfileheadercontext.h>
+#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/searchlib/common/foregroundtaskexecutor.h>
+
+using namespace document;
+using namespace proton;
+using namespace search;
+using namespace search::index;
+
+typedef search::attribute::Config AVConfig;
+typedef search::attribute::BasicType AVBasicType;
+
+const vespalib::string TEST_DIR = "testdir";
+const uint64_t CREATE_SERIAL_NUM = 8u;
+
+Schema
+createSchema()
+{
+ Schema schema;
+ schema.addAttributeField(Schema::AttributeField("a1", Schema::DataType::INT32));
+ return schema;
+}
+
+struct DocContext
+{
+ Schema _schema;
+ DocBuilder _builder;
+ DocContext()
+ : _schema(createSchema()),
+ _builder(_schema)
+ {
+ }
+ Document::UP create(uint32_t id, int64_t fieldValue) {
+ vespalib::string docId =
+ vespalib::make_string("id:searchdocument:searchdocument::%u", id);
+ return _builder.startDocument(docId).
+ startAttributeField("a1").addInt(fieldValue).endField().
+ endDocument();
+ }
+};
+
+struct Fixture
+{
+ test::DirectoryHandler _testDir;
+ DummyFileHeaderContext _fileHeader;
+ ForegroundTaskExecutor _attributeFieldWriter;
+ AttributeManager::SP _mgr;
+ AttributePopulator _pop;
+ DocContext _ctx;
+ Fixture()
+ : _testDir(TEST_DIR),
+ _fileHeader(),
+ _attributeFieldWriter(),
+ _mgr(new AttributeManager(TEST_DIR, "test.subdb",
+ TuneFileAttributes(),
+ _fileHeader, _attributeFieldWriter)),
+ _pop(_mgr, 1, "test"),
+ _ctx()
+ {
+ _mgr->addAttribute("a1", AVConfig(AVBasicType::INT32),
+ 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(1u, 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(2u, attr->get().getStatus().getLastSyncToken());
+}
+
+TEST_MAIN()
+{
+ TEST_RUN_ALL();
+}