@Override protected void processPath(PathData src) throws IOException { StringBuilder outputString = new StringBuilder(); if (showQuotasAndUsageOnly || showQuotabyType) { QuotaUsage usage = src.fs.getQuotaUsage(src.path); outputString.append(usage.toString( isHumanReadable(), showQuotabyType, storageTypes)); } else { ContentSummary summary = src.fs.getContentSummary(src.path); outputString.append(summary.toString( showQuotas, isHumanReadable(), excludeSnapshots)); } if(displayECPolicy){ ContentSummary summary = src.fs.getContentSummary(src.path); if(!summary.getErasureCodingPolicy().equals("Replicated")){ outputString.append("EC:"); } outputString.append(summary.getErasureCodingPolicy()); outputString.append(" "); } outputString.append(src); out.println(outputString.toString()); }
@Test public void processOptionsAll() { LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-h"); options.add("dummy"); Count count = new Count(); count.processOptions(options); assertTrue(count.isShowQuotas()); assertTrue(count.isHumanReadable()); }
@Test public void processPathNoQuotasHuman() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PathData pathData = new PathData(path.toString(), conf); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-h"); options.add("dummy"); count.processOptions(options); count.processPath(pathData); verify(out).println(HUMAN + NO_QUOTAS + path.toString()); }
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); } }
@Test public void getCommandName() { Count count = new Count(); String actual = count.getCommandName(); String expected = "count"; assertEquals("Count.getCommandName", expected, actual); }
@Test public void isDeprecated() { Count count = new Count(); boolean actual = count.isDeprecated(); boolean expected = false; assertEquals("Count.isDeprecated", expected, actual); }
@Test public void getReplacementCommand() { Count count = new Count(); String actual = count.getReplacementCommand(); String expected = null; assertEquals("Count.getReplacementCommand", expected, actual); }
@Override protected void run(Path path) throws IOException { FileSystem fs = path.getFileSystem(getConf()); System.out.println(fs.getContentSummary(path).toString(qOption) + path); } }
@Test public void processOptionsHumanReadable() { LinkedList<String> options = new LinkedList<String>(); options.add("-h"); options.add("dummy"); Count count = new Count(); count.processOptions(options); assertFalse(count.isShowQuotas()); assertTrue(count.isHumanReadable()); }
@Test public void processPathNoQuotas() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PathData pathData = new PathData(path.toString(), conf); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("dummy"); count.processOptions(options); count.processPath(pathData); verify(out).println(BYTES + NO_QUOTAS + path.toString()); verifyNoMoreInteractions(out); }
@Test public void getCommandName() { Count count = new Count(); String actual = count.getCommandName(); String expected = "count"; assertEquals("Count.getCommandName", expected, actual); }
@Test public void isDeprecated() { Count count = new Count(); boolean actual = count.isDeprecated(); boolean expected = false; assertEquals("Count.isDeprecated", expected, actual); }
@Test public void getReplacementCommand() { Count count = new Count(); String actual = count.getReplacementCommand(); String expected = null; assertEquals("Count.getReplacementCommand", expected, actual); }