20
20
package org .elasticsearch .packaging .test ;
21
21
22
22
import com .carrotsearch .randomizedtesting .annotations .TestCaseOrdering ;
23
+ import com .carrotsearch .randomizedtesting .generators .RandomStrings ;
23
24
import org .apache .http .client .fluent .Request ;
24
25
import org .elasticsearch .packaging .util .Archives ;
25
26
import org .elasticsearch .packaging .util .Distribution ;
27
+ import org .elasticsearch .packaging .util .FileUtils ;
26
28
import org .elasticsearch .packaging .util .Installation ;
27
29
import org .elasticsearch .packaging .util .Platforms ;
28
30
import org .elasticsearch .packaging .util .ServerUtils ;
29
31
import org .elasticsearch .packaging .util .Shell ;
30
32
import org .elasticsearch .packaging .util .Shell .Result ;
31
33
32
- import java .io .IOException ;
33
34
import java .nio .charset .StandardCharsets ;
34
35
import java .nio .file .Files ;
35
36
import java .nio .file .Path ;
37
+ import java .nio .file .Paths ;
36
38
import java .util .stream .Stream ;
37
39
40
+ import static com .carrotsearch .randomizedtesting .RandomizedTest .getRandom ;
38
41
import static org .elasticsearch .packaging .util .Archives .ARCHIVE_OWNER ;
39
42
import static org .elasticsearch .packaging .util .Archives .installArchive ;
40
43
import static org .elasticsearch .packaging .util .Archives .verifyArchiveInstallation ;
49
52
import static org .elasticsearch .packaging .util .FileUtils .rm ;
50
53
import static org .elasticsearch .packaging .util .ServerUtils .makeRequest ;
51
54
import static org .hamcrest .CoreMatchers .containsString ;
55
+ import static org .hamcrest .CoreMatchers .equalTo ;
52
56
import static org .hamcrest .CoreMatchers .is ;
53
57
import static org .hamcrest .CoreMatchers .not ;
54
58
import static org .hamcrest .CoreMatchers .notNullValue ;
62
66
@ TestCaseOrdering (TestCaseOrdering .AlphabeticOrder .class )
63
67
public abstract class ArchiveTestCase extends PackagingTestCase {
64
68
65
- public void test10Install () {
69
+ public void test10Install () throws Exception {
66
70
installation = installArchive (distribution ());
67
71
verifyArchiveInstallation (installation , distribution ());
68
72
}
69
73
70
- public void test20PluginsListWithNoPlugins () {
74
+ public void test20PluginsListWithNoPlugins () throws Exception {
71
75
assumeThat (installation , is (notNullValue ()));
72
76
73
77
final Installation .Executables bin = installation .executables ();
@@ -77,7 +81,7 @@ public void test20PluginsListWithNoPlugins() {
77
81
assertThat (r .stdout , isEmptyString ());
78
82
}
79
83
80
- public void test30NoJava () {
84
+ public void test30NoJava () throws Exception {
81
85
assumeThat (installation , is (notNullValue ()));
82
86
83
87
final Installation .Executables bin = installation .executables ();
@@ -101,7 +105,7 @@ public void test30NoJava() {
101
105
}
102
106
}
103
107
104
- public void test40CreateKeystoreManually () {
108
+ public void test40CreateKeystoreManually () throws Exception {
105
109
assumeThat (installation , is (notNullValue ()));
106
110
107
111
final Installation .Executables bin = installation .executables ();
@@ -134,7 +138,7 @@ public void test40CreateKeystoreManually() {
134
138
});
135
139
}
136
140
137
- public void test50StartAndStop () throws IOException {
141
+ public void test50StartAndStop () throws Exception {
138
142
assumeThat (installation , is (notNullValue ()));
139
143
140
144
// cleanup from previous test
@@ -152,7 +156,7 @@ public void test50StartAndStop() throws IOException {
152
156
Archives .stopElasticsearch (installation );
153
157
}
154
158
155
- public void assertRunsWithJavaHome () throws IOException {
159
+ public void assertRunsWithJavaHome () throws Exception {
156
160
Shell sh = newShell ();
157
161
158
162
Platforms .onLinux (() -> {
@@ -173,13 +177,13 @@ public void assertRunsWithJavaHome() throws IOException {
173
177
assertThat (new String (Files .readAllBytes (log ), StandardCharsets .UTF_8 ), containsString (systemJavaHome ));
174
178
}
175
179
176
- public void test51JavaHomeOverride () throws IOException {
180
+ public void test51JavaHomeOverride () throws Exception {
177
181
assumeThat (installation , is (notNullValue ()));
178
182
179
183
assertRunsWithJavaHome ();
180
184
}
181
185
182
- public void test52BundledJdkRemoved () throws IOException {
186
+ public void test52BundledJdkRemoved () throws Exception {
183
187
assumeThat (installation , is (notNullValue ()));
184
188
assumeThat (distribution ().hasJdk , is (true ));
185
189
@@ -192,7 +196,63 @@ public void test52BundledJdkRemoved() throws IOException {
192
196
}
193
197
}
194
198
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 {
196
256
assumeThat (installation , is (notNullValue ()));
197
257
198
258
assertThat (installation .config ("elasticsearch.keystore" ), file (File , ARCHIVE_OWNER , ARCHIVE_OWNER , p660 ));
@@ -211,7 +271,7 @@ public void test60AutoCreateKeystore() {
211
271
});
212
272
}
213
273
214
- public void test70CustomPathConfAndJvmOptions () throws IOException {
274
+ public void test70CustomPathConfAndJvmOptions () throws Exception {
215
275
assumeThat (installation , is (notNullValue ()));
216
276
217
277
final Path tempConf = getTempDir ().resolve ("esconf-alternate" );
@@ -260,7 +320,7 @@ public void test70CustomPathConfAndJvmOptions() throws IOException {
260
320
}
261
321
}
262
322
263
- public void test80RelativePathConf () throws IOException {
323
+ public void test80RelativePathConf () throws Exception {
264
324
assumeThat (installation , is (notNullValue ()));
265
325
266
326
final Path temp = getTempDir ().resolve ("esconf-alternate" );
@@ -304,7 +364,7 @@ public void test80RelativePathConf() throws IOException {
304
364
}
305
365
}
306
366
307
- public void test90SecurityCliPackaging () {
367
+ public void test90SecurityCliPackaging () throws Exception {
308
368
assumeThat (installation , is (notNullValue ()));
309
369
310
370
final Installation .Executables bin = installation .executables ();
@@ -328,7 +388,7 @@ public void test90SecurityCliPackaging() {
328
388
}
329
389
}
330
390
331
- public void test91ElasticsearchShardCliPackaging () {
391
+ public void test91ElasticsearchShardCliPackaging () throws Exception {
332
392
assumeThat (installation , is (notNullValue ()));
333
393
334
394
final Installation .Executables bin = installation .executables ();
@@ -345,7 +405,7 @@ public void test91ElasticsearchShardCliPackaging() {
345
405
}
346
406
}
347
407
348
- public void test92ElasticsearchNodeCliPackaging () {
408
+ public void test92ElasticsearchNodeCliPackaging () throws Exception {
349
409
assumeThat (installation , is (notNullValue ()));
350
410
351
411
final Installation .Executables bin = installation .executables ();
@@ -363,7 +423,7 @@ public void test92ElasticsearchNodeCliPackaging() {
363
423
}
364
424
}
365
425
366
- public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir () throws IOException {
426
+ public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir () throws Exception {
367
427
assumeThat (installation , is (notNullValue ()));
368
428
369
429
Path relativeDataPath = installation .data .relativize (installation .home );
0 commit comments