HDFS-5360. Improvement of usage message of renameSnapshot and deleteSnapshot. Contributed by Shinichi Yamashita.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1532938 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Wang 2013-10-16 23:16:13 +00:00
parent 0b18a51c33
commit 5776b0b324
4 changed files with 62 additions and 3 deletions

View File

@ -68,7 +68,7 @@ class SnapshotCommands extends FsCommand {
throw new IllegalArgumentException("<snapshotDir> is missing."); throw new IllegalArgumentException("<snapshotDir> is missing.");
} }
if (args.size() > 2) { if (args.size() > 2) {
throw new IllegalArgumentException("Too many arguements."); throw new IllegalArgumentException("Too many arguments.");
} }
if (args.size() == 2) { if (args.size() == 2) {
snapshotName = args.removeLast(); snapshotName = args.removeLast();
@ -110,7 +110,7 @@ class SnapshotCommands extends FsCommand {
@Override @Override
protected void processOptions(LinkedList<String> args) throws IOException { protected void processOptions(LinkedList<String> args) throws IOException {
if (args.size() != 2) { if (args.size() != 2) {
throw new IOException("args number not 2: " + args.size()); throw new IllegalArgumentException("Incorrect number of arguments.");
} }
snapshotName = args.removeLast(); snapshotName = args.removeLast();
} }
@ -150,7 +150,7 @@ class SnapshotCommands extends FsCommand {
@Override @Override
protected void processOptions(LinkedList<String> args) throws IOException { protected void processOptions(LinkedList<String> args) throws IOException {
if (args.size() != 3) { if (args.size() != 3) {
throw new IOException("args number not 3: " + args.size()); throw new IllegalArgumentException("Incorrect number of arguments.");
} }
newName = args.removeLast(); newName = args.removeLast();
oldName = args.removeLast(); oldName = args.removeLast();

View File

@ -118,6 +118,9 @@ Release 2.2.1 - UNRELEASED
IMPROVEMENTS IMPROVEMENTS
HDFS-5360. Improvement of usage message of renameSnapshot and
deleteSnapshot. (Shinichi Yamashita via wang)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -23,12 +23,15 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSTestUtil;
@ -921,4 +924,29 @@ public class TestSnapshotDeletion {
subFile1Status = hdfs.getFileStatus(subFile1SCopy); subFile1Status = hdfs.getFileStatus(subFile1SCopy);
assertEquals(REPLICATION_1, subFile1Status.getReplication()); assertEquals(REPLICATION_1, subFile1Status.getReplication());
} }
@Test
public void testDeleteSnapshotCommandWithIllegalArguments() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream psOut = new PrintStream(out);
System.setOut(psOut);
System.setErr(psOut);
FsShell shell = new FsShell();
shell.setConf(conf);
String[] argv1 = {"-deleteSnapshot", "/tmp"};
int val = shell.run(argv1);
assertTrue(val == -1);
assertTrue(out.toString().contains(
argv1[0] + ": Incorrect number of arguments."));
out.reset();
String[] argv2 = {"-deleteSnapshot", "/tmp", "s1", "s2"};
val = shell.run(argv2);
assertTrue(val == -1);
assertTrue(out.toString().contains(
argv2[0] + ": Incorrect number of arguments."));
psOut.close();
out.close();
}
} }

View File

@ -22,10 +22,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.DistributedFileSystem;
@ -226,4 +229,29 @@ public class TestSnapshotRename {
} }
} }
} }
@Test
public void testRenameSnapshotCommandWithIllegalArguments() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream psOut = new PrintStream(out);
System.setOut(psOut);
System.setErr(psOut);
FsShell shell = new FsShell();
shell.setConf(conf);
String[] argv1 = {"-renameSnapshot", "/tmp", "s1"};
int val = shell.run(argv1);
assertTrue(val == -1);
assertTrue(out.toString().contains(
argv1[0] + ": Incorrect number of arguments."));
out.reset();
String[] argv2 = {"-renameSnapshot", "/tmp", "s1", "s2", "s3"};
val = shell.run(argv2);
assertTrue(val == -1);
assertTrue(out.toString().contains(
argv2[0] + ": Incorrect number of arguments."));
psOut.close();
out.close();
}
} }