From 72231250ed81e10d66bfe70701e64fa5fe50f712 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 15 Jun 2016 23:09:44 +0200 Subject: Publish --- searchcorespi/src/tests/plugin/.gitignore | 5 ++ searchcorespi/src/tests/plugin/CMakeLists.txt | 29 ++++++++ searchcorespi/src/tests/plugin/DESC | 1 + searchcorespi/src/tests/plugin/FILES | 1 + searchcorespi/src/tests/plugin/empty.cpp | 1 + .../src/tests/plugin/factoryregistry_test.cpp | 63 ++++++++++++++++++ searchcorespi/src/tests/plugin/plugin.cpp | 77 ++++++++++++++++++++++ searchcorespi/src/tests/plugin/plugin_test.cpp | 32 +++++++++ 8 files changed, 209 insertions(+) create mode 100644 searchcorespi/src/tests/plugin/.gitignore create mode 100644 searchcorespi/src/tests/plugin/CMakeLists.txt create mode 100644 searchcorespi/src/tests/plugin/DESC create mode 100644 searchcorespi/src/tests/plugin/FILES create mode 100644 searchcorespi/src/tests/plugin/empty.cpp create mode 100644 searchcorespi/src/tests/plugin/factoryregistry_test.cpp create mode 100644 searchcorespi/src/tests/plugin/plugin.cpp create mode 100644 searchcorespi/src/tests/plugin/plugin_test.cpp (limited to 'searchcorespi/src/tests') 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 +LOG_SETUP("factoryregistry_test"); +#include + +#include +#include +#include +#include + +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 + +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 &; + 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 +#include +#include +#include +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(); } -- cgit v1.2.3