Add default for EnginePlugin.getEngineFactory (#2419)

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 <jmazane@amazon.com>
This commit is contained in:
John Mazanec 2022-03-16 13:28:24 -04:00 committed by GitHub
parent 02ffd4c548
commit f52f6f5052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -56,7 +56,9 @@ public interface EnginePlugin {
* *
* @return an optional engine factory * @return an optional engine factory
*/ */
Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings); default Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
return Optional.empty();
}
/** /**
* EXPERT: * EXPERT:

View File

@ -146,6 +146,21 @@ public class EngineConfigFactoryTests extends OpenSearchTestCase {
assertNotNull(config.getCodec()); assertNotNull(config.getCodec());
} }
public void testGetEngineFactory() {
final EngineFactory engineFactory = config -> null;
EnginePlugin enginePluginThatImplementsGetEngineFactory = new EnginePlugin() {
@Override
public Optional<EngineFactory> 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 { private static class FooEnginePlugin extends Plugin implements EnginePlugin {
@Override @Override
public Optional<EngineFactory> getEngineFactory(final IndexSettings indexSettings) { public Optional<EngineFactory> getEngineFactory(final IndexSettings indexSettings) {