-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bat scripts to work with JAVA_HOME with parantheses #39712
Changes from 23 commits
fe6435b
ded1387
fe06d04
baa4bec
b3be477
74816f6
5ac3a5e
152cafa
bb72cb4
a7365f8
7ea2662
e64b134
8e140b0
00737f5
ae1ce84
c7c9cb6
e5dc371
1ac4523
0fc3077
c7c03b9
cc7c050
c02fa27
4502319
5e12a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,21 +20,24 @@ | |
package org.elasticsearch.packaging.test; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; | ||
import com.carrotsearch.randomizedtesting.generators.RandomStrings; | ||
import org.apache.http.client.fluent.Request; | ||
import org.elasticsearch.packaging.util.Archives; | ||
import org.elasticsearch.packaging.util.Distribution; | ||
import org.elasticsearch.packaging.util.FileUtils; | ||
import org.elasticsearch.packaging.util.Installation; | ||
import org.elasticsearch.packaging.util.Platforms; | ||
import org.elasticsearch.packaging.util.ServerUtils; | ||
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.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
|
||
import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom; | ||
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; | ||
|
@@ -49,6 +52,7 @@ | |
import static org.elasticsearch.packaging.util.FileUtils.rm; | ||
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
|
@@ -62,12 +66,12 @@ | |
@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class) | ||
public abstract class ArchiveTestCase extends PackagingTestCase { | ||
|
||
public void test10Install() { | ||
public void test10Install() throws Exception { | ||
installation = installArchive(distribution()); | ||
verifyArchiveInstallation(installation, distribution()); | ||
} | ||
|
||
public void test20PluginsListWithNoPlugins() { | ||
public void test20PluginsListWithNoPlugins() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -77,7 +81,7 @@ public void test20PluginsListWithNoPlugins() { | |
assertThat(r.stdout, isEmptyString()); | ||
} | ||
|
||
public void test30NoJava() { | ||
public void test30NoJava() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -101,7 +105,7 @@ public void test30NoJava() { | |
} | ||
} | ||
|
||
public void test40CreateKeystoreManually() { | ||
public void test40CreateKeystoreManually() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -134,7 +138,7 @@ public void test40CreateKeystoreManually() { | |
}); | ||
} | ||
|
||
public void test50StartAndStop() throws IOException { | ||
public void test50StartAndStop() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
// cleanup from previous test | ||
|
@@ -152,7 +156,7 @@ public void test50StartAndStop() throws IOException { | |
Archives.stopElasticsearch(installation); | ||
} | ||
|
||
public void assertRunsWithJavaHome() throws IOException { | ||
public void assertRunsWithJavaHome() throws Exception { | ||
Shell sh = newShell(); | ||
|
||
Platforms.onLinux(() -> { | ||
|
@@ -173,13 +177,13 @@ public void assertRunsWithJavaHome() throws IOException { | |
assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome)); | ||
} | ||
|
||
public void test51JavaHomeOverride() throws IOException { | ||
public void test51JavaHomeOverride() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
assertRunsWithJavaHome(); | ||
} | ||
|
||
public void test52BundledJdkRemoved() throws IOException { | ||
public void test52BundledJdkRemoved() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
assumeThat(distribution().hasJdk, is(true)); | ||
|
||
|
@@ -192,7 +196,63 @@ public void test52BundledJdkRemoved() throws IOException { | |
} | ||
} | ||
|
||
public void test60AutoCreateKeystore() { | ||
public void test53JavaHomeWithSpecialCharacters() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
Platforms.onWindows(() -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we have a similar test in bats, can you add the linux side here as well so we can just remove that test? |
||
final Shell sh = new Shell(); | ||
try { | ||
// once windows 2012 is no longer supported and powershell 5.0 is always available we can change this command | ||
sh.run("cmd /c mklink /D 'C:\\Program Files (x86)\\java' $Env:JAVA_HOME"); | ||
|
||
sh.getEnv().put("JAVA_HOME", "C:\\Program Files (x86)\\java"); | ||
|
||
//verify ES can start, stop and run plugin list | ||
Archives.runElasticsearch(installation, sh); | ||
|
||
Archives.stopElasticsearch(installation); | ||
|
||
String pluginListCommand = installation.bin + "/elasticsearch-plugin list"; | ||
Result result = sh.run(pluginListCommand); | ||
assertThat(result.exitCode, equalTo(0)); | ||
|
||
} finally { | ||
//clean up sym link | ||
sh.runIgnoreExitCode("cmd /c del /F /Q 'C:\\Program Files (x86)\\java' "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to ignore the exit? If this fails, later tests could fail? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actuality I thought that if this fails the rest of the test should continue. JAVA_HOME should not propagate so it won't be visible if failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it fails, something is messed up. I think we should stop testing. |
||
} | ||
}); | ||
|
||
Platforms.onLinux(() -> { | ||
final Shell sh = new Shell(); | ||
// Create temporary directory with a space and link to java binary. | ||
// Use it as java_home | ||
String nameWithSpace = RandomStrings.randomAsciiAlphanumOfLength(getRandom(), 10) + "java home"; | ||
String test_java_home = FileUtils.mkdir(Paths.get("/home",ARCHIVE_OWNER, nameWithSpace)).toAbsolutePath().toString(); | ||
try { | ||
final String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim(); | ||
final String java = systemJavaHome + "/bin/java"; | ||
|
||
sh.run("mkdir -p \"" + test_java_home + "/bin\""); | ||
sh.run("ln -s \"" + java + "\" \"" + test_java_home + "/bin/java\""); | ||
sh.run("chown -R " + ARCHIVE_OWNER + ":" + ARCHIVE_OWNER + " \"" + test_java_home + "\""); | ||
|
||
sh.getEnv().put("JAVA_HOME", test_java_home); | ||
|
||
//verify ES can start, stop and run plugin list | ||
Archives.runElasticsearch(installation, sh); | ||
|
||
Archives.stopElasticsearch(installation); | ||
|
||
String pluginListCommand = installation.bin + "/elasticsearch-plugin list"; | ||
Result result = sh.run(pluginListCommand); | ||
assertThat(result.exitCode, equalTo(0)); | ||
} finally { | ||
FileUtils.rm(Paths.get("\"" + test_java_home + "\"")); | ||
} | ||
}); | ||
} | ||
|
||
public void test60AutoCreateKeystore() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
assertThat(installation.config("elasticsearch.keystore"), file(File, ARCHIVE_OWNER, ARCHIVE_OWNER, p660)); | ||
|
@@ -211,7 +271,7 @@ public void test60AutoCreateKeystore() { | |
}); | ||
} | ||
|
||
public void test70CustomPathConfAndJvmOptions() throws IOException { | ||
public void test70CustomPathConfAndJvmOptions() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Path tempConf = getTempDir().resolve("esconf-alternate"); | ||
|
@@ -260,7 +320,7 @@ public void test70CustomPathConfAndJvmOptions() throws IOException { | |
} | ||
} | ||
|
||
public void test80RelativePathConf() throws IOException { | ||
public void test80RelativePathConf() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Path temp = getTempDir().resolve("esconf-alternate"); | ||
|
@@ -304,7 +364,7 @@ public void test80RelativePathConf() throws IOException { | |
} | ||
} | ||
|
||
public void test90SecurityCliPackaging() { | ||
public void test90SecurityCliPackaging() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -328,7 +388,7 @@ public void test90SecurityCliPackaging() { | |
} | ||
} | ||
|
||
public void test91ElasticsearchShardCliPackaging() { | ||
public void test91ElasticsearchShardCliPackaging() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -345,7 +405,7 @@ public void test91ElasticsearchShardCliPackaging() { | |
} | ||
} | ||
|
||
public void test92ElasticsearchNodeCliPackaging() { | ||
public void test92ElasticsearchNodeCliPackaging() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
final Installation.Executables bin = installation.executables(); | ||
|
@@ -363,7 +423,7 @@ public void test92ElasticsearchNodeCliPackaging() { | |
} | ||
} | ||
|
||
public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws IOException { | ||
public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws Exception { | ||
assumeThat(installation, is(notNullValue())); | ||
|
||
Path relativeDataPath = installation.data.relativize(installation.home); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed this offline: at first glance I had thought this was modifying the deprecated for loop that searches the path for java. Now I see this is a different loop (although I am confused why we need a loop at all: TempDirectory only prints one line). I believe this entire PR can be moved back to basing on master.