aboutsummaryrefslogtreecommitdiffstats
path: root/searchcorespi/src/tests/plugin/factoryregistry_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchcorespi/src/tests/plugin/factoryregistry_test.cpp')
-rw-r--r--searchcorespi/src/tests/plugin/factoryregistry_test.cpp63
1 files changed, 63 insertions, 0 deletions
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(); }