forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Abhilasha Seth <[email protected]>
- Loading branch information
1 parent
c3b2718
commit d785fa7
Showing
15 changed files
with
375 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
server/src/internalClusterTest/java/org/opensearch/plugins/PluginsServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* 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.Version; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.env.Environment; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.VersionUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class PluginsServiceIT extends OpenSearchIntegTestCase { | ||
|
||
public void testNodeBootstrapWithCompatiblePlugin() throws IOException { | ||
// Prepare the plugins directory and then start a node | ||
Path baseDir = createTempDir(); | ||
Path pluginDir = baseDir.resolve("plugins/dummy-plugin"); | ||
PluginTestUtil.writePluginProperties( | ||
pluginDir, | ||
"description", | ||
"dummy desc", | ||
"name", | ||
"dummyPlugin", | ||
"version", | ||
"1.0", | ||
"opensearch.version", | ||
Version.CURRENT.toString(), | ||
"java.version", | ||
System.getProperty("java.specification.version"), | ||
"classname", | ||
"test.DummyPlugin" | ||
); | ||
try (InputStream jar = PluginsServiceTests.class.getResourceAsStream("dummy-plugin.jar")) { | ||
Files.copy(jar, pluginDir.resolve("dummy-plugin.jar")); | ||
} | ||
internalCluster().startNode(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), baseDir)); | ||
for (PluginsService pluginsService : internalCluster().getDataNodeInstances(PluginsService.class)) { | ||
// Ensure plugins service was able to load the plugin | ||
assertEquals(1, pluginsService.info().getPluginInfos().stream().filter(info -> info.getName().equals("dummyPlugin")).count()); | ||
} | ||
} | ||
|
||
public void testNodeBootstrapWithRangeCompatiblePlugin() throws IOException { | ||
// Prepare the plugins directory and then start a node | ||
Path baseDir = createTempDir(); | ||
Path pluginDir = baseDir.resolve("plugins/dummy-plugin"); | ||
String range1 = "~" + Version.CURRENT; | ||
String range2 = "=" + Version.CURRENT; | ||
String ranges = "\"" + range1 + "," + range2 + "\""; | ||
PluginTestUtil.writePluginProperties( | ||
pluginDir, | ||
"description", | ||
"dummy desc", | ||
"name", | ||
"dummyPlugin", | ||
"version", | ||
"1.0", | ||
"dependencies", | ||
"{opensearch:" + ranges + "}", | ||
"java.version", | ||
System.getProperty("java.specification.version"), | ||
"classname", | ||
"test.DummyPlugin" | ||
); | ||
try (InputStream jar = PluginsServiceTests.class.getResourceAsStream("dummy-plugin.jar")) { | ||
Files.copy(jar, pluginDir.resolve("dummy-plugin.jar")); | ||
} | ||
internalCluster().startNode(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), baseDir)); | ||
for (PluginsService pluginsService : internalCluster().getDataNodeInstances(PluginsService.class)) { | ||
// Ensure plugins service was able to load the plugin | ||
assertEquals(1, pluginsService.info().getPluginInfos().stream().filter(info -> info.getName().equals("dummyPlugin")).count()); | ||
} | ||
} | ||
|
||
public void testNodeBootstrapWithInCompatiblePlugin() throws IOException { | ||
// Prepare the plugins directory with an incompatible plugin and attempt to start a node | ||
Path baseDir = createTempDir(); | ||
Path pluginDir = baseDir.resolve("plugins/dummy-plugin"); | ||
String incompatibleRange = "~" | ||
+ VersionUtils.getVersion(Version.CURRENT.major, Version.CURRENT.minor, (byte) (Version.CURRENT.revision + 1)); | ||
PluginTestUtil.writePluginProperties( | ||
pluginDir, | ||
"description", | ||
"dummy desc", | ||
"name", | ||
"dummyPlugin", | ||
"version", | ||
"1.0", | ||
"dependencies", | ||
"{opensearch:" + incompatibleRange + "}", | ||
"java.version", | ||
System.getProperty("java.specification.version"), | ||
"classname", | ||
"test.DummyPlugin" | ||
); | ||
try (InputStream jar = PluginsServiceTests.class.getResourceAsStream("dummy-plugin.jar")) { | ||
Files.copy(jar, pluginDir.resolve("dummy-plugin.jar")); | ||
} | ||
IllegalArgumentException e = assertThrows( | ||
IllegalArgumentException.class, | ||
() -> internalCluster().startNode(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), baseDir)) | ||
); | ||
assertThat(e.getMessage(), containsString("Plugin [dummyPlugin] was built for OpenSearch version ")); | ||
} | ||
} |
Oops, something went wrong.