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:
Bernd Ahlers
2023-04-07 12:49:40 +02:00
committed by GitHub
parent 62b90afd9a
commit a2a2ee7af8
2 changed files with 61 additions and 3 deletions

View File

@@ -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;
}
}
}