@Test public void testImportMain() throws Exception { PrintStream oldPrintStream = System.err; SecurityManager SECURITY_MANAGER = System.getSecurityManager(); LauncherSecurityManager newSecurityManager= new LauncherSecurityManager(); System.setSecurityManager(newSecurityManager); ByteArrayOutputStream data = new ByteArrayOutputStream(); String[] args = {}; System.setErr(new PrintStream(data)); try { System.setErr(new PrintStream(data)); try { RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains("Wrong number of parameters:")); assertTrue(data.toString().contains( "Usage: RowCounter [options] <tablename> [--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); assertTrue(data.toString().contains("-Dhbase.client.scanner.caching=100")); assertTrue(data.toString().contains("-Dmapreduce.map.speculative=false")); } data.reset(); try { args = new String[2]; args[0] = "table"; args[1] = "--range=1"; RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains( "Please specify range in such format as \"--range=a,b\" or, with only one boundary," + " \"--range=,b\" or \"--range=a,\"")); assertTrue(data.toString().contains( "Usage: RowCounter [options] <tablename> [--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); } } finally { System.setErr(oldPrintStream); System.setSecurityManager(SECURITY_MANAGER); } }
public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 1) { printUsage("Wrong number of parameters: " + args.length); System.exit(-1); } Job job = createSubmittableJob(conf, otherArgs); if (job == null) { System.exit(-1); } System.exit(job.waitForCompletion(true) ? 0 : 1); }
RowCounter { public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 1) { printUsage("Wrong number of parameters: " + args.length); System.exit(-1); } Job job = createSubmittableJob(conf, otherArgs); if (job == null) { System.exit(-1); } System.exit(job.waitForCompletion(true) ? 0 : 1); } }
RowCounter { public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 1) { printUsage("Wrong number of parameters: " + args.length); System.exit(-1); } Job job = createSubmittableJob(conf, otherArgs); if (job == null) { System.exit(-1); } System.exit(job.waitForCompletion(true) ? 0 : 1); }  }
RowCounter { public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 1) { printUsage("Wrong number of parameters: " + args.length); System.exit(-1); } Job job = createSubmittableJob(conf, otherArgs); if (job == null) { System.exit(-1); } System.exit(job.waitForCompletion(true) ? 0 : 1); }  static Job createSubmittableJob(Configuration conf, String[] args); static void main(String[] args); }
RowCounter { public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 1) { printUsage("Wrong number of parameters: " + args.length); System.exit(-1); } Job job = createSubmittableJob(conf, otherArgs); if (job == null) { System.exit(-1); } System.exit(job.waitForCompletion(true) ? 0 : 1); }  static Job createSubmittableJob(Configuration conf, String[] args); static void main(String[] args);  }