Bat scripts to work with JAVA_HOME with parentheses Backports (#40832)

backports :
Bat scripts to work with JAVA_HOME with parentheses (#39712)
Link to SYSTEM_JAVA_HOME on windows (#40806)
This commit is contained in:
Przemyslaw Gomulka 2019-04-04 18:42:05 +02:00 committed by GitHub
parent fb5a0652a8
commit 65d25186d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 126 additions and 72 deletions

View File

@ -65,5 +65,5 @@ rem check the Java version
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1 %JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
if not defined ES_TMPDIR ( if not defined ES_TMPDIR (
for /f "tokens=* usebackq" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory""`) do set ES_TMPDIR=%%a for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory"`) do set ES_TMPDIR=%%a
) )

View File

@ -41,9 +41,9 @@ IF ERRORLEVEL 1 (
EXIT /B %ERRORLEVEL% EXIT /B %ERRORLEVEL%
) )
set "ES_JVM_OPTIONS=%ES_PATH_CONF%\jvm.options" set ES_JVM_OPTIONS=%ES_PATH_CONF%\jvm.options
@setlocal @setlocal
for /F "usebackq delims=" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" || echo jvm_options_parser_failed"`) do set JVM_OPTIONS=%%a for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" ^|^| echo jvm_options_parser_failed`) do set JVM_OPTIONS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%JVM_OPTIONS%" & set ES_JAVA_OPTS=%JVM_OPTIONS:${ES_TMPDIR}=!ES_TMPDIR!% %ES_JAVA_OPTS% @endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%JVM_OPTIONS%" & set ES_JAVA_OPTS=%JVM_OPTIONS:${ES_TMPDIR}=!ES_TMPDIR!% %ES_JAVA_OPTS%
if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" ( if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (

View File

