Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB2B7DBB7 for ; Fri, 29 Jun 2012 22:24:17 +0000 (UTC) Received: (qmail 10206 invoked by uid 500); 29 Jun 2012 22:24:17 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 10158 invoked by uid 500); 29 Jun 2012 22:24:17 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 10151 invoked by uid 99); 29 Jun 2012 22:24:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jun 2012 22:24:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jun 2012 22:24:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D94FD2388962; Fri, 29 Jun 2012 22:23:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1355583 - in /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src: main/java/org/apache/hadoop/util/HostsFileReader.java test/java/org/apache/hadoop/util/TestHostsFileReader.java Date: Fri, 29 Jun 2012 22:23:55 -0000 To: common-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120629222355.D94FD2388962@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: todd Date: Fri Jun 29 22:23:53 2012 New Revision: 1355583 URL: http://svn.apache.org/viewvc?rev=1355583&view=rev Log: HDFS-3446. HostsFileReader silently ignores bad includes/excludes. Contributed by Matthew Jacobs. Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/HostsFileReader.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/HostsFileReader.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/HostsFileReader.java?rev=1355583&r1=1355582&r2=1355583&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/HostsFileReader.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/HostsFileReader.java Fri Jun 29 22:23:53 2012 @@ -50,9 +50,6 @@ public class HostsFileReader { private void readFileToSet(String filename, Set set) throws IOException { File file = new File(filename); - if (!file.exists()) { - return; - } FileInputStream fis = new FileInputStream(file); BufferedReader reader = null; try { Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java?rev=1355583&r1=1355582&r2=1355583&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java Fri Jun 29 22:23:53 2012 @@ -18,8 +18,8 @@ package org.apache.hadoop.util; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileWriter; -import java.util.Set; import org.junit.*; import static org.junit.Assert.*; @@ -37,8 +37,6 @@ public class TestHostsFileReader { File INCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.include"); String excludesFile = HOSTS_TEST_DIR + "/dfs.exclude"; String includesFile = HOSTS_TEST_DIR + "/dfs.include"; - private Set includes; - private Set excludes; @Before public void setUp() throws Exception { @@ -101,6 +99,43 @@ public class TestHostsFileReader { } /* + * Test creating a new HostsFileReader with nonexistent files + */ + @Test + public void testCreateHostFileReaderWithNonexistentFile() throws Exception { + try { + new HostsFileReader( + HOSTS_TEST_DIR + "/doesnt-exist", + HOSTS_TEST_DIR + "/doesnt-exist"); + Assert.fail("Should throw FileNotFoundException"); + } catch (FileNotFoundException ex) { + // Exception as expected + } + } + + /* + * Test refreshing an existing HostsFileReader with an includes file that no longer exists + */ + @Test + public void testRefreshHostFileReaderWithNonexistentFile() throws Exception { + FileWriter efw = new FileWriter(excludesFile); + FileWriter ifw = new FileWriter(includesFile); + + efw.close(); + + ifw.close(); + + HostsFileReader hfp = new HostsFileReader(includesFile, excludesFile); + assertTrue(INCLUDES_FILE.delete()); + try { + hfp.refresh(); + Assert.fail("Should throw FileNotFoundException"); + } catch (FileNotFoundException ex) { + // Exception as expected + } + } + + /* * Test for null file */ @Test