@@ -65,7 +65,7 @@ public class ServerProcessTests extends ESTestCase {
65
65
protected final Map <String , String > sysprops = new HashMap <>();
66
66
protected final Map <String , String > envVars = new HashMap <>();
67
67
Path esHomeDir ;
68
- Path workingDir ;
68
+ Path logsDir ;
69
69
Settings .Builder nodeSettings ;
70
70
ProcessValidator processValidator ;
71
71
MainMethod mainCallback ;
@@ -94,8 +94,8 @@ public void resetEnv() {
94
94
sysprops .put ("os.name" , "Linux" );
95
95
sysprops .put ("java.home" , "javahome" );
96
96
sysprops .put ("es.path.home" , esHomeDir .toString ());
97
+ logsDir = esHomeDir .resolve ("logs" );
97
98
envVars .clear ();
98
- workingDir = createTempDir ();
99
99
nodeSettings = Settings .builder ();
100
100
processValidator = null ;
101
101
mainCallback = null ;
@@ -207,15 +207,7 @@ ProcessInfo createProcessInfo() {
207
207
}
208
208
209
209
ServerArgs createServerArgs (boolean daemonize , boolean quiet ) {
210
- return new ServerArgs (
211
- daemonize ,
212
- quiet ,
213
- null ,
214
- secrets ,
215
- nodeSettings .build (),
216
- esHomeDir .resolve ("config" ),
217
- esHomeDir .resolve ("logs" )
218
- );
210
+ return new ServerArgs (daemonize , quiet , null , secrets , nodeSettings .build (), esHomeDir .resolve ("config" ), logsDir );
219
211
}
220
212
221
213
ServerProcess startProcess (boolean daemonize , boolean quiet ) throws Exception {
@@ -231,8 +223,7 @@ ServerProcess startProcess(boolean daemonize, boolean quiet) throws Exception {
231
223
.withProcessInfo (pinfo )
232
224
.withServerArgs (createServerArgs (daemonize , quiet ))
233
225
.withJvmOptions (List .of ())
234
- .withTempDir (ServerProcessUtils .setupTempDir (pinfo ))
235
- .withWorkingDir (workingDir );
226
+ .withTempDir (ServerProcessUtils .setupTempDir (pinfo ));
236
227
return serverProcessBuilder .start (starter );
237
228
}
238
229
@@ -241,7 +232,7 @@ public void testProcessBuilder() throws Exception {
241
232
assertThat (pb .redirectInput (), equalTo (ProcessBuilder .Redirect .PIPE ));
242
233
assertThat (pb .redirectOutput (), equalTo (ProcessBuilder .Redirect .INHERIT ));
243
234
assertThat (pb .redirectError (), equalTo (ProcessBuilder .Redirect .PIPE ));
244
- assertThat (String .valueOf (pb .directory ()), equalTo (workingDir . toString ())); // leave default, which is working directory
235
+ assertThat (String .valueOf (pb .directory ()), equalTo (esHomeDir . resolve ( "logs" ). toString ()));
245
236
};
246
237
mainCallback = (args , stdin , stderr , exitCode ) -> {
247
238
try (PrintStream err = new PrintStream (stderr , true , StandardCharsets .UTF_8 )) {
@@ -315,8 +306,7 @@ public void testCommandLineSysprops() throws Exception {
315
306
.withProcessInfo (createProcessInfo ())
316
307
.withServerArgs (createServerArgs (false , false ))
317
308
.withJvmOptions (List .of ("-Dfoo1=bar" , "-Dfoo2=baz" ))
318
- .withTempDir (Path .of ("." ))
319
- .withWorkingDir (workingDir );
309
+ .withTempDir (Path .of ("." ));
320
310
serverProcessBuilder .start (starter ).waitFor ();
321
311
}
322
312
@@ -433,4 +423,26 @@ public void testProcessDies() throws Exception {
433
423
int exitCode = server .waitFor ();
434
424
assertThat (exitCode , equalTo (-9 ));
435
425
}
426
+
427
+ public void testLogsDirIsFile () throws Exception {
428
+ Files .createFile (logsDir );
429
+ var e = expectThrows (UserException .class , this ::runForeground );
430
+ assertThat (e .getMessage (), containsString ("exists but is not a directory" ));
431
+ }
432
+
433
+ public void testLogsDirCreateParents () throws Exception {
434
+ Path testDir = createTempDir ();
435
+ logsDir = testDir .resolve ("subdir/logs" );
436
+ processValidator = pb -> assertThat (String .valueOf (pb .directory ()), equalTo (logsDir .toString ()));
437
+ runForeground ();
438
+ }
439
+
440
+ public void testLogsCreateFailure () throws Exception {
441
+ Path testDir = createTempDir ();
442
+ Path parentFile = testDir .resolve ("exists" );
443
+ Files .createFile (parentFile );
444
+ logsDir = parentFile .resolve ("logs" );
445
+ var e = expectThrows (UserException .class , this ::runForeground );
446
+ assertThat (e .getMessage (), containsString ("Unable to create logs dir" ));
447
+ }
436
448
}
0 commit comments