|
@@ -30,12 +30,11 @@ import org.elasticsearch.packaging.util.Shell;
|
|
|
import org.elasticsearch.packaging.util.Shell.Result;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
-import static java.util.stream.Collectors.joining;
|
|
|
import static org.elasticsearch.packaging.util.Archives.ARCHIVE_OWNER;
|
|
|
import static org.elasticsearch.packaging.util.Archives.installArchive;
|
|
|
import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation;
|
|
@@ -46,6 +45,7 @@ import static org.elasticsearch.packaging.util.FileUtils.append;
|
|
|
import static org.elasticsearch.packaging.util.FileUtils.cp;
|
|
|
import static org.elasticsearch.packaging.util.FileUtils.getTempDir;
|
|
|
import static org.elasticsearch.packaging.util.FileUtils.mkdir;
|
|
|
+import static org.elasticsearch.packaging.util.FileUtils.mv;
|
|
|
import static org.elasticsearch.packaging.util.FileUtils.rm;
|
|
|
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
|
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
@@ -77,46 +77,23 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
|
|
|
assertThat(r.stdout, isEmptyString());
|
|
|
}
|
|
|
|
|
|
- public void test30AbortWhenJavaMissing() {
|
|
|
+ public void test30NoJava() {
|
|
|
assumeThat(installation, is(notNullValue()));
|
|
|
|
|
|
final Installation.Executables bin = installation.executables();
|
|
|
final Shell sh = new Shell();
|
|
|
|
|
|
- Platforms.onWindows(() -> {
|
|
|
- // on windows, removing java from PATH and removing JAVA_HOME is less involved than changing the permissions of the java
|
|
|
- // executable. we also don't check permissions in the windows scripts anyway
|
|
|
- final String originalPath = sh.run("$Env:PATH").stdout.trim();
|
|
|
- final String newPath = Arrays.stream(originalPath.split(";"))
|
|
|
- .filter(path -> path.contains("Java") == false)
|
|
|
- .collect(joining(";"));
|
|
|
-
|
|
|
- // note the lack of a $ when clearing the JAVA_HOME env variable - with a $ it deletes the java home directory
|
|
|
- // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/providers/environment-provider?view=powershell-6
|
|
|
- //
|
|
|
- // this won't persist to another session so we don't have to reset anything
|
|
|
- final Result runResult = sh.runIgnoreExitCode(
|
|
|
- "$Env:PATH = '" + newPath + "'; " +
|
|
|
- "Remove-Item Env:JAVA_HOME; " +
|
|
|
- bin.elasticsearch
|
|
|
- );
|
|
|
+ final Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
|
|
|
|
|
|
+ try {
|
|
|
+ mv(installation.bundledJdk, relocatedJdk);
|
|
|
+ // ask for elasticsearch version to quickly exit if java is actually found (ie test failure)
|
|
|
+ final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v");
|
|
|
assertThat(runResult.exitCode, is(1));
|
|
|
- assertThat(runResult.stderr, containsString("could not find java; set JAVA_HOME"));
|
|
|
- });
|
|
|
-
|
|
|
- Platforms.onLinux(() -> {
|
|
|
- final String javaPath = sh.run("command -v java").stdout.trim();
|
|
|
-
|
|
|
- try {
|
|
|
- sh.run("chmod -x '" + javaPath + "'");
|
|
|
- final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString());
|
|
|
- assertThat(runResult.exitCode, is(1));
|
|
|
- assertThat(runResult.stderr, containsString("could not find java; set JAVA_HOME"));
|
|
|
- } finally {
|
|
|
- sh.run("chmod +x '" + javaPath + "'");
|
|
|
- }
|
|
|
- });
|
|
|
+ assertThat(runResult.stderr, containsString("could not find java in JAVA_HOME or bundled"));
|
|
|
+ } finally {
|
|
|
+ mv(relocatedJdk, installation.bundledJdk);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void test40CreateKeystoreManually() {
|
|
@@ -160,15 +137,51 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
|
|
|
|
|
|
Archives.runElasticsearch(installation);
|
|
|
|
|
|
- final String gcLogName = Platforms.LINUX
|
|
|
- ? "gc.log.0.current"
|
|
|
- : "gc.log";
|
|
|
- assertTrue("gc logs exist", Files.exists(installation.logs.resolve(gcLogName)));
|
|
|
+ assertTrue("gc logs exist", Files.exists(installation.logs.resolve("gc.log")));
|
|
|
ServerUtils.runElasticsearchTests();
|
|
|
|
|
|
Archives.stopElasticsearch(installation);
|
|
|
}
|
|
|
|
|
|
+ public void assertRunsWithJavaHome() throws IOException {
|
|
|
+ Shell sh = new Shell();
|
|
|
+
|
|
|
+ Platforms.onLinux(() -> {
|
|
|
+ String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
|
|
|
+ sh.getEnv().put("JAVA_HOME", systemJavaHome);
|
|
|
+ });
|
|
|
+ Platforms.onWindows(() -> {
|
|
|
+ final String systemJavaHome = sh.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
|
|
|
+ sh.getEnv().put("JAVA_HOME", systemJavaHome);
|
|
|
+ });
|
|
|
+
|
|
|
+ Archives.runElasticsearch(installation, sh);
|
|
|
+ ServerUtils.runElasticsearchTests();
|
|
|
+ Archives.stopElasticsearch(installation);
|
|
|
+
|
|
|
+ String systemJavaHome = sh.getEnv().get("JAVA_HOME");
|
|
|
+ Path log = installation.logs.resolve("elasticsearch.log");
|
|
|
+ assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void test51JavaHomeOverride() throws IOException {
|
|
|
+ assumeThat(installation, is(notNullValue()));
|
|
|
+
|
|
|
+ assertRunsWithJavaHome();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void test52BundledJdkRemoved() throws IOException {
|
|
|
+ assumeThat(installation, is(notNullValue()));
|
|
|
+
|
|
|
+ Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
|
|
|
+ try {
|
|
|
+ mv(installation.bundledJdk, relocatedJdk);
|
|
|
+ assertRunsWithJavaHome();
|
|
|
+ } finally {
|
|
|
+ mv(relocatedJdk, installation.bundledJdk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void test60AutoCreateKeystore() {
|
|
|
assumeThat(installation, is(notNullValue()));
|
|
|
|