@ -20,21 +20,24 @@
package org.elasticsearch.packaging.test; package org.elasticsearch.packaging.test;
import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering;
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Request;
import org.elasticsearch.packaging.util.Archives; import org.elasticsearch.packaging.util.Archives;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.FileUtils;
import org.elasticsearch.packaging.util.Installation; import org.elasticsearch.packaging.util.Installation;
import org.elasticsearch.packaging.util.Platforms; import org.elasticsearch.packaging.util.Platforms;
import org.elasticsearch.packaging.util.ServerUtils; import org.elasticsearch.packaging.util.ServerUtils;
import org.elasticsearch.packaging.util.Shell; import org.elasticsearch.packaging.util.Shell;
import org.elasticsearch.packaging.util.Shell.Result; import org.elasticsearch.packaging.util.Shell.Result;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream; 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.ARCHIVE_OWNER;
import static org.elasticsearch.packaging.util.Archives.installArchive; import static org.elasticsearch.packaging.util.Archives.installArchive;
import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation; import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation;
@ -49,6 +52,7 @@ import static org.elasticsearch.packaging.util.FileUtils.mv;
import static org.elasticsearch.packaging.util.FileUtils.rm; import static org.elasticsearch.packaging.util.FileUtils.rm;
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest; import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
@ -62,12 +66,12 @@ import static org.junit.Assume.assumeThat;
@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class) @TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class)
public abstract class ArchiveTestCase extends PackagingTestCase { public abstract class ArchiveTestCase extends PackagingTestCase {
public void test10Install() { public void test10Install() throws Exception {
installation = installArchive(distribution()); installation = installArchive(distribution());
verifyArchiveInstallation(installation, distribution()); verifyArchiveInstallation(installation, distribution());
} }
public void test20PluginsListWithNoPlugins() { public void test20PluginsListWithNoPlugins() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -77,7 +81,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assertThat(r.stdout, isEmptyString()); assertThat(r.stdout, isEmptyString());
} }
public void test30NoJava() { public void test30NoJava() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -101,7 +105,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test40CreateKeystoreManually() { public void test40CreateKeystoreManually() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -134,7 +138,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
}); });
} }
public void test50StartAndStop() throws IOException { public void test50StartAndStop() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
// cleanup from previous test // cleanup from previous test
@ -152,7 +156,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
Archives.stopElasticsearch(installation); Archives.stopElasticsearch(installation);
} }
public void assertRunsWithJavaHome() throws IOException { public void assertRunsWithJavaHome() throws Exception {
Shell sh = newShell(); Shell sh = newShell();
Platforms.onLinux(() -> { Platforms.onLinux(() -> {
@ -173,13 +177,13 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome)); 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())); assumeThat(installation, is(notNullValue()));
assertRunsWithJavaHome(); assertRunsWithJavaHome();
} }
public void test52BundledJdkRemoved() throws IOException { public void test52BundledJdkRemoved() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
assumeThat(distribution().hasJdk, is(true)); assumeThat(distribution().hasJdk, is(true));
@ -192,7 +196,63 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test60AutoCreateKeystore() { public void test53JavaHomeWithSpecialCharacters() throws Exception {
assumeThat(installation, is(notNullValue()));
Platforms.onWindows(() -> {
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:SYSTEM_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 rmdir '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())); assumeThat(installation, is(notNullValue()));
assertThat(installation.config("elasticsearch.keystore"), file(File, ARCHIVE_OWNER, ARCHIVE_OWNER, p660)); assertThat(installation.config("elasticsearch.keystore"), file(File, ARCHIVE_OWNER, ARCHIVE_OWNER, p660));
@ -211,7 +271,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
}); });
} }
public void test70CustomPathConfAndJvmOptions() throws IOException { public void test70CustomPathConfAndJvmOptions() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Path tempConf = getTempDir().resolve("esconf-alternate"); final Path tempConf = getTempDir().resolve("esconf-alternate");
@ -260,7 +320,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test80RelativePathConf() throws IOException { public void test80RelativePathConf() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Path temp = getTempDir().resolve("esconf-alternate"); final Path temp = getTempDir().resolve("esconf-alternate");
@ -304,7 +364,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test90SecurityCliPackaging() { public void test90SecurityCliPackaging() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -328,7 +388,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test91ElasticsearchShardCliPackaging() { public void test91ElasticsearchShardCliPackaging() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -345,7 +405,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test92ElasticsearchNodeCliPackaging() { public void test92ElasticsearchNodeCliPackaging() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -363,7 +423,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
} }
} }
public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws IOException { public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
Path relativeDataPath = installation.data.relativize(installation.home); Path relativeDataPath = installation.data.relativize(installation.home);

View File

@ -26,7 +26,6 @@ import org.elasticsearch.packaging.util.Shell;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -54,7 +53,7 @@ public abstract class DebPreservationTestCase extends PackagingTestCase {
protected abstract Distribution distribution(); protected abstract Distribution distribution();
@BeforeClass @BeforeClass
public static void cleanup() { public static void cleanup() throws Exception {
installation = null; installation = null;
cleanEverything(); cleanEverything();
} }
@ -65,14 +64,14 @@ public abstract class DebPreservationTestCase extends PackagingTestCase {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
} }
public void test10Install() throws IOException { public void test10Install() throws Exception {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution(), newShell()); verifyPackageInstallation(installation, distribution(), newShell());
} }
public void test20Remove() { public void test20Remove() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
remove(distribution()); remove(distribution());
@ -117,7 +116,7 @@ public abstract class DebPreservationTestCase extends PackagingTestCase {
assertTrue(Files.exists(installation.envFile)); assertTrue(Files.exists(installation.envFile));
} }
public void test30Purge() { public void test30Purge() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Shell sh = new Shell(); final Shell sh = new Shell();

View File

@ -20,6 +20,7 @@
package org.elasticsearch.packaging.test; package org.elasticsearch.packaging.test;
import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering;
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Request;
import org.elasticsearch.packaging.util.FileUtils; import org.elasticsearch.packaging.util.FileUtils;
import org.elasticsearch.packaging.util.Shell; import org.elasticsearch.packaging.util.Shell;
@ -27,7 +28,6 @@ import org.elasticsearch.packaging.util.Shell.Result;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import org.junit.Before; import org.junit.Before;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -36,6 +36,7 @@ import java.nio.file.StandardOpenOption;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom;
import static org.elasticsearch.packaging.util.FileUtils.append; import static org.elasticsearch.packaging.util.FileUtils.append;
import static org.elasticsearch.packaging.util.FileUtils.assertPathsDontExist; import static org.elasticsearch.packaging.util.FileUtils.assertPathsDontExist;
import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist; import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist;
@ -72,19 +73,19 @@ public abstract class PackageTestCase extends PackagingTestCase {
private Shell sh; private Shell sh;
@Before @Before
public void onlyCompatibleDistributions() { public void onlyCompatibleDistributions() throws Exception {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
sh = newShell(); sh = newShell();
} }
public void test10InstallPackage() throws IOException { public void test10InstallPackage() throws Exception {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution(), sh); verifyPackageInstallation(installation, distribution(), sh);
} }
public void test20PluginsCommandWhenNoPlugins() { public void test20PluginsCommandWhenNoPlugins() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
assertThat(sh.run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString()); assertThat(sh.run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString());
@ -104,7 +105,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch"))); assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
} }
public void assertRunsWithJavaHome() throws IOException { public void assertRunsWithJavaHome() throws Exception {
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim(); String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
byte[] originalEnvFile = Files.readAllBytes(installation.envFile); byte[] originalEnvFile = Files.readAllBytes(installation.envFile);
try { try {
@ -121,7 +122,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome)); assertThat(new String(Files.readAllBytes(log), StandardCharsets.UTF_8), containsString(systemJavaHome));
} }
public void test32JavaHomeOverride() throws IOException { public void test32JavaHomeOverride() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
// we always run with java home when no bundled jdk is included, so this test would be repetitive // we always run with java home when no bundled jdk is included, so this test would be repetitive
assumeThat(distribution().hasJdk, is(true)); assumeThat(distribution().hasJdk, is(true));
@ -129,7 +130,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertRunsWithJavaHome(); assertRunsWithJavaHome();
} }
public void test42BundledJdkRemoved() throws IOException { public void test42BundledJdkRemoved() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
assumeThat(distribution().hasJdk, is(true)); assumeThat(distribution().hasJdk, is(true));
@ -142,7 +143,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
} }
} }
public void test40StartServer() throws IOException { public void test40StartServer() throws Exception {
String start = sh.runIgnoreExitCode("date ").stdout.trim(); String start = sh.runIgnoreExitCode("date ").stdout.trim();
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
@ -160,7 +161,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
verifyPackageInstallation(installation, distribution(), sh); // check startup script didn't change permissions verifyPackageInstallation(installation, distribution(), sh); // check startup script didn't change permissions
} }
public void test50Remove() { public void test50Remove() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
remove(distribution()); remove(distribution());
@ -210,7 +211,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertFalse(Files.exists(SYSTEMD_SERVICE)); assertFalse(Files.exists(SYSTEMD_SERVICE));
} }
public void test60Reinstall() throws IOException { public void test60Reinstall() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
installation = install(distribution()); installation = install(distribution());
@ -221,7 +222,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertRemoved(distribution()); assertRemoved(distribution());
} }
public void test70RestartServer() throws IOException { public void test70RestartServer() throws Exception {
try { try {
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
@ -236,7 +237,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
} }
public void test72TestRuntimeDirectory() throws IOException { public void test72TestRuntimeDirectory() throws Exception {
try { try {
installation = install(distribution()); installation = install(distribution());
FileUtils.rm(installation.pidDir); FileUtils.rm(installation.pidDir);
@ -248,7 +249,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
} }
} }
public void test73gcLogsExist() throws IOException { public void test73gcLogsExist() throws Exception {
installation = install(distribution()); installation = install(distribution());
startElasticsearch(sh); startElasticsearch(sh);
// it can be gc.log or gc.log.0.current // it can be gc.log or gc.log.0.current
@ -265,7 +266,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
* # but it should not block ES from starting * # but it should not block ES from starting
* # see https://github.com/elastic/elasticsearch/issues/11594 * # see https://github.com/elastic/elasticsearch/issues/11594
*/ */
public void test80DeletePID_DIRandRestart() throws IOException { public void test80DeletePID_DIRandRestart() throws Exception {
assumeTrue(isSystemd()); assumeTrue(isSystemd());
rm(installation.pidDir); rm(installation.pidDir);
@ -281,7 +282,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
stopElasticsearch(sh); stopElasticsearch(sh);
} }
public void test81CustomPathConfAndJvmOptions() throws IOException { public void test81CustomPathConfAndJvmOptions() throws Exception {
assumeTrue(isSystemd()); assumeTrue(isSystemd());
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
@ -292,8 +293,9 @@ public abstract class PackageTestCase extends PackagingTestCase {
// The custom config directory is not under /tmp or /var/tmp because // The custom config directory is not under /tmp or /var/tmp because
// systemd's private temp directory functionally means different // systemd's private temp directory functionally means different
// processes can have different views of what's in these directories // processes can have different views of what's in these directories
String temp = sh.runIgnoreExitCode("mktemp -p /etc -d").stdout.trim(); String randomName = RandomStrings.randomAsciiAlphanumOfLength(getRandom(), 10);
final Path tempConf = Paths.get(temp); sh.run("mkdir /etc/"+randomName);
final Path tempConf = Paths.get("/etc/"+randomName);
try { try {
mkdir(tempConf); mkdir(tempConf);
@ -332,7 +334,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
} }
} }
public void test82SystemdMask() throws IOException { public void test82SystemdMask() throws Exception {
try { try {
assumeTrue(isSystemd()); assumeTrue(isSystemd());
@ -346,7 +348,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
} }
} }
public void test83serviceFileSetsLimits() throws IOException { public void test83serviceFileSetsLimits() throws Exception {
// Limits are changed on systemd platforms only // Limits are changed on systemd platforms only
assumeTrue(isSystemd()); assumeTrue(isSystemd());

View File

@ -64,7 +64,7 @@ public abstract class PackagingTestCase extends Assert {
protected static Installation installation; protected static Installation installation;
@BeforeClass @BeforeClass
public static void cleanup() { public static void cleanup() throws Exception {
installation = null; installation = null;
cleanEverything(); cleanEverything();
} }
@ -72,7 +72,7 @@ public abstract class PackagingTestCase extends Assert {
/** The {@link Distribution} that should be tested in this case */ /** The {@link Distribution} that should be tested in this case */
protected abstract Distribution distribution(); protected abstract Distribution distribution();
protected Shell newShell() { protected Shell newShell() throws Exception {
Shell sh = new Shell(); Shell sh = new Shell();
if (distribution().hasJdk == false) { if (distribution().hasJdk == false) {
Platforms.onLinux(() -> { Platforms.onLinux(() -> {

View File

@ -26,7 +26,6 @@ import org.elasticsearch.packaging.util.Shell;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -56,7 +55,7 @@ public abstract class RpmPreservationTestCase extends PackagingTestCase {
protected abstract Distribution distribution(); protected abstract Distribution distribution();
@BeforeClass @BeforeClass
public static void cleanup() { public static void cleanup() throws Exception {
installation = null; installation = null;
cleanEverything(); cleanEverything();
} }
@ -67,14 +66,14 @@ public abstract class RpmPreservationTestCase extends PackagingTestCase {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
} }
public void test10Install() throws IOException { public void test10Install() throws Exception {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution(), newShell()); verifyPackageInstallation(installation, distribution(), newShell());
} }
public void test20Remove() { public void test20Remove() throws Exception {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
remove(distribution()); remove(distribution());
@ -89,7 +88,7 @@ public abstract class RpmPreservationTestCase extends PackagingTestCase {
assertFalse(Files.exists(installation.envFile)); assertFalse(Files.exists(installation.envFile));
} }
public void test30PreserveConfig() throws IOException { public void test30PreserveConfig() throws Exception {
final Shell sh = new Shell(); final Shell sh = new Shell();
installation = install(distribution()); installation = install(distribution());

View File

@ -102,7 +102,7 @@ public abstract class WindowsServiceTestCase extends PackagingTestCase {
} }
} }
public void test10InstallArchive() { public void test10InstallArchive() throws Exception {
installation = installArchive(distribution()); installation = installArchive(distribution());
verifyArchiveInstallation(installation, distribution()); verifyArchiveInstallation(installation, distribution());
serviceScript = installation.bin("elasticsearch-service.bat").toString(); serviceScript = installation.bin("elasticsearch-service.bat").toString();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.packaging.util; package org.elasticsearch.packaging.util;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -37,15 +36,14 @@ import static org.elasticsearch.packaging.util.FileUtils.getCurrentVersion;
import static org.elasticsearch.packaging.util.FileUtils.getDefaultArchiveInstallPath; import static org.elasticsearch.packaging.util.FileUtils.getDefaultArchiveInstallPath;
import static org.elasticsearch.packaging.util.FileUtils.getDistributionFile; import static org.elasticsearch.packaging.util.FileUtils.getDistributionFile;
import static org.elasticsearch.packaging.util.FileUtils.lsGlob; import static org.elasticsearch.packaging.util.FileUtils.lsGlob;
import static org.elasticsearch.packaging.util.FileUtils.mv; import static org.elasticsearch.packaging.util.FileUtils.mv;
import static org.elasticsearch.packaging.util.FileUtils.slurp; import static org.elasticsearch.packaging.util.FileUtils.slurp;
import static org.elasticsearch.packaging.util.Platforms.isDPKG; import static org.elasticsearch.packaging.util.Platforms.isDPKG;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -59,11 +57,11 @@ public class Archives {
? "vagrant" ? "vagrant"
: "elasticsearch"; : "elasticsearch";
public static Installation installArchive(Distribution distribution) { public static Installation installArchive(Distribution distribution) throws Exception {
return installArchive(distribution, getDefaultArchiveInstallPath(), getCurrentVersion()); return installArchive(distribution, getDefaultArchiveInstallPath(), getCurrentVersion());
} }
public static Installation installArchive(Distribution distribution, Path fullInstallPath, String version) { public static Installation installArchive(Distribution distribution, Path fullInstallPath, String version) throws Exception {
final Shell sh = new Shell(); final Shell sh = new Shell();
final Path distributionFile = getDistributionFile(distribution); final Path distributionFile = getDistributionFile(distribution);
@ -255,11 +253,7 @@ public class Archives {
).forEach(configFile -> assertThat(es.config(configFile), file(File, owner, owner, p660))); ).forEach(configFile -> assertThat(es.config(configFile), file(File, owner, owner, p660)));
} }
public static void runElasticsearch(Installation installation) throws IOException { public static void runElasticsearch(Installation installation, Shell sh) throws Exception {
runElasticsearch(installation, new Shell());
}
public static void runElasticsearch(Installation installation, Shell sh) throws IOException {
final Path pidFile = installation.home.resolve("elasticsearch.pid"); final Path pidFile = installation.home.resolve("elasticsearch.pid");
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
@ -309,7 +303,7 @@ public class Archives {
Platforms.onWindows(() -> sh.run("Get-Process -Id " + pid)); Platforms.onWindows(() -> sh.run("Get-Process -Id " + pid));
} }
public static void stopElasticsearch(Installation installation) { public static void stopElasticsearch(Installation installation) throws Exception {
Path pidFile = installation.home.resolve("elasticsearch.pid"); Path pidFile = installation.home.resolve("elasticsearch.pid");
assertTrue(Files.exists(pidFile)); assertTrue(Files.exists(pidFile));
String pid = slurp(pidFile).trim(); String pid = slurp(pidFile).trim();

View File

@ -50,7 +50,7 @@ public class Cleanup {
// todo // todo
private static final List<String> ELASTICSEARCH_FILES_WINDOWS = Collections.emptyList(); private static final List<String> ELASTICSEARCH_FILES_WINDOWS = Collections.emptyList();
public static void cleanEverything() { public static void cleanEverything() throws Exception {
final Shell sh = new Shell(); final Shell sh = new Shell();
// kill elasticsearch processes // kill elasticsearch processes

View File

@ -54,14 +54,14 @@ public class Packages {
public static final Path SYSVINIT_SCRIPT = Paths.get("/etc/init.d/elasticsearch"); public static final Path SYSVINIT_SCRIPT = Paths.get("/etc/init.d/elasticsearch");
public static final Path SYSTEMD_SERVICE = Paths.get("/usr/lib/systemd/system/elasticsearch.service"); public static final Path SYSTEMD_SERVICE = Paths.get("/usr/lib/systemd/system/elasticsearch.service");
public static void assertInstalled(Distribution distribution) { public static void assertInstalled(Distribution distribution) throws Exception {
final Result status = packageStatus(distribution); final Result status = packageStatus(distribution);
assertThat(status.exitCode, is(0)); assertThat(status.exitCode, is(0));
Platforms.onDPKG(() -> assertFalse(Pattern.compile("(?m)^Status:.+deinstall ok").matcher(status.stdout).find())); Platforms.onDPKG(() -> assertFalse(Pattern.compile("(?m)^Status:.+deinstall ok").matcher(status.stdout).find()));
} }
public static void assertRemoved(Distribution distribution) { public static void assertRemoved(Distribution distribution) throws Exception {
final Result status = packageStatus(distribution); final Result status = packageStatus(distribution);
Platforms.onRPM(() -> assertThat(status.exitCode, is(1))); Platforms.onRPM(() -> assertThat(status.exitCode, is(1)));
@ -133,7 +133,7 @@ public class Packages {
} }
} }
public static void remove(Distribution distribution) { public static void remove(Distribution distribution) throws Exception {
final Shell sh = new Shell(); final Shell sh = new Shell();
Platforms.onRPM(() -> { Platforms.onRPM(() -> {

View File

@ -65,25 +65,25 @@ public class Platforms {
return new Shell().runIgnoreExitCode("which service").isSuccess(); return new Shell().runIgnoreExitCode("which service").isSuccess();
} }
public static void onWindows(PlatformAction action) { public static void onWindows(PlatformAction action) throws Exception {
if (WINDOWS) { if (WINDOWS) {
action.run(); action.run();
} }
} }
public static void onLinux(PlatformAction action) { public static void onLinux(PlatformAction action) throws Exception {
if (LINUX) { if (LINUX) {
action.run(); action.run();
} }
} }
public static void onRPM(PlatformAction action) { public static void onRPM(PlatformAction action) throws Exception {
if (isRPM()) { if (isRPM()) {
action.run(); action.run();
} }
} }
public static void onDPKG(PlatformAction action) { public static void onDPKG(PlatformAction action) throws Exception {
if (isDPKG()) { if (isDPKG()) {
action.run(); action.run();
} }
@ -94,6 +94,6 @@ public class Platforms {
*/ */
@FunctionalInterface @FunctionalInterface
public interface PlatformAction { public interface PlatformAction {
void run(); void run() throws Exception;
} }
} }