|  | @@ -52,11 +52,9 @@ import static org.elasticsearch.discovery.zen.FileBasedUnicastHostsProvider.UNIC
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private boolean legacyLocation;
 | 
	
		
			
				|  |  |      private ThreadPool threadPool;
 | 
	
		
			
				|  |  |      private ExecutorService executorService;
 | 
	
		
			
				|  |  |      private MockTransportService transportService;
 | 
	
		
			
				|  |  | -    private Path configPath;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Before
 | 
	
		
			
				|  |  |      public void setUp() throws Exception {
 | 
	
	
		
			
				|  | @@ -108,24 +106,12 @@ public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          assertEquals(9300, nodes.get(2).getPort());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void testBuildDynamicNodesLegacyLocation() throws Exception {
 | 
	
		
			
				|  |  | -        legacyLocation = true;
 | 
	
		
			
				|  |  | -        testBuildDynamicNodes();
 | 
	
		
			
				|  |  | -        assertDeprecatedLocationWarning();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      public void testEmptyUnicastHostsFile() throws Exception {
 | 
	
		
			
				|  |  |          final List<String> hostEntries = Collections.emptyList();
 | 
	
		
			
				|  |  |          final List<TransportAddress> addresses = setupAndRunHostProvider(hostEntries);
 | 
	
		
			
				|  |  |          assertEquals(0, addresses.size());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void testEmptyUnicastHostsFileLegacyLocation() throws Exception {
 | 
	
		
			
				|  |  | -        legacyLocation = true;
 | 
	
		
			
				|  |  | -        testEmptyUnicastHostsFile();
 | 
	
		
			
				|  |  | -        assertDeprecatedLocationWarning();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      public void testUnicastHostsDoesNotExist() {
 | 
	
		
			
				|  |  |          final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
 | 
	
		
			
				|  |  |          final FileBasedUnicastHostsProvider provider = new FileBasedUnicastHostsProvider(settings, createTempDir().toAbsolutePath());
 | 
	
	
		
			
				|  | @@ -141,12 +127,6 @@ public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          assertEquals(0, addresses.size());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void testInvalidHostEntriesLegacyLocation() throws Exception {
 | 
	
		
			
				|  |  | -        legacyLocation = true;
 | 
	
		
			
				|  |  | -        testInvalidHostEntries();
 | 
	
		
			
				|  |  | -        assertDeprecatedLocationWarning();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      public void testSomeInvalidHostEntries() throws Exception {
 | 
	
		
			
				|  |  |          final List<String> hostEntries = Arrays.asList("192.168.0.1:9300:9300", "192.168.0.1:9301");
 | 
	
		
			
				|  |  |          final List<TransportAddress> addresses = setupAndRunHostProvider(hostEntries);
 | 
	
	
		
			
				|  | @@ -155,12 +135,6 @@ public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          assertEquals(9301, addresses.get(0).getPort());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void testSomeInvalidHostEntriesLegacyLocation() throws Exception {
 | 
	
		
			
				|  |  | -        legacyLocation = true;
 | 
	
		
			
				|  |  | -        testSomeInvalidHostEntries();
 | 
	
		
			
				|  |  | -        assertDeprecatedLocationWarning();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      // sets up the config dir, writes to the unicast hosts file in the config dir,
 | 
	
		
			
				|  |  |      // and then runs the file-based unicast host provider to get the list of discovery nodes
 | 
	
		
			
				|  |  |      private List<TransportAddress> setupAndRunHostProvider(final List<String> hostEntries) throws IOException {
 | 
	
	
		
			
				|  | @@ -168,15 +142,9 @@ public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          final Settings settings = Settings.builder()
 | 
	
		
			
				|  |  |              .put(Environment.PATH_HOME_SETTING.getKey(), homeDir)
 | 
	
		
			
				|  |  |              .build();
 | 
	
		
			
				|  |  | -        if (randomBoolean()) {
 | 
	
		
			
				|  |  | -            configPath = homeDir.resolve("config");
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            configPath = createTempDir();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        final Path discoveryFilePath = legacyLocation ? configPath.resolve("discovery-file") : configPath;
 | 
	
		
			
				|  |  | -        Files.createDirectories(discoveryFilePath);
 | 
	
		
			
				|  |  | -        final Path unicastHostsPath = discoveryFilePath.resolve(UNICAST_HOSTS_FILE);
 | 
	
		
			
				|  |  | -        try (BufferedWriter writer = Files.newBufferedWriter(unicastHostsPath)) {
 | 
	
		
			
				|  |  | +        final Path configPath = randomBoolean() ? homeDir.resolve("config") : createTempDir();
 | 
	
		
			
				|  |  | +        Files.createDirectories(configPath);
 | 
	
		
			
				|  |  | +        try (BufferedWriter writer = Files.newBufferedWriter(configPath.resolve(UNICAST_HOSTS_FILE))) {
 | 
	
		
			
				|  |  |              writer.write(String.join("\n", hostEntries));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -184,12 +152,4 @@ public class FileBasedUnicastHostsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              UnicastZenPing.resolveHostsLists(executorService, logger, hosts, limitPortCounts, transportService,
 | 
	
		
			
				|  |  |                  TimeValue.timeValueSeconds(10)));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    private void assertDeprecatedLocationWarning() {
 | 
	
		
			
				|  |  | -        assertWarnings("Found dynamic hosts list at [" +
 | 
	
		
			
				|  |  | -            configPath.resolve("discovery-file").resolve(UNICAST_HOSTS_FILE) +
 | 
	
		
			
				|  |  | -            "] but this path is deprecated. This list should be at [" +
 | 
	
		
			
				|  |  | -            configPath.resolve(UNICAST_HOSTS_FILE) +
 | 
	
		
			
				|  |  | -            "] instead. Support for the deprecated path will be removed in future.");
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  }
 |