Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 30736 invoked from network); 22 Oct 2009 22:47:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Oct 2009 22:47:21 -0000 Received: (qmail 86286 invoked by uid 500); 22 Oct 2009 22:47:21 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 86240 invoked by uid 500); 22 Oct 2009 22:47:21 -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 86231 invoked by uid 99); 22 Oct 2009 22:47:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Oct 2009 22:47:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 22 Oct 2009 22:47:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2A56A23888FE; Thu, 22 Oct 2009 22:46:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r828887 - in /hadoop/common/branches/branch-0.21: CHANGES.txt src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java Date: Thu, 22 Oct 2009 22:46:57 -0000 To: common-commits@hadoop.apache.org From: szetszwo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091022224657.2A56A23888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: szetszwo Date: Thu Oct 22 22:46:56 2009 New Revision: 828887 URL: http://svn.apache.org/viewvc?rev=828887&view=rev Log: HADOOP-6327. FileContext tests should not use /tmp and should clean up files. Contributed by Sanjay Radia Modified: hadoop/common/branches/branch-0.21/CHANGES.txt hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java Modified: hadoop/common/branches/branch-0.21/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/CHANGES.txt?rev=828887&r1=828886&r2=828887&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.21/CHANGES.txt Thu Oct 22 22:46:56 2009 @@ -1082,6 +1082,9 @@ HADOOP-6292. Update native libraries guide. (Corinne Chandel via cdouglas) + HADOOP-6327. FileContext tests should not use /tmp and should clean up + files. (Sanjay Radia via szetszwo) + Release 0.20.2 - Unreleased NEW FEATURES Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java?rev=828887&r1=828886&r2=828887&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java (original) +++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java Thu Oct 22 22:46:56 2009 @@ -52,9 +52,10 @@ protected static FileContext fc; static final String TEST_ROOT_DIR = new Path(System.getProperty( - "test.build.data", "/tmp")).toString().replace(' ', '_') + "test.build.data", "build/test/data")).toString().replace(' ', '_') + "/test"; + protected Path getTestRootRelativePath(String pathString) { return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString)); } Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java?rev=828887&r1=828886&r2=828887&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java (original) +++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java Thu Oct 22 22:46:56 2009 @@ -56,11 +56,35 @@ private static String TEST_DIR_AXA = "test/hadoop/axa"; private static String TEST_DIR_AXX = "test/hadoop/axx"; - private static String TEST_ROOT_DIR = - System.getProperty("test.build.data", "/tmp"); + static final String LOCAL_FS_ROOT_URI = "file:///tmp/test"; - protected Path getTestRootPath(String pathString) { - return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString)); + static final String TEST_ROOT_DIR = + System.getProperty("test.build.data", "build/test/data").replace(' ', '_'); + + + /** + * we need to store the absRootDir because some tests may do a setWd and + * the TEST_ROOT_DIR may itself be relative. + */ + String absTestRootDir = null; + protected String getAbsoluteTestRootDir() throws IOException { + if (absTestRootDir == null) { + if (TEST_ROOT_DIR.startsWith("/")) { + absTestRootDir = TEST_ROOT_DIR; + } else { + absTestRootDir = getDefaultWorkingDirectory().toString() + "/" + + TEST_ROOT_DIR; + } + } + return absTestRootDir; + } + + protected Path getTestRootDir() throws IOException { + return fc.makeQualified(new Path(getAbsoluteTestRootDir())); + } + + protected Path getTestRootPath(String pathString) throws IOException { + return fc.makeQualified(new Path(getAbsoluteTestRootDir(), pathString)); } @@ -75,7 +99,7 @@ //A test filter with returns any path containing a "b" final private static PathFilter TEST_X_FILTER = new PathFilter() { public boolean accept(Path file) { - if(file.toString().contains("x") || file.toString().contains("X")) + if(file.getName().contains("x") || file.toString().contains("X")) return true; else return false; @@ -97,6 +121,7 @@ @After public void tearDown() throws Exception { fc.delete(getTestRootPath("test"), true); + fc.delete(new Path(LOCAL_FS_ROOT_URI), true); } protected static int getBlockSize() { @@ -130,7 +155,9 @@ @Test public void testWorkingDirectory() throws Exception { - Path workDir = getDefaultWorkingDirectory(); + // First we cd to our test root + Path workDir = new Path(getTestRootDir(), new Path("test")); + fc.setWorkingDirectory(workDir); Assert.assertEquals(workDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path(".")); @@ -140,8 +167,14 @@ Assert.assertEquals(workDir.getParent(), fc.getWorkingDirectory()); // cd using a relative path + + // Go back to our test root + workDir = new Path(getTestRootDir(), new Path("test")); + fc.setWorkingDirectory(workDir); + Assert.assertEquals(workDir, fc.getWorkingDirectory()); + Path relativeDir = new Path("existingDir1"); - Path absoluteDir = new Path(workDir.getParent(),"existingDir1"); + Path absoluteDir = new Path(workDir,"existingDir1"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(relativeDir); Assert.assertEquals(absoluteDir, @@ -166,7 +199,8 @@ } // Try a URI - absoluteDir = new Path("file:///tmp/existingDir"); + + absoluteDir = new Path(LOCAL_FS_ROOT_URI + "/existingDir"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(absoluteDir); Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); @@ -930,7 +964,8 @@ Assert.assertEquals("Source exists", srcExists, fc.exists(src)); Assert.assertEquals("Destination exists", dstExists, fc.exists(dst)); } - private boolean containsPath(Path path, FileStatus[] filteredPaths) { + private boolean containsPath(Path path, FileStatus[] filteredPaths) + throws IOException { for(int i = 0; i < filteredPaths.length; i ++) { if(getTestRootPath(path.toString()).equals(filteredPaths[i].getPath())) return true;