|
30 | 30 | import org.elasticsearch.index.Index;
|
31 | 31 | import org.elasticsearch.index.IndexSettings;
|
32 | 32 | import org.elasticsearch.index.shard.ShardId;
|
| 33 | +import org.elasticsearch.node.Node; |
33 | 34 | import org.elasticsearch.test.ESTestCase;
|
34 | 35 | import org.elasticsearch.test.IndexSettingsModule;
|
35 | 36 |
|
@@ -450,6 +451,32 @@ public void testExistingTempFiles() throws IOException {
|
450 | 451 | }
|
451 | 452 | }
|
452 | 453 |
|
| 454 | + public void testIfNodeEnvironmentInitiationFails() throws IOException { |
| 455 | + // simulate some previous left over temp files |
| 456 | + Settings settings = buildEnvSettings(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build()); |
| 457 | + |
| 458 | + List<String> dataPaths = Environment.PATH_DATA_SETTING.get(settings); |
| 459 | + |
| 460 | + |
| 461 | + final Path nodePath = NodeEnvironment.resolveNodePath(PathUtils.get(dataPaths.get(0)), 0); |
| 462 | + final Path indicesPath = nodePath.resolve(NodeEnvironment.INDICES_FOLDER); |
| 463 | + |
| 464 | + Files.createDirectories(indicesPath.resolve("index-uuid")); |
| 465 | + try { |
| 466 | + |
| 467 | + NodeEnvironment env = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); |
| 468 | + Path nodepatt = env.nodePaths()[0].indicesPath; |
| 469 | + env.close(); |
| 470 | + fail("Node environment instantiation should have failed for non data node" + nodepatt + " " + indicesPath + |
| 471 | + env.availableIndexFolders()); |
| 472 | + } catch (IllegalStateException e) { |
| 473 | + // that's OK :) |
| 474 | + } |
| 475 | + |
| 476 | + for (String path: dataPaths) { |
| 477 | + Files.deleteIfExists(indicesPath.resolve("index-uuid")); |
| 478 | + } |
| 479 | + } |
453 | 480 | /** Converts an array of Strings to an array of Paths, adding an additional child if specified */
|
454 | 481 | private Path[] stringsToPaths(String[] strings, String additional) {
|
455 | 482 | Path[] locations = new Path[strings.length];
|
|
0 commit comments