You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by jg...@apache.org on 2010/05/01 23:08:34 UTC
svn commit: r940112 - in /hadoop/common/trunk: ./
src/java/org/apache/hadoop/fs/ src/test/core/org/apache/hadoop/fs/
Author: jghoman
Date: Sat May 1 21:08:34 2010
New Revision: 940112
URL: http://svn.apache.org/viewvc?rev=940112&view=rev
Log:
HADOOP-6730. Bug in FileContext#copy and provide base class for FileContext tests. (Ravi Phulari via jghoman)
Added:
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextUtilBase.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFcLocalFsUtil.java
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileContext.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextTestHelper.java
Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=940112&r1=940111&r2=940112&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Sat May 1 21:08:34 2010
@@ -2,6 +2,11 @@ Hadoop Change Log
Trunk (unreleased changes)
+ BUG FIXES
+
+ HADOOP-6730. Bug in FileContext#copy and provide base class for FileContext
+ tests. (Ravi Phulari via jghoman)
+
Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileContext.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileContext.java?rev=940112&r1=940111&r2=940112&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileContext.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileContext.java Sat May 1 21:08:34 2010
@@ -2050,8 +2050,8 @@ public final class FileContext {
*/
private void checkDest(String srcName, Path dst, boolean overwrite)
throws AccessControlException, IOException {
- FileStatus dstFs = getFileStatus(dst);
try {
+ FileStatus dstFs = getFileStatus(dst);
if (dstFs.isDir()) {
if (null == srcName) {
throw new IOException("Target " + dst + " is a directory");
Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextTestHelper.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextTestHelper.java?rev=940112&r1=940111&r2=940112&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextTestHelper.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextTestHelper.java Sat May 1 21:08:34 2010
@@ -17,12 +17,16 @@
*/
package org.apache.hadoop.fs;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
import java.util.EnumSet;
import org.apache.hadoop.fs.Options.CreateOpts;
import org.apache.hadoop.fs.Options.CreateOpts.BlockSize;
+import org.apache.hadoop.io.IOUtils;
/**
* Helper class for unit tests.
@@ -145,4 +149,19 @@ public final class FileContextTestHelper
return false;
}
}
+
+ public static void writeFile(FileContext fc, Path path,byte b[]) throws Exception {
+ FSDataOutputStream out =
+ fc.create(path,EnumSet.of(CreateFlag.CREATE), CreateOpts.createParent());
+ out.write(b);
+ out.close();
+ }
+
+ public static byte[] readFile(FileContext fc, Path path, int len ) throws Exception {
+ DataInputStream dis = fc.open(path);
+ byte[] buffer = new byte[len];
+ IOUtils.readFully(dis, buffer, 0, len);
+ dis.close();
+ return buffer;
+ }
}
Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextUtilBase.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextUtilBase.java?rev=940112&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextUtilBase.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextUtilBase.java Sat May 1 21:08:34 2010
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs;
+
+import java.util.Arrays;
+
+import org.apache.hadoop.util.StringUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import static org.apache.hadoop.fs.FileContextTestHelper.*;
+
+/**
+ * <p>
+ * A collection of Util tests for the {@link FileContext#util()}.
+ * This test should be used for testing an instance of {@link FileContext#util()}
+ * that has been initialized to a specific default FileSystem such a
+ * LocalFileSystem, HDFS,S3, etc.
+ * </p>
+ * <p>
+ * To test a given {@link FileSystem} implementation create a subclass of this
+ * test and override {@link #setUp()} to initialize the <code>fc</code>
+ * {@link FileContext} instance variable.
+ *
+ * </p>
+ */
+public abstract class FileContextUtilBase {
+ protected FileContext fc;
+
+ {
+ try {
+ ((org.apache.commons.logging.impl.Log4JLogger)FileSystem.LOG).getLogger()
+ .setLevel(org.apache.log4j.Level.DEBUG);
+ } catch(Exception e) {
+ System.out.println("Cannot change log level\n"
+ + StringUtils.stringifyException(e));
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ fc.mkdir(getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ fc.delete(getTestRootPath(fc), true);
+ }
+
+ @Test
+ public void testFcCopy() throws Exception{
+ final String ts = "some random text";
+ Path file1 = getTestRootPath(fc, "file1");
+ Path file2 = getTestRootPath(fc, "file2");
+
+ writeFile(fc, file1, ts.getBytes());
+ assertTrue(fc.util().exists(file1));
+ fc.util().copy(file1, file2);
+
+ // verify that newly copied file2 exists
+ assertTrue("Failed to copy file2 ", fc.util().exists(file2));
+ // verify that file2 contains test string
+ assertTrue("Copied files does not match ",Arrays.equals(ts.getBytes(),
+ readFile(fc,file2,ts.getBytes().length)));
+ }
+}
\ No newline at end of file
Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFcLocalFsUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFcLocalFsUtil.java?rev=940112&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFcLocalFsUtil.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFcLocalFsUtil.java Sat May 1 21:08:34 2010
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs;
+
+import org.junit.Before;
+
+/**
+ * Test Util for localFs using FileContext API.
+ */
+public class TestFcLocalFsUtil extends
+ FileContextUtilBase {
+
+ @Before
+ public void setUp() throws Exception {
+ fc = FileContext.getLocalFSFileContext();
+ super.setUp();
+ }
+}