From cc05bcc39530041b2dcdfde4effae8f4a24d5d23 Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Wed, 9 Mar 2022 11:36:26 -0800 Subject: [PATCH 1/3] Add default for EnginePlugin.getEngineFactory Adds default implementation for getEngineFactory in EnginePlugin. The default just returns Optional.empty(), allowing plugin developers to implement this plugin without implementing this method. Signed-off-by: John Mazanec --- server/src/main/java/org/opensearch/plugins/EnginePlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/plugins/EnginePlugin.java b/server/src/main/java/org/opensearch/plugins/EnginePlugin.java index 4c3a07d7b98d9..31844dbdaec2b 100644 --- a/server/src/main/java/org/opensearch/plugins/EnginePlugin.java +++ b/server/src/main/java/org/opensearch/plugins/EnginePlugin.java @@ -56,7 +56,9 @@ public interface EnginePlugin { * * @return an optional engine factory */ - Optional getEngineFactory(IndexSettings indexSettings); + default Optional getEngineFactory(IndexSettings indexSettings) { + return Optional.empty(); + } /** * EXPERT: From 9e10d0ea6e34f1534a7666db035224b26b0ad167 Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Wed, 9 Mar 2022 13:02:51 -0800 Subject: [PATCH 2/3] Add EnginePluginTests for getEngineFactory method Signed-off-by: John Mazanec --- .../opensearch/plugins/EnginePluginTests.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 server/src/test/java/org/opensearch/plugins/EnginePluginTests.java diff --git a/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java b/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java new file mode 100644 index 0000000000000..19b392a0251d9 --- /dev/null +++ b/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.plugins; + +import org.opensearch.index.IndexSettings; +import org.opensearch.index.engine.EngineFactory; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.Optional; + +public class EnginePluginTests extends OpenSearchTestCase { + + public void testGetEngineFactory() { + final EngineFactory engineFactory = config -> null; + EnginePlugin enginePluginThatImplementsGetEngineFactory = new EnginePlugin() { + @Override + public Optional getEngineFactory(IndexSettings indexSettings) { + return Optional.of(engineFactory); + } + }; + assertEquals(engineFactory, enginePluginThatImplementsGetEngineFactory.getEngineFactory(null).orElse(null)); + + EnginePlugin enginePluginThatDoesNotImplementsGetEngineFactory = new EnginePlugin() { + }; + assertFalse(enginePluginThatDoesNotImplementsGetEngineFactory.getEngineFactory(null).isPresent()); + } +} From 98f2f5e8e9d0152916eed4bb4d9e1207db73b312 Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Fri, 11 Mar 2022 09:17:21 -0800 Subject: [PATCH 3/3] Move getEngineFactory test Signed-off-by: John Mazanec --- .../engine/EngineConfigFactoryTests.java | 15 +++++++++ .../opensearch/plugins/EnginePluginTests.java | 33 ------------------- 2 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 server/src/test/java/org/opensearch/plugins/EnginePluginTests.java diff --git a/server/src/test/java/org/opensearch/index/engine/EngineConfigFactoryTests.java b/server/src/test/java/org/opensearch/index/engine/EngineConfigFactoryTests.java index a6bc87d53c004..8030619500278 100644 --- a/server/src/test/java/org/opensearch/index/engine/EngineConfigFactoryTests.java +++ b/server/src/test/java/org/opensearch/index/engine/EngineConfigFactoryTests.java @@ -146,6 +146,21 @@ public void testCreateCodecServiceFromFactory() { assertNotNull(config.getCodec()); } + public void testGetEngineFactory() { + final EngineFactory engineFactory = config -> null; + EnginePlugin enginePluginThatImplementsGetEngineFactory = new EnginePlugin() { + @Override + public Optional getEngineFactory(IndexSettings indexSettings) { + return Optional.of(engineFactory); + } + }; + assertEquals(engineFactory, enginePluginThatImplementsGetEngineFactory.getEngineFactory(null).orElse(null)); + + EnginePlugin enginePluginThatDoesNotImplementsGetEngineFactory = new EnginePlugin() { + }; + assertFalse(enginePluginThatDoesNotImplementsGetEngineFactory.getEngineFactory(null).isPresent()); + } + private static class FooEnginePlugin extends Plugin implements EnginePlugin { @Override public Optional getEngineFactory(final IndexSettings indexSettings) { diff --git a/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java b/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java deleted file mode 100644 index 19b392a0251d9..0000000000000 --- a/server/src/test/java/org/opensearch/plugins/EnginePluginTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.plugins; - -import org.opensearch.index.IndexSettings; -import org.opensearch.index.engine.EngineFactory; -import org.opensearch.test.OpenSearchTestCase; - -import java.util.Optional; - -public class EnginePluginTests extends OpenSearchTestCase { - - public void testGetEngineFactory() { - final EngineFactory engineFactory = config -> null; - EnginePlugin enginePluginThatImplementsGetEngineFactory = new EnginePlugin() { - @Override - public Optional getEngineFactory(IndexSettings indexSettings) { - return Optional.of(engineFactory); - } - }; - assertEquals(engineFactory, enginePluginThatImplementsGetEngineFactory.getEngineFactory(null).orElse(null)); - - EnginePlugin enginePluginThatDoesNotImplementsGetEngineFactory = new EnginePlugin() { - }; - assertFalse(enginePluginThatDoesNotImplementsGetEngineFactory.getEngineFactory(null).isPresent()); - } -}