aboutsummaryrefslogtreecommitdiffstats
path: root/searchcorespi/src/tests
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 /searchcorespi/src/tests
Publish
Diffstat (limited to 'searchcorespi/src/tests')
-rw-r--r--searchcorespi/src/tests/plugin/.gitignore5
-rw-r--r--searchcorespi/src/tests/plugin/CMakeLists.txt29
-rw-r--r--searchcorespi/src/tests/plugin/DESC1
-rw-r--r--searchcorespi/src/tests/plugin/FILES1
-rw-r--r--searchcorespi/src/tests/plugin/empty.cpp1
-rw-r--r--searchcorespi/src/tests/plugin/factoryregistry_test.cpp63
-rw-r--r--searchcorespi/src/tests/plugin/plugin.cpp77
-rw-r--r--searchcorespi/src/tests/plugin/plugin_test.cpp32
8 files changed, 209 insertions, 0 deletions
diff --git a/searchcorespi/src/tests/plugin/.gitignore b/searchcorespi/src/tests/plugin/.gitignore
new file mode 100644
index 00000000000..e49000038ad
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/.gitignore
@@ -0,0 +1,5 @@
+Makefile
+.depend
+*_test
+searchcorespi_factoryregistry_test_app
+searchcorespi_plugin_test_app
diff --git a/searchcorespi/src/tests/plugin/CMakeLists.txt b/searchcorespi/src/tests/plugin/CMakeLists.txt
new file mode 100644
index 00000000000..ae70cc2d7f7
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/CMakeLists.txt
@@ -0,0 +1,29 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchcorespi_plugin_test_app
+ SOURCES
+ plugin_test.cpp
+ DEPENDS
+ searchcorespi
+)
+vespa_add_test(
+ NAME searchcorespi_plugin_test_app
+ COMMAND searchcorespi_plugin_test_app
+ ENVIRONMENT "LD_LIBRARY_PATH=."
+)
+vespa_add_executable(searchcorespi_factoryregistry_test_app
+ SOURCES
+ factoryregistry_test.cpp
+ DEPENDS
+ searchcorespi
+)
+vespa_add_test(NAME searchcorespi_factoryregistry_test_app COMMAND searchcorespi_factoryregistry_test_app)
+vespa_add_library(searchcorespi_tplugin
+ SOURCES
+ plugin.cpp
+ DEPENDS
+)
+vespa_add_library(searchcorespi_illegal-plugin
+ SOURCES
+ empty.cpp
+ DEPENDS
+)
diff --git a/searchcorespi/src/tests/plugin/DESC b/searchcorespi/src/tests/plugin/DESC
new file mode 100644
index 00000000000..80d66100e85
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/DESC
@@ -0,0 +1 @@
+Test of factory plugin interface.
diff --git a/searchcorespi/src/tests/plugin/FILES b/searchcorespi/src/tests/plugin/FILES
new file mode 100644
index 00000000000..1b658927feb
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/FILES
@@ -0,0 +1 @@
+plugin_test.cpp
diff --git a/searchcorespi/src/tests/plugin/empty.cpp b/searchcorespi/src/tests/plugin/empty.cpp
new file mode 100644
index 00000000000..d84fabdd5a2
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/empty.cpp
@@ -0,0 +1 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
diff --git a/searchcorespi/src/tests/plugin/factoryregistry_test.cpp b/searchcorespi/src/tests/plugin/factoryregistry_test.cpp
new file mode 100644
index 00000000000..16cb03a5496
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/factoryregistry_test.cpp
@@ -0,0 +1,63 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Unit tests for factoryregistry.
+
+#include <vespa/log/log.h>
+LOG_SETUP("factoryregistry_test");
+#include <vespa/fastos/fastos.h>
+
+#include <vespa/searchcorespi/plugin/factoryregistry.h>
+#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h>
+#include <vespa/vespalib/stllike/string.h>
+#include <vespa/vespalib/testkit/testapp.h>
+
+using vespalib::string;
+using namespace searchcorespi;
+
+namespace {
+
+struct MyFactory : IIndexManagerFactory {
+
+ virtual IIndexManager::UP createIndexManager(const IndexManagerConfig &,
+ const index::IndexMaintainerConfig &,
+ const index::IndexMaintainerContext &) {
+ return IIndexManager::UP();
+ }
+ virtual config::ConfigKeySet getConfigKeys(
+ const string &,
+ const search::index::Schema &,
+ const config::ConfigInstance &) {
+ return config::ConfigKeySet();
+ }
+};
+
+const string name = "factory";
+
+TEST("require that factories can be added and removed") {
+ FactoryRegistry registry;
+ EXPECT_FALSE(registry.isRegistered(name));
+ registry.add(name, IIndexManagerFactory::SP(new MyFactory));
+ EXPECT_TRUE(registry.get(name).get());
+ EXPECT_TRUE(registry.isRegistered(name));
+ registry.remove(name);
+ EXPECT_EXCEPTION(registry.get(name), vespalib::IllegalArgumentException,
+ "No factory is registered with the name");
+}
+
+TEST("require that two factories with the same name cannot be added") {
+ FactoryRegistry registry;
+ registry.add(name, IIndexManagerFactory::SP(new MyFactory));
+ EXPECT_EXCEPTION(
+ registry.add(name, IIndexManagerFactory::SP(new MyFactory)),
+ vespalib::IllegalArgumentException,
+ "A factory is already registered with the same name");
+}
+
+TEST("require that a non-existent factory cannot be removed") {
+ FactoryRegistry registry;
+ EXPECT_EXCEPTION(registry.remove(name), vespalib::IllegalArgumentException,
+ "No factory is registered with the name");
+}
+
+} // namespace
+
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchcorespi/src/tests/plugin/plugin.cpp b/searchcorespi/src/tests/plugin/plugin.cpp
new file mode 100644
index 00000000000..ecd8cc892d9
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/plugin.cpp
@@ -0,0 +1,77 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h>
+
+using namespace search;
+using namespace search::index;
+using namespace vespalib;
+using namespace config;
+
+namespace searchcorespi {
+class IndexManager : public searchcorespi::IIndexManager
+{
+public:
+
+ typedef search::SerialNum SerialNum;
+ typedef search::index::Schema Schema;
+ typedef document::Document Document;
+ using OnWriteDoneType =
+ const std::shared_ptr<search::IDestructorCallback> &;
+ virtual void putDocument(uint32_t, const Document &, SerialNum) override { }
+ virtual void removeDocument(uint32_t, SerialNum) override { }
+ virtual void commit(SerialNum, OnWriteDoneType) override { }
+ virtual void heartBeat(SerialNum ) {}
+ virtual SerialNum getCurrentSerialNum() const { return 0; }
+ virtual SerialNum getFlushedSerialNum() const { return 0; }
+ virtual IndexSearchable::SP getSearchable() const {
+ IndexSearchable::SP s;
+ return s;
+ }
+ virtual SearchableStats getSearchableStats() const {
+ SearchableStats s;
+ return s;
+ }
+ virtual searchcorespi::IFlushTarget::List getFlushTargets() {
+ searchcorespi::IFlushTarget::List l;
+ return l;
+ }
+ virtual void setSchema(const Schema & , const Schema &) { }
+ virtual void wipeHistory(SerialNum , const Schema &) { }
+};
+
+class IndexManagerFactory : public searchcorespi::IIndexManagerFactory
+{
+public:
+ virtual IIndexManager::UP createIndexManager(const IndexManagerConfig &managerCfg,
+ const index::IndexMaintainerConfig &maintainerConfig,
+ const index::IndexMaintainerContext &maintainerContext);
+
+ virtual ConfigKeySet getConfigKeys(const string &configId,
+ const Schema &schema,
+ const ConfigInstance &rootConfig);
+};
+
+IIndexManager::UP
+IndexManagerFactory::createIndexManager(const IndexManagerConfig &,
+ const index::IndexMaintainerConfig &,
+ const index::IndexMaintainerContext &)
+{
+ return IIndexManager::UP(new IndexManager());
+}
+
+ConfigKeySet
+IndexManagerFactory::getConfigKeys(const string &,
+ const Schema &,
+ const ConfigInstance &)
+{
+ ConfigKeySet keys;
+ return keys;
+}
+
+}
+
+searchcorespi::IIndexManagerFactory *
+createIndexManagerFactory()
+{
+ return new searchcorespi::IndexManagerFactory();
+}
+
diff --git a/searchcorespi/src/tests/plugin/plugin_test.cpp b/searchcorespi/src/tests/plugin/plugin_test.cpp
new file mode 100644
index 00000000000..34692b4ed7b
--- /dev/null
+++ b/searchcorespi/src/tests/plugin/plugin_test.cpp
@@ -0,0 +1,32 @@
+// 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/vespalib/testkit/testapp.h>
+#include <vespa/searchcorespi/plugin/factoryloader.h>
+#include <vespa/log/log.h>
+LOG_SETUP("factory_test");
+
+using namespace searchcorespi;
+
+namespace {
+TEST("require that plugins can be loaded.") {
+ FactoryLoader fl;
+ IIndexManagerFactory::UP f = fl.create("searchcorespi_tplugin");
+ ASSERT_TRUE(f.get());
+}
+
+TEST("require that non-existent plugin causes failure") {
+ FactoryLoader fl;
+ EXPECT_EXCEPTION(fl.create("no-such-plugin"),
+ vespalib::IllegalArgumentException,
+ "cannot open shared object file");
+}
+
+TEST("require that missing factory function causes failure") {
+ FactoryLoader fl;
+ EXPECT_EXCEPTION(fl.create("searchcorespi_illegal-plugin"),
+ vespalib::IllegalArgumentException,
+ "Failed locating symbol 'createIndexManagerFactory'");
+}
+} // namespace
+
+TEST_MAIN() { TEST_RUN_ALL(); }