/** test main method. Import should print help and call System.exit */ @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> " + "[--starttime=[start] --endtime=[end] " + "[--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> " + "[--starttime=[start] --endtime=[end] " + "[--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); } } finally { System.setErr(oldPrintStream); System.setSecurityManager(SECURITY_MANAGER); } }
private void doBenchmark(RowCounter counter) throws Exception { long start = System.currentTimeMillis(); for (int i = 0; i < runs; i++) { int c = counter.count(query); assertEquals(expectedSize, c); } long end = System.currentTimeMillis(); System.out.printf( "%s: %.2f seconds per run of %d\n", counter.getName(), Float.valueOf(end - start) / 1000 / runs, expectedSize); }
@Test public void test() throws Exception { Configuration conf = new Configuration(); HADOOP_UTIL.setupAndGetTestDir(ITRowCounter.class.getName(), conf).getAbsolutePath(); createFourTabletsTableWithNineRows(TABLE_NAME); String[] args = new String[] { "-D" + CommandLineParser.MASTER_ADDRESSES_KEY + "=" + getMasterAddresses(), TABLE_NAME }; GenericOptionsParser parser = new GenericOptionsParser(conf, args); Job job = RowCounter.createSubmittableJob(parser.getConfiguration(), parser.getRemainingArgs()); assertTrue("Job did not end properly", job.waitForCompletion(true)); assertEquals(9, job.getCounters().findCounter(RowCounter.Counters.ROWS).getValue()); }