use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class OpenSearchCliTestCase method runTest.
void runTest(final int expectedStatus, final boolean expectedInit, final BiConsumer<String, String> outputConsumer, final InitConsumer initConsumer, final String... args) throws Exception {
final MockTerminal terminal = new MockTerminal();
final Path home = createTempDir();
try {
final AtomicBoolean init = new AtomicBoolean();
final int status = OpenSearch.main(args, new OpenSearch() {
@Override
protected Environment createEnv(final Map<String, String> settings) throws UserException {
Settings.Builder builder = Settings.builder().put("path.home", home);
settings.forEach((k, v) -> builder.put(k, v));
final Settings realSettings = builder.build();
return new Environment(realSettings, home.resolve("config"));
}
@Override
void init(final boolean daemonize, final Path pidFile, final boolean quiet, Environment initialEnv) {
init.set(true);
initConsumer.accept(!daemonize, pidFile, quiet, initialEnv);
}
@Override
protected boolean addShutdownHook() {
return false;
}
}, terminal);
assertThat(status, equalTo(expectedStatus));
assertThat(init.get(), equalTo(expectedInit));
outputConsumer.accept(terminal.getOutput(), terminal.getErrorOutput());
} catch (Exception e) {
// if an unexpected exception is thrown, we log
// terminal output to aid debugging
logger.info("Stdout:\n" + terminal.getOutput());
logger.info("Stderr:\n" + terminal.getErrorOutput());
// rethrow so the test fails
throw e;
}
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class AnalysisTestsHelper method createTestAnalysisFromSettings.
public static OpenSearchTestCase.TestAnalysis createTestAnalysisFromSettings(final Settings settings, final Path configPath, final AnalysisPlugin... plugins) throws IOException {
final Settings actualSettings;
if (settings.get(IndexMetadata.SETTING_VERSION_CREATED) == null) {
actualSettings = Settings.builder().put(settings).put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
} else {
actualSettings = settings;
}
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", actualSettings);
final AnalysisRegistry analysisRegistry = new AnalysisModule(new Environment(actualSettings, configPath), Arrays.asList(plugins)).getAnalysisRegistry();
return new OpenSearchTestCase.TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class OpenSearchTestCase method createTestAnalysis.
/**
* Creates an TestAnalysis with all the default analyzers configured.
*/
public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Settings nodeSettings, AnalysisPlugin... analysisPlugins) throws IOException {
Environment env = TestEnvironment.newEnvironment(nodeSettings);
AnalysisModule analysisModule = new AnalysisModule(env, Arrays.asList(analysisPlugins));
AnalysisRegistry analysisRegistry = analysisModule.getAnalysisRegistry();
return new TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class OpenSearchIntegTestCase method randomRepoPath.
/**
* Returns path to a random directory that can be used to create a temporary file system repo
*/
public static Path randomRepoPath(Settings settings) {
Environment environment = TestEnvironment.newEnvironment(settings);
Path[] repoFiles = environment.repoFiles();
assert repoFiles.length > 0;
Path path;
do {
path = repoFiles[0].resolve(randomAlphaOfLength(10));
} while (Files.exists(path));
return path;
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class AbstractBootstrapCheckTestCase method createTestContext.
protected BootstrapContext createTestContext(Settings settings, Metadata metadata) {
Path homePath = createTempDir();
Environment environment = new Environment(settings(Version.CURRENT).put(settings).put(Environment.PATH_HOME_SETTING.getKey(), homePath.toString()).build(), null);
return new BootstrapContext(environment, metadata);
}
Aggregations