You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by sz...@apache.org on 2011/07/13 05:01:25 UTC
svn commit: r1145843 - in /hadoop/common/trunk/hdfs: CHANGES.txt
src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java
Author: szetszwo
Date: Wed Jul 13 03:01:25 2011
New Revision: 1145843
URL: http://svn.apache.org/viewvc?rev=1145843&view=rev
Log:
HDFS-2131. Add new tests for the -overwrite/-f option in put and copyFromLocal by HADOOP-7361. Contributed by Uma Maheswara Rao G
Modified:
hadoop/common/trunk/hdfs/CHANGES.txt
hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java
Modified: hadoop/common/trunk/hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/CHANGES.txt?rev=1145843&r1=1145842&r2=1145843&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hdfs/CHANGES.txt Wed Jul 13 03:01:25 2011
@@ -549,6 +549,9 @@ Trunk (unreleased changes)
HDFS-1977. Stop using StringUtils.stringifyException().
(Bharath Mundlapudi via jitendra)
+ HDFS-2131. Add new tests for the -overwrite/-f option in put and
+ copyFromLocal by HADOOP-7361. (Uma Maheswara Rao G via szetszwo)
+
OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image
Modified: hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml?rev=1145843&r1=1145842&r2=1145843&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml (original)
+++ hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml Wed Jul 13 03:01:25 2011
@@ -2671,6 +2671,24 @@
</test>
<test> <!-- TESTED -->
+ <description>cp: putting file into an already existing destination with -f option(absolute path)</description>
+ <test-commands>
+ <command>-fs NAMENODE -touchz /user/file0</command>
+ <command>-fs NAMENODE -cp -f CLITEST_DATA/data120bytes /user/file0</command>
+ <command>-fs NAMENODE -cat /user/file0</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r /user</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>12345678901234</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
<description>cp: copying directory to directory in hdfs:// path</description>
<test-commands>
<command>-fs NAMENODE -mkdir hdfs:///dir0</command>
@@ -4077,6 +4095,24 @@
</test>
<test> <!-- TESTED -->
+ <description>put: putting file into an already existing destination with -f option(absolute path)</description>
+ <test-commands>
+ <command>-fs NAMENODE -touchz /user/file0</command>
+ <command>-fs NAMENODE -put -f CLITEST_DATA/data120bytes /user/file0</command>
+ <command>-fs NAMENODE -cat /user/file0</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r /user</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>12345678901234</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
<description>put: putting file into an already existing destination(relative path)</description>
<test-commands>
<command>-fs NAMENODE -touchz file0</command>
@@ -4593,6 +4629,25 @@
</test>
<test> <!-- TESTED -->
+ <description>copyFromLocal: copying file into an already existing destination with -f option(absolute path)</description>
+ <test-commands>
+ <command>-fs NAMENODE -touchz /user/file0</command>
+ <command>-fs NAMENODE -copyFromLocal -f CLITEST_DATA/data120bytes /user/file0</command>
+ <command>-fs NAMENODE -cat /user/file0</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r /user</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>12345678901234</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+
<description>copyFromLocal: copying file into an already existing destination(relative path)</description>
<test-commands>
<command>-fs NAMENODE -touchz file0</command>
Modified: hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java?rev=1145843&r1=1145842&r2=1145843&view=diff
==============================================================================
--- hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java (original)
+++ hadoop/common/trunk/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java Wed Jul 13 03:01:25 2011
@@ -1354,4 +1354,73 @@ public class TestDFSShell extends TestCa
int res = admin.run(new String[] {"-refreshNodes"});
assertEquals("expected to fail -1", res , -1);
}
+
+ // force Copy Option is -f
+ public void testCopyCommandsWithForceOption() throws Exception {
+ Configuration conf = new Configuration();
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
+ .format(true).build();
+ FsShell shell = null;
+ FileSystem fs = null;
+ File localFile = new File("testFileForPut");
+ Path hdfsTestDir = new Path("ForceTestDir");
+ try {
+ fs = cluster.getFileSystem();
+ fs.mkdirs(hdfsTestDir);
+ localFile.createNewFile();
+ writeFile(fs, new Path("testFileForPut"));
+ shell = new FsShell();
+
+ // Tests for put
+ String[] argv = new String[] { "-put", "-f", localFile.getName(),
+ "ForceTestDir" };
+ int res = ToolRunner.run(shell, argv);
+ int SUCCESS = 0;
+ int ERROR = 1;
+ assertEquals("put -f is not working", SUCCESS, res);
+
+ argv = new String[] { "-put", localFile.getName(), "ForceTestDir" };
+ res = ToolRunner.run(shell, argv);
+ assertEquals("put command itself is able to overwrite the file", ERROR,
+ res);
+
+ // Tests for copyFromLocal
+ argv = new String[] { "-copyFromLocal", "-f", localFile.getName(),
+ "ForceTestDir" };
+ res = ToolRunner.run(shell, argv);
+ assertEquals("copyFromLocal -f is not working", SUCCESS, res);
+
+ argv = new String[] { "-copyFromLocal", localFile.getName(),
+ "ForceTestDir" };
+ res = ToolRunner.run(shell, argv);
+ assertEquals(
+ "copyFromLocal command itself is able to overwrite the file", ERROR,
+ res);
+
+ // Tests for cp
+ argv = new String[] { "-cp", "-f", localFile.getName(), "ForceTestDir" };
+ res = ToolRunner.run(shell, argv);
+ assertEquals("cp -f is not working", SUCCESS, res);
+
+ argv = new String[] { "-cp", localFile.getName(),
+ "ForceTestDir" };
+ res = ToolRunner.run(shell, argv);
+ assertEquals("cp command itself is able to overwrite the file", ERROR,
+ res);
+ } finally {
+ if (null != shell)
+ shell.close();
+
+ if (localFile.exists())
+ localFile.delete();
+
+ if (null != fs) {
+ fs.delete(hdfsTestDir, true);
+ fs.close();
+ }
+ cluster.shutdown();
+ }
+
+ }
+
}