|
20 | 20 | import org.elasticsearch.common.settings.SecureSettings; |
21 | 21 | import org.elasticsearch.common.settings.Settings; |
22 | 22 | import org.elasticsearch.core.IOUtils; |
| 23 | +import org.elasticsearch.env.Environment; |
23 | 24 | import org.elasticsearch.test.ESTestCase; |
24 | 25 | import org.junit.AfterClass; |
25 | 26 | import org.junit.Before; |
|
32 | 33 | import java.io.PrintStream; |
33 | 34 | import java.io.UncheckedIOException; |
34 | 35 | import java.nio.charset.StandardCharsets; |
| 36 | +import java.nio.file.FileAlreadyExistsException; |
35 | 37 | import java.nio.file.Files; |
36 | 38 | import java.nio.file.Path; |
37 | 39 | import java.nio.file.Paths; |
@@ -65,6 +67,7 @@ public class ServerProcessTests extends ESTestCase { |
65 | 67 | protected final Map<String, String> sysprops = new HashMap<>(); |
66 | 68 | protected final Map<String, String> envVars = new HashMap<>(); |
67 | 69 | Path esHomeDir; |
| 70 | + Path logsDir; |
68 | 71 | Settings.Builder nodeSettings; |
69 | 72 | ProcessValidator processValidator; |
70 | 73 | MainMethod mainCallback; |
@@ -93,6 +96,7 @@ public void resetEnv() { |
93 | 96 | sysprops.put("os.name", "Linux"); |
94 | 97 | sysprops.put("java.home", "javahome"); |
95 | 98 | sysprops.put("es.path.home", esHomeDir.toString()); |
| 99 | + logsDir = esHomeDir.resolve("logs"); |
96 | 100 | envVars.clear(); |
97 | 101 | nodeSettings = Settings.builder(); |
98 | 102 | processValidator = null; |
@@ -212,7 +216,7 @@ ServerArgs createServerArgs(boolean daemonize, boolean quiet) { |
212 | 216 | secrets, |
213 | 217 | nodeSettings.build(), |
214 | 218 | esHomeDir.resolve("config"), |
215 | | - esHomeDir.resolve("logs") |
| 219 | + logsDir |
216 | 220 | ); |
217 | 221 | } |
218 | 222 |
|
@@ -429,4 +433,26 @@ public void testProcessDies() throws Exception { |
429 | 433 | int exitCode = server.waitFor(); |
430 | 434 | assertThat(exitCode, equalTo(-9)); |
431 | 435 | } |
| 436 | + |
| 437 | + public void testLogsDirIsFile() throws Exception { |
| 438 | + Files.createFile(logsDir); |
| 439 | + var e = expectThrows(UserException.class, this::runForeground); |
| 440 | + assertThat(e.getMessage(), containsString("exists but is not a directory")); |
| 441 | + } |
| 442 | + |
| 443 | + public void testLogsDirCreateParents() throws Exception { |
| 444 | + Path testDir = createTempDir(); |
| 445 | + logsDir = testDir.resolve("subdir/logs"); |
| 446 | + processValidator = pb -> assertThat(pb.directory().toString(), equalTo(logsDir.toString())); |
| 447 | + runForeground(); |
| 448 | + } |
| 449 | + |
| 450 | + public void testLogsCreateFailure() throws Exception { |
| 451 | + Path testDir = createTempDir(); |
| 452 | + Path parentFile = testDir.resolve("exists"); |
| 453 | + Files.createFile(parentFile); |
| 454 | + logsDir = parentFile.resolve("logs"); |
| 455 | + var e = expectThrows(UserException.class, this::runForeground); |
| 456 | + assertThat(e.getMessage(), containsString("Unable to create logs dir")); |
| 457 | + } |
432 | 458 | } |
0 commit comments