private void runCount(String path, long dirs, long files, Configuration conf ) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); PrintStream oldOut = System.out; System.setOut(out); Scanner in = null; String results = null; try { new Count(new String[]{path}, 0, conf).runAll(); results = bytes.toString(); in = new Scanner(results); assertEquals(dirs, in.nextLong()); assertEquals(files, in.nextLong()); } finally { if (in!=null) in.close(); IOUtils.closeStream(out); System.setOut(oldOut); System.out.println("results:\n" + results); } }
public void testCount() throws Exception { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null); DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem(); FsShell shell = new FsShell(); shell.setConf(conf); try { String root = createTree(dfs, "count"); // Verify the counts runCount(root, 2, 4, conf); runCount(root + "2", 2, 1, conf); runCount(root + "2/f1", 0, 1, conf); runCount(root + "2/sub", 1, 0, conf); final FileSystem localfs = FileSystem.getLocal(conf); Path localpath = new Path(TEST_ROOT_DIR, "testcount"); localpath = localpath.makeQualified(localfs); localfs.mkdirs(localpath); final String localstr = localpath.toString(); System.out.println("localstr=" + localstr); runCount(localstr, 1, 0, conf); assertEquals(0, new Count(new String[]{root, localstr}, 0, conf).runAll()); } finally { try { dfs.close(); } catch (Exception e) { } cluster.shutdown(); } }
public void testCount() throws Exception { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem(); FsShell shell = new FsShell(); shell.setConf(conf); try { String root = createTree(dfs, "count"); // Verify the counts runCount(root, 2, 4, conf); runCount(root + "2", 2, 1, conf); runCount(root + "2/f1", 0, 1, conf); runCount(root + "2/sub", 1, 0, conf); final FileSystem localfs = FileSystem.getLocal(conf); Path localpath = new Path(TEST_ROOT_DIR, "testcount"); localpath = localpath.makeQualified(localfs.getUri(), localfs.getWorkingDirectory()); localfs.mkdirs(localpath); final String localstr = localpath.toString(); System.out.println("localstr=" + localstr); runCount(localstr, 1, 0, conf); assertEquals(0, new Count(new String[]{root, localstr}, 0, conf).runAll()); } finally { try { dfs.close(); } catch (Exception e) { } cluster.shutdown(); } }