HDFS-2131. Add new tests for the -overwrite/-f option in put and copyFromLocal by HADOOP-7361. Contributed by Uma Maheswara Rao G

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1145843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-07-13 03:01:25 +00:00
parent bf1b1b4ef7
commit 13a26379ed
3 changed files with 127 additions and 0 deletions

View File

@ -549,6 +549,9 @@ Trunk (unreleased changes)
HDFS-1977. Stop using StringUtils.stringifyException(). HDFS-1977. Stop using StringUtils.stringifyException().
(Bharath Mundlapudi via jitendra) (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 OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

View File

@ -2670,6 +2670,24 @@
</comparators> </comparators>
</test> </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 --> <test> <!-- TESTED -->
<description>cp: copying directory to directory in hdfs:// path</description> <description>cp: copying directory to directory in hdfs:// path</description>
<test-commands> <test-commands>
@ -4076,6 +4094,24 @@
</comparators> </comparators>
</test> </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 --> <test> <!-- TESTED -->
<description>put: putting file into an already existing destination(relative path)</description> <description>put: putting file into an already existing destination(relative path)</description>
<test-commands> <test-commands>
@ -4593,6 +4629,25 @@
</test> </test>
<test> <!-- TESTED --> <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> <description>copyFromLocal: copying file into an already existing destination(relative path)</description>
<test-commands> <test-commands>
<command>-fs NAMENODE -touchz file0</command> <command>-fs NAMENODE -touchz file0</command>

View File

@ -1354,4 +1354,73 @@ public class TestDFSShell extends TestCase {
int res = admin.run(new String[] {"-refreshNodes"}); int res = admin.run(new String[] {"-refreshNodes"});
assertEquals("expected to fail -1", res , -1); 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();
}
}
} }