HBASE-12304 CellCounter will throw AIOBE when output directory is not specified. (Ashish Singhi)

This commit is contained in:
anoopsjohn 2014-10-28 17:56:09 +05:30
parent 1d2c4bca56
commit f9fce4caf0
2 changed files with 28 additions and 1 deletions

View File

@ -243,7 +243,7 @@ public class CellCounter {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length < 1) {
if (otherArgs.length < 2) {
System.err.println("ERROR: Wrong number of parameters: " + args.length);
System.err.println("Usage: CellCounter <tablename> <outputDir> <reportSeparator> " +
"[^[regex pattern] or [Prefix] for row filter]] ");

View File

@ -200,4 +200,31 @@ public class TestCellCounter {
FileUtil.fullyDelete(new File(outputPath));
}
}
@Test (timeout=300000)
public void TestCellCounterWithoutOutputDir() throws Exception {
PrintStream oldPrintStream = System.err;
SecurityManager SECURITY_MANAGER = System.getSecurityManager();
LauncherSecurityManager newSecurityManager= new LauncherSecurityManager();
System.setSecurityManager(newSecurityManager);
ByteArrayOutputStream data = new ByteArrayOutputStream();
String[] args = {"tableName"};
System.setErr(new PrintStream(data));
try {
System.setErr(new PrintStream(data));
try {
CellCounter.main(args);
fail("should be SecurityException");
} catch (SecurityException e) {
assertEquals(-1, newSecurityManager.getExitCode());
assertTrue(data.toString().contains("ERROR: Wrong number of parameters:"));
// should be information about usage
assertTrue(data.toString().contains("Usage:"));
}
} finally {
System.setErr(oldPrintStream);
System.setSecurityManager(SECURITY_MANAGER);
}
}
}