HDFS-2154. In TestDFSShell, use TEST_ROOT_DIR and fix some deprecated warnings.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1147184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-07-15 15:09:43 +00:00
parent 4f0dba4142
commit f582aa4492
2 changed files with 23 additions and 23 deletions

View File

@ -554,6 +554,9 @@ Trunk (unreleased changes)
HDFS-2140. Move Host2NodesMap to the blockmanagement package. (szetszwo) HDFS-2140. Move Host2NodesMap to the blockmanagement package. (szetszwo)
HDFS-2154. In TestDFSShell, use TEST_ROOT_DIR and fix some deprecated
warnings. (szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

View File

@ -43,7 +43,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.shell.Count;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.FSDataset; import org.apache.hadoop.hdfs.server.datanode.FSDataset;
@ -701,10 +700,10 @@ public class TestDFSShell extends TestCase {
String root = createTree(dfs, "count"); String root = createTree(dfs, "count");
// Verify the counts // Verify the counts
runCount(root, 2, 4, conf); runCount(root, 2, 4, shell);
runCount(root + "2", 2, 1, conf); runCount(root + "2", 2, 1, shell);
runCount(root + "2/f1", 0, 1, conf); runCount(root + "2/f1", 0, 1, shell);
runCount(root + "2/sub", 1, 0, conf); runCount(root + "2/sub", 1, 0, shell);
final FileSystem localfs = FileSystem.getLocal(conf); final FileSystem localfs = FileSystem.getLocal(conf);
Path localpath = new Path(TEST_ROOT_DIR, "testcount"); Path localpath = new Path(TEST_ROOT_DIR, "testcount");
@ -714,8 +713,8 @@ public class TestDFSShell extends TestCase {
final String localstr = localpath.toString(); final String localstr = localpath.toString();
System.out.println("localstr=" + localstr); System.out.println("localstr=" + localstr);
runCount(localstr, 1, 0, conf); runCount(localstr, 1, 0, shell);
assertEquals(0, new Count(new String[]{root, localstr}, 0, conf).runAll()); assertEquals(0, runCmd(shell, "-count", root, localstr));
} finally { } finally {
try { try {
dfs.close(); dfs.close();
@ -724,7 +723,7 @@ public class TestDFSShell extends TestCase {
cluster.shutdown(); cluster.shutdown();
} }
} }
private void runCount(String path, long dirs, long files, Configuration conf private static void runCount(String path, long dirs, long files, FsShell shell
) throws IOException { ) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bytes); PrintStream out = new PrintStream(bytes);
@ -733,7 +732,7 @@ public class TestDFSShell extends TestCase {
Scanner in = null; Scanner in = null;
String results = null; String results = null;
try { try {
new Count(new String[]{path}, 0, conf).runAll(); runCmd(shell, "-count", path);
results = bytes.toString(); results = bytes.toString();
in = new Scanner(results); in = new Scanner(results);
assertEquals(dirs, in.nextLong()); assertEquals(dirs, in.nextLong());
@ -747,7 +746,7 @@ public class TestDFSShell extends TestCase {
} }
//throws IOException instead of Exception as shell.run() does. //throws IOException instead of Exception as shell.run() does.
private int runCmd(FsShell shell, String... args) throws IOException { private static int runCmd(FsShell shell, String... args) throws IOException {
StringBuilder cmdline = new StringBuilder("RUN:"); StringBuilder cmdline = new StringBuilder("RUN:");
for (String arg : args) cmdline.append(" " + arg); for (String arg : args) cmdline.append(" " + arg);
LOG.info(cmdline.toString()); LOG.info(cmdline.toString());
@ -1362,48 +1361,46 @@ public class TestDFSShell extends TestCase {
.format(true).build(); .format(true).build();
FsShell shell = null; FsShell shell = null;
FileSystem fs = null; FileSystem fs = null;
File localFile = new File("testFileForPut"); final File localFile = new File(TEST_ROOT_DIR, "testFileForPut");
Path hdfsTestDir = new Path("ForceTestDir"); final String localfilepath = localFile.getAbsolutePath();
final String testdir = TEST_ROOT_DIR + "/ForceTestDir";
final Path hdfsTestDir = new Path(testdir);
try { try {
fs = cluster.getFileSystem(); fs = cluster.getFileSystem();
fs.mkdirs(hdfsTestDir); fs.mkdirs(hdfsTestDir);
localFile.createNewFile(); localFile.createNewFile();
writeFile(fs, new Path("testFileForPut")); writeFile(fs, new Path(TEST_ROOT_DIR, "testFileForPut"));
shell = new FsShell(); shell = new FsShell();
// Tests for put // Tests for put
String[] argv = new String[] { "-put", "-f", localFile.getName(), String[] argv = new String[] { "-put", "-f", localfilepath, testdir };
"ForceTestDir" };
int res = ToolRunner.run(shell, argv); int res = ToolRunner.run(shell, argv);
int SUCCESS = 0; int SUCCESS = 0;
int ERROR = 1; int ERROR = 1;
assertEquals("put -f is not working", SUCCESS, res); assertEquals("put -f is not working", SUCCESS, res);
argv = new String[] { "-put", localFile.getName(), "ForceTestDir" }; argv = new String[] { "-put", localfilepath, testdir };
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
assertEquals("put command itself is able to overwrite the file", ERROR, assertEquals("put command itself is able to overwrite the file", ERROR,
res); res);
// Tests for copyFromLocal // Tests for copyFromLocal
argv = new String[] { "-copyFromLocal", "-f", localFile.getName(), argv = new String[] { "-copyFromLocal", "-f", localfilepath, testdir };
"ForceTestDir" };
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
assertEquals("copyFromLocal -f is not working", SUCCESS, res); assertEquals("copyFromLocal -f is not working", SUCCESS, res);
argv = new String[] { "-copyFromLocal", localFile.getName(), argv = new String[] { "-copyFromLocal", localfilepath, testdir };
"ForceTestDir" };
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
assertEquals( assertEquals(
"copyFromLocal command itself is able to overwrite the file", ERROR, "copyFromLocal command itself is able to overwrite the file", ERROR,
res); res);
// Tests for cp // Tests for cp
argv = new String[] { "-cp", "-f", localFile.getName(), "ForceTestDir" }; argv = new String[] { "-cp", "-f", localfilepath, testdir };
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
assertEquals("cp -f is not working", SUCCESS, res); assertEquals("cp -f is not working", SUCCESS, res);
argv = new String[] { "-cp", localFile.getName(), argv = new String[] { "-cp", localfilepath, testdir };
"ForceTestDir" };
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
assertEquals("cp command itself is able to overwrite the file", ERROR, assertEquals("cp command itself is able to overwrite the file", ERROR,
res); res);