Count extends FsCommand { @Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, OPTION_QUOTA, OPTION_HUMAN, OPTION_HEADER, OPTION_QUOTA_AND_USAGE, OPTION_EXCLUDE_SNAPSHOT, OPTION_ECPOLICY, OPTION_SNAPSHOT_COUNT); cf.addOptionWithValue(OPTION_TYPE); cf.parse(args); if (args.isEmpty()) { args.add("."); } showQuotas = cf.getOpt(OPTION_QUOTA); humanReadable = cf.getOpt(OPTION_HUMAN); showQuotasAndUsageOnly = cf.getOpt(OPTION_QUOTA_AND_USAGE); excludeSnapshots = cf.getOpt(OPTION_EXCLUDE_SNAPSHOT); displayECPolicy = cf.getOpt(OPTION_ECPOLICY); showSnapshot = cf.getOpt(OPTION_SNAPSHOT_COUNT); if (showQuotas || showQuotasAndUsageOnly) { String types = cf.getOptValue(OPTION_TYPE); if (null != types) { showQuotabyType = true; storageTypes = getAndCheckStorageTypes(types); } else { showQuotabyType = false; } if (excludeSnapshots) { out.println(OPTION_QUOTA + " or " + OPTION_QUOTA_AND_USAGE + " option " + "is given, the -x option is ignored."); excludeSnapshots = false; } } if (cf.getOpt(OPTION_HEADER)) { StringBuilder headString = new StringBuilder(); if (showQuotabyType) { headString.append(QuotaUsage.getStorageTypeHeader(storageTypes)); } else { if (showQuotasAndUsageOnly) { headString.append(QuotaUsage.getHeader()); } else { headString.append(ContentSummary.getHeader(showQuotas)); } } if(displayECPolicy){ headString.append("ERASURECODING_POLICY "); } if (showSnapshot) { headString.append(ContentSummary.getSnapshotHeader()); } headString.append("PATHNAME"); out.println(headString.toString()); } } Count(); @Deprecated  Count(String[] cmd, int pos, Configuration conf); static void registerCommands(CommandFactory factory); static final String NAME; static final String USAGE; static final String DESCRIPTION; }
@Test public void processOptionsHeaderNoQuotas() { LinkedList<String> options = new LinkedList<String>(); options.add("-v"); options.add("dummy"); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; count.processOptions(options); String noQuotasHeader = " DIR_COUNT FILE_COUNT CONTENT_SIZE PATHNAME"; verify(out).println(noQuotasHeader); verifyNoMoreInteractions(out); }
@Test public void processOptionsHeaderWithQuotas() { LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-v"); options.add("dummy"); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; count.processOptions(options); String withQuotasHeader = " QUOTA REM_QUOTA SPACE_QUOTA REM_SPACE_QUOTA " + " DIR_COUNT FILE_COUNT CONTENT_SIZE PATHNAME"; verify(out).println(withQuotasHeader); verifyNoMoreInteractions(out); }
@Test public void processPathWithQuotasByStorageTypesHeader() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-v"); options.add("-t"); options.add("all"); options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + " SSD_QUOTA REM_SSD_QUOTA DISK_QUOTA REM_DISK_QUOTA " + "ARCHIVE_QUOTA REM_ARCHIVE_QUOTA PROVIDED_QUOTA REM_PROVIDED_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); }
@Test public void processPathWithQuotasBySSDStorageTypesHeader() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-v"); options.add("-t"); options.add("SSD"); options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = " SSD_QUOTA REM_SSD_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); }
@Test public void processPathWithQuotasByQTVH() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-t"); options.add("-v"); options.add("-h"); options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + " SSD_QUOTA REM_SSD_QUOTA " + " DISK_QUOTA REM_DISK_QUOTA " + "ARCHIVE_QUOTA REM_ARCHIVE_QUOTA " + "PROVIDED_QUOTA REM_PROVIDED_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); }
@Test public void processPathWithQuotasByMultipleStorageTypes() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-v"); options.add("-t"); options.add("SSD,DISK"); options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = " SSD_QUOTA REM_SSD_QUOTA " + " DISK_QUOTA REM_DISK_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); }
@Test public void processPathWithSnapshotHeader() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-s"); options.add("-v"); options.add("dummy"); count.processOptions(options); String withSnapshotHeader = " DIR_COUNT FILE_COUNT CONTENT_SIZE " + " SNAPSHOT_LENGTH SNAPSHOT_FILE_COUNT " + " SNAPSHOT_DIR_COUNT SNAPSHOT_SPACE_CONSUMED PATHNAME"; verify(out).println(withSnapshotHeader); verifyNoMoreInteractions(out); }