mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Don't pass JAVA_HOME environment variable to OpenSearch process (#15166)
The OpenSearch process should use its bundled JVM version.
This commit is contained in:
@@ -21,13 +21,16 @@ import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.RetryerBuilder;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
import com.github.rholder.retry.WaitStrategies;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.ExecuteException;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.graylog.datanode.ProcessProvidingExecutor;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
@@ -37,6 +40,7 @@ import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -89,7 +93,14 @@ class CommandLineProcessTest {
|
||||
LOG.info("On process failed:", e);
|
||||
}
|
||||
};
|
||||
final CommandLineProcess process = new CommandLineProcess(binPath, Collections.emptyList(), listener);
|
||||
final TestExecutor testExecutor = new TestExecutor();
|
||||
final CommandLineProcess process = new CommandLineProcess(
|
||||
binPath,
|
||||
Collections.emptyList(),
|
||||
listener,
|
||||
() -> testExecutor,
|
||||
() -> Map.of("USER", "test", "JAVA_HOME", "/path/to/jre")
|
||||
);
|
||||
process.start();
|
||||
|
||||
waitTillLogsAreAvailable(stdout, 3);
|
||||
@@ -106,6 +117,8 @@ class CommandLineProcessTest {
|
||||
.hasSize(1)
|
||||
.contains("This message goes to stderr");
|
||||
|
||||
Assertions.assertThat(testExecutor.getEnvironment())
|
||||
.doesNotContainKey("JAVA_HOME");
|
||||
}
|
||||
|
||||
private void waitTillLogsAreAvailable(List<String> logs, int expectedLinesCount) throws ExecutionException, RetryException {
|
||||
@@ -155,4 +168,21 @@ class CommandLineProcessTest {
|
||||
|
||||
Assertions.assertThat(exitCode).isEqualTo(143);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that allows access to the environment argument.
|
||||
*/
|
||||
private static class TestExecutor extends ProcessProvidingExecutor {
|
||||
private Map<String, String> environment = Map.of();
|
||||
|
||||
@Override
|
||||
protected Process launch(CommandLine command, Map<String, String> env, File dir) throws IOException {
|
||||
this.environment = env;
|
||||
return super.launch(command, env, dir);
|
||||
}
|
||||
|
||||
public Map<String, String> getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user