HDFS-8205. CommandFormat#parse() should not parse option as value of option. (Contributed by Peter Shi and Xiaoyu Yao)

This commit is contained in:
Arpit Agarwal 2015-04-27 12:23:34 -07:00
parent 0e8af401d7
commit c254a2a671
5 changed files with 73 additions and 3 deletions

View File

@ -114,7 +114,8 @@ public class CommandFormat {
options.put(opt, Boolean.TRUE);
} else if (optionsWithValue.containsKey(opt)) {
args.remove(pos);
if (pos < args.size() && (args.size() > minPar)) {
if (pos < args.size() && (args.size() > minPar)
&& !args.get(pos).startsWith("-")) {
arg = args.get(pos);
args.remove(pos);
} else {

View File

@ -315,6 +315,34 @@ public class TestCount {
verifyNoMoreInteractions(out);
}
@Test
public void processPathWithQuotasByQTVH() throws Exception {
Path path = new Path("mockfs:/test");
when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat);
PrintStream out = mock(PrintStream.class);
Count count = new Count();
count.out = out;
LinkedList<String> options = new LinkedList<String>();
options.add("-q");
options.add("-t");
options.add("-v");
options.add("-h");
options.add("dummy");
count.processOptions(options);
String withStorageTypeHeader =
// <----13---> <-------17------>
" DISK_QUOTA REM_DISK_QUOTA " +
" SSD_QUOTA REM_SSD_QUOTA " +
"ARCHIVE_QUOTA REM_ARCHIVE_QUOTA " +
"PATHNAME";
verify(out).println(withStorageTypeHeader);
verifyNoMoreInteractions(out);
}
@Test
public void processPathWithQuotasByMultipleStorageTypesContent() throws Exception {
Path path = new Path("mockfs:/test");

View File

@ -294,6 +294,9 @@ Release 2.7.1 - UNRELEASED
HDFS-8070. Pre-HDFS-7915 DFSClient cannot use short circuit on
post-HDFS-7915 DataNode (cmccabe)
HDFS-8205. CommandFormat#parse() should not parse option as
value of option. (Peter Shi and Xiaoyu Yao via Arpit Agarwal)
Release 2.7.0 - 2015-04-20
INCOMPATIBLE CHANGES

View File

@ -222,9 +222,9 @@ public class DFSAdmin extends FsShell {
ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) {
super(fs);
CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE);
c.addOptionWithValue("storageType");
List<String> parameters = c.parse(args, pos);
String storageTypeString =
StringUtils.popOptionWithArgument("-storageType", parameters);
String storageTypeString = c.getOptValue("storageType");
if (storageTypeString != null) {
this.type = StorageType.parseStorageType(storageTypeString);
}

View File

@ -7573,6 +7573,44 @@
</comparators>
</test>
<test> <!-- TESTED -->
<description>setSpaceQuota -storageType: directory with quota by storage type</description>
<test-commands>
<command>-fs NAMENODE -mkdir /ttt</command>
<dfs-admin-command>-fs NAMENODE -setSpaceQuota 1m -storageType DISK /ttt </dfs-admin-command>
<command>-fs NAMENODE -count -q -t DISK /ttt</command>
</test-commands>
<cleanup-commands>
<command>-fs NAMENODE -rm -r /ttt</command>
</cleanup-commands>
<comparators>
<comparator>
<type>RegexpComparator</type>
<expected-output>( |\t)*1048576( |\t)*1048576 /ttt</expected-output>
</comparator>
</comparators>
</test>
<test> <!-- TESTED -->
<description>clrSpaceQuota -storageType: directory quota by storage type</description>
<test-commands>
<command>-fs NAMENODE -mkdir /ttt</command>
<dfs-admin-command>-fs NAMENODE -setSpaceQuota 1m -storageType DISK /ttt </dfs-admin-command>
<command>-fs NAMENODE -count -q -t DISK /ttt</command>
<dfs-admin-command>-fs NAMENODE -clrSpaceQuota -storageType DISK /ttt </dfs-admin-command>
<command>-fs NAMENODE -count -q -t DISK /ttt</command>
</test-commands>
<cleanup-commands>
<command>-fs NAMENODE -rm -r /ttt</command>
</cleanup-commands>
<comparators>
<comparator>
<type>RegexpComparator</type>
<expected-output>( |\t)*none( |\t)*inf /ttt</expected-output>
</comparator>
</comparators>
</test>
<test> <!-- TESTED -->
<description>count: directory using relative path with -q option</description>
<test-commands>