2020package org .elasticsearch .packaging .test ;
2121
2222import com .carrotsearch .randomizedtesting .annotations .TestCaseOrdering ;
23+ import com .carrotsearch .randomizedtesting .generators .RandomStrings ;
2324import org .apache .http .client .fluent .Request ;
2425import org .elasticsearch .packaging .util .Archives ;
2526import org .elasticsearch .packaging .util .Distribution ;
27+ import org .elasticsearch .packaging .util .FileUtils ;
2628import org .elasticsearch .packaging .util .Installation ;
2729import org .elasticsearch .packaging .util .Platforms ;
2830import org .elasticsearch .packaging .util .ServerUtils ;
2931import org .elasticsearch .packaging .util .Shell ;
3032import org .elasticsearch .packaging .util .Shell .Result ;
3133
32- import java .io .IOException ;
3334import java .nio .charset .StandardCharsets ;
3435import java .nio .file .Files ;
3536import java .nio .file .Path ;
37+ import java .nio .file .Paths ;
3638import java .util .stream .Stream ;
3739
40+ import static com .carrotsearch .randomizedtesting .RandomizedTest .getRandom ;
3841import static org .elasticsearch .packaging .util .Archives .ARCHIVE_OWNER ;
3942import static org .elasticsearch .packaging .util .Archives .installArchive ;
4043import static org .elasticsearch .packaging .util .Archives .verifyArchiveInstallation ;
4952import static org .elasticsearch .packaging .util .FileUtils .rm ;
5053import static org .elasticsearch .packaging .util .ServerUtils .makeRequest ;
5154import static org .hamcrest .CoreMatchers .containsString ;
55+ import static org .hamcrest .CoreMatchers .equalTo ;
5256import static org .hamcrest .CoreMatchers .is ;
5357import static org .hamcrest .CoreMatchers .not ;
5458import static org .hamcrest .CoreMatchers .notNullValue ;
6266@ TestCaseOrdering (TestCaseOrdering .AlphabeticOrder .class )
6367public abstract class ArchiveTestCase extends PackagingTestCase {
6468
65- public void test10Install () {
69+ public void test10Install () throws Exception {
6670 installation = installArchive (distribution ());
6771 verifyArchiveInstallation (installation , distribution ());
6872 }
6973
70- public void test20PluginsListWithNoPlugins () {
74+ public void test20PluginsListWithNoPlugins () throws Exception {
7175 assumeThat (installation , is (notNullValue ()));
7276
7377 final Installation .Executables bin = installation .executables ();
@@ -77,7 +81,7 @@ public void test20PluginsListWithNoPlugins() {
7781 assertThat (r .stdout , isEmptyString ());
7882 }
7983
80- public void test30NoJava () {
84+ public void test30NoJava () throws Exception {
8185 assumeThat (installation , is (notNullValue ()));
8286
8387 final Installation .Executables bin = installation .executables ();
@@ -101,7 +105,7 @@ public void test30NoJava() {
101105 }
102106 }
103107
104- public void test40CreateKeystoreManually () {
108+ public void test40CreateKeystoreManually () throws Exception {
105109 assumeThat (installation , is (notNullValue ()));
106110
107111 final Installation .Executables bin = installation .executables ();
@@ -134,7 +138,7 @@ public void test40CreateKeystoreManually() {
134138 });
135139 }
136140
137- public void test50StartAndStop () throws IOException {
141+ public void test50StartAndStop () throws Exception {
138142 assumeThat (installation , is (notNullValue ()));
139143
140144 // cleanup from previous test
@@ -152,7 +156,7 @@ public void test50StartAndStop() throws IOException {
152156 Archives .stopElasticsearch (installation );
153157 }
154158
155- public void assertRunsWithJavaHome () throws IOException {
159+ public void assertRunsWithJavaHome () throws Exception {
156160 Shell sh = newShell ();
157161
158162 Platforms .onLinux (() -> {
@@ -173,13 +177,13 @@ public void assertRunsWithJavaHome() throws IOException {
173177 assertThat (new String (Files .readAllBytes (log ), StandardCharsets .UTF_8 ), containsString (systemJavaHome ));
174178 }
175179
176- public void test51JavaHomeOverride () throws IOException {
180+ public void test51JavaHomeOverride () throws Exception {
177181 assumeThat (installation , is (notNullValue ()));
178182
179183 assertRunsWithJavaHome ();
180184 }
181185
182- public void test52BundledJdkRemoved () throws IOException {
186+ public void test52BundledJdkRemoved () throws Exception {
183187 assumeThat (installation , is (notNullValue ()));
184188 assumeThat (distribution ().hasJdk , is (true ));
185189
@@ -192,7 +196,63 @@ public void test52BundledJdkRemoved() throws IOException {
192196 }
193197 }
194198
195- public void test60AutoCreateKeystore () {
199+ public void test53JavaHomeWithSpecialCharacters () throws Exception {
200+ assumeThat (installation , is (notNullValue ()));
201+
202+ Platforms .onWindows (() -> {
203+ final Shell sh = new Shell ();
204+ try {
205+ // once windows 2012 is no longer supported and powershell 5.0 is always available we can change this command
206+ sh .run ("cmd /c mklink /D 'C:\\ Program Files (x86)\\ java' $Env:SYSTEM_JAVA_HOME" );
207+
208+ sh .getEnv ().put ("JAVA_HOME" , "C:\\ Program Files (x86)\\ java" );
209+
210+ //verify ES can start, stop and run plugin list
211+ Archives .runElasticsearch (installation , sh );
212+
213+ Archives .stopElasticsearch (installation );
214+
215+ String pluginListCommand = installation .bin + "/elasticsearch-plugin list" ;
216+ Result result = sh .run (pluginListCommand );
217+ assertThat (result .exitCode , equalTo (0 ));
218+
219+ } finally {
220+ //clean up sym link
221+ sh .run ("cmd /c rmdir 'C:\\ Program Files (x86)\\ java' " );
222+ }
223+ });
224+
225+ Platforms .onLinux (() -> {
226+ final Shell sh = new Shell ();
227+ // Create temporary directory with a space and link to java binary.
228+ // Use it as java_home
229+ String nameWithSpace = RandomStrings .randomAsciiAlphanumOfLength (getRandom (), 10 ) + "java home" ;
230+ String test_java_home = FileUtils .mkdir (Paths .get ("/home" ,ARCHIVE_OWNER , nameWithSpace )).toAbsolutePath ().toString ();
231+ try {
232+ final String systemJavaHome = sh .run ("echo $SYSTEM_JAVA_HOME" ).stdout .trim ();
233+ final String java = systemJavaHome + "/bin/java" ;
234+
235+ sh .run ("mkdir -p \" " + test_java_home + "/bin\" " );
236+ sh .run ("ln -s \" " + java + "\" \" " + test_java_home + "/bin/java\" " );
237+ sh .run ("chown -R " + ARCHIVE_OWNER + ":" + ARCHIVE_OWNER + " \" " + test_java_home + "\" " );
238+
239+ sh .getEnv ().put ("JAVA_HOME" , test_java_home );
240+
241+ //verify ES can start, stop and run plugin list
242+ Archives .runElasticsearch (installation , sh );
243+
244+ Archives .stopElasticsearch (installation );
245+
246+ String pluginListCommand = installation .bin + "/elasticsearch-plugin list" ;
247+ Result result = sh .run (pluginListCommand );
248+ assertThat (result .exitCode , equalTo (0 ));
249+ } finally {
250+ FileUtils .rm (Paths .get ("\" " + test_java_home + "\" " ));
251+ }
252+ });
253+ }
254+
255+ public void test60AutoCreateKeystore () throws Exception {
196256 assumeThat (installation , is (notNullValue ()));
197257
198258 assertThat (installation .config ("elasticsearch.keystore" ), file (File , ARCHIVE_OWNER , ARCHIVE_OWNER , p660 ));
@@ -211,7 +271,7 @@ public void test60AutoCreateKeystore() {
211271 });
212272 }
213273
214- public void test70CustomPathConfAndJvmOptions () throws IOException {
274+ public void test70CustomPathConfAndJvmOptions () throws Exception {
215275 assumeThat (installation , is (notNullValue ()));
216276
217277 final Path tempConf = getTempDir ().resolve ("esconf-alternate" );
@@ -260,7 +320,7 @@ public void test70CustomPathConfAndJvmOptions() throws IOException {
260320 }
261321 }
262322
263- public void test80RelativePathConf () throws IOException {
323+ public void test80RelativePathConf () throws Exception {
264324 assumeThat (installation , is (notNullValue ()));
265325
266326 final Path temp = getTempDir ().resolve ("esconf-alternate" );
@@ -304,7 +364,7 @@ public void test80RelativePathConf() throws IOException {
304364 }
305365 }
306366
307- public void test90SecurityCliPackaging () {
367+ public void test90SecurityCliPackaging () throws Exception {
308368 assumeThat (installation , is (notNullValue ()));
309369
310370 final Installation .Executables bin = installation .executables ();
@@ -328,7 +388,7 @@ public void test90SecurityCliPackaging() {
328388 }
329389 }
330390
331- public void test91ElasticsearchShardCliPackaging () {
391+ public void test91ElasticsearchShardCliPackaging () throws Exception {
332392 assumeThat (installation , is (notNullValue ()));
333393
334394 final Installation .Executables bin = installation .executables ();
@@ -345,7 +405,7 @@ public void test91ElasticsearchShardCliPackaging() {
345405 }
346406 }
347407
348- public void test92ElasticsearchNodeCliPackaging () {
408+ public void test92ElasticsearchNodeCliPackaging () throws Exception {
349409 assumeThat (installation , is (notNullValue ()));
350410
351411 final Installation .Executables bin = installation .executables ();
@@ -363,7 +423,7 @@ public void test92ElasticsearchNodeCliPackaging() {
363423 }
364424 }
365425
366- public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir () throws IOException {
426+ public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir () throws Exception {
367427 assumeThat (installation , is (notNullValue ()));
368428
369429 Path relativeDataPath = installation .data .relativize (installation .home );
0 commit comments