@@ -65,7 +65,7 @@ public class ServerProcessTests extends ESTestCase {
6565 protected final Map <String , String > sysprops = new HashMap <>();
6666 protected final Map <String , String > envVars = new HashMap <>();
6767 Path esHomeDir ;
68- Path workingDir ;
68+ Path logsDir ;
6969 Settings .Builder nodeSettings ;
7070 ProcessValidator processValidator ;
7171 MainMethod mainCallback ;
@@ -94,8 +94,8 @@ public void resetEnv() {
9494 sysprops .put ("os.name" , "Linux" );
9595 sysprops .put ("java.home" , "javahome" );
9696 sysprops .put ("es.path.home" , esHomeDir .toString ());
97+ logsDir = esHomeDir .resolve ("logs" );
9798 envVars .clear ();
98- workingDir = createTempDir ();
9999 nodeSettings = Settings .builder ();
100100 processValidator = null ;
101101 mainCallback = null ;
@@ -207,15 +207,7 @@ ProcessInfo createProcessInfo() {
207207 }
208208
209209 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 );
219211 }
220212
221213 ServerProcess startProcess (boolean daemonize , boolean quiet ) throws Exception {
@@ -231,8 +223,7 @@ ServerProcess startProcess(boolean daemonize, boolean quiet) throws Exception {
231223 .withProcessInfo (pinfo )
232224 .withServerArgs (createServerArgs (daemonize , quiet ))
233225 .withJvmOptions (List .of ())
234- .withTempDir (ServerProcessUtils .setupTempDir (pinfo ))
235- .withWorkingDir (workingDir );
226+ .withTempDir (ServerProcessUtils .setupTempDir (pinfo ));
236227 return serverProcessBuilder .start (starter );
237228 }
238229
@@ -241,7 +232,7 @@ public void testProcessBuilder() throws Exception {
241232 assertThat (pb .redirectInput (), equalTo (ProcessBuilder .Redirect .PIPE ));
242233 assertThat (pb .redirectOutput (), equalTo (ProcessBuilder .Redirect .INHERIT ));
243234 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 ()));
245236 };
246237 mainCallback = (args , stdin , stderr , exitCode ) -> {
247238 try (PrintStream err = new PrintStream (stderr , true , StandardCharsets .UTF_8 )) {
@@ -315,8 +306,7 @@ public void testCommandLineSysprops() throws Exception {
315306 .withProcessInfo (createProcessInfo ())
316307 .withServerArgs (createServerArgs (false , false ))
317308 .withJvmOptions (List .of ("-Dfoo1=bar" , "-Dfoo2=baz" ))
318- .withTempDir (Path .of ("." ))
319- .withWorkingDir (workingDir );
309+ .withTempDir (Path .of ("." ));
320310 serverProcessBuilder .start (starter ).waitFor ();
321311 }
322312
@@ -433,4 +423,26 @@ public void testProcessDies() throws Exception {
433423 int exitCode = server .waitFor ();
434424 assertThat (exitCode , equalTo (-9 ));
435425 }
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+ }
436448}
0 commit comments