-
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
Merged
pgomulka
merged 24 commits into
elastic:master
from
pgomulka:feature/windows_startup_scripts
Apr 2, 2019
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fe6435b
Bat scripts to work with JAVA_HOME with parantheses
pgomulka ded1387
Merge remote-tracking branch 'upstream/master' into feature/windows_s…
pgomulka fe06d04
refactor run method
pgomulka baa4bec
Linux version of java with spaces
pgomulka b3be477
compile fix
pgomulka 74816f6
fix temp path
pgomulka 5ac3a5e
Merge branch 'master' into feature/windows_startup_scripts
pgomulka 152cafa
minor cleanup
pgomulka bb72cb4
not looking into PATH at all
pgomulka a7365f8
compile error
pgomulka 7ea2662
compile errors
pgomulka e64b134
fix the linux version of the test
pgomulka 8e140b0
Merge branch 'master' into feature/windows_startup_scripts
pgomulka 00737f5
fix linux test
pgomulka ae1ce84
fixing failing tests
pgomulka c7c9cb6
permissions for tmp file
pgomulka e5dc371
chown temp file
pgomulka 1ac4523
Merge remote-tracking branch 'upstream/master' into feature/windows_s…
pgomulka 0fc3077
compile error
pgomulka c7c03b9
code review follow up
pgomulka cc7c050
remove random tmp creation
pgomulka c02fa27
refactor tmp creation to regular direcotry
pgomulka 4502319
fix cleanup
pgomulka 5e12a34
don't ignore cleanup failure
pgomulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.run("cmd /c del /F /Q 'C:\\Program Files (x86)\\java' "); | ||
} | ||
}); | ||
|
||
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.