FileSize implements IStatistic { public Map<FileSizeConstants, Long> getFileSizesInByte() { EnumMap<FileSizeConstants, Long> fileSizes = new EnumMap<>(FileSizeConstants.class); for (FileSizeConstants kinds : MonitorConstants.FileSizeConstants.values()) { if (kinds.equals(FileSizeConstants.SYS)) { fileSizes.put(kinds, collectSeqFileSize(fileSizes, kinds)); } else { File file = SystemFileFactory.INSTANCE.getFile(kinds.getPath()); if (file.exists()) { try { fileSizes.put(kinds, FileUtils.sizeOfDirectory(file)); } catch (Exception e) { logger.error("Meet error while trying to get {} size with dir {} .", kinds, kinds.getPath(), e); fileSizes.put(kinds, ABNORMAL_VALUE); } } else { fileSizes.put(kinds, INIT_VALUE_IF_FILE_NOT_EXIST); } } } return fileSizes; } private  FileSize(); @Override Map<String, TSRecord> getAllStatisticsValue(); @Override void registerStatMetadata(); @Override List<String> getAllPathForStatistic(); @Override Map<String, AtomicLong> getStatParamsHashMap(); static FileSize getInstance(); Map<FileSizeConstants, Long> getFileSizesInByte();  }
@Ignore @Test public void testGetFileSizesInByte() { long dataSizeBefore; long dataSizeAfter; boolean isWriteSuccess = true; File testFile = new File(TEST_FILE_PATH); if (testFile.exists()) { try { Files.delete(testFile.toPath()); } catch (IOException e) { isWriteSuccess = false; e.printStackTrace(); } } try { if (!testFile.createNewFile()) { isWriteSuccess = false; } } catch (IOException e) { e.printStackTrace(); } dataSizeBefore = FileSize.getInstance().getFileSizesInByte().get(FileSizeConstants.SYS); byte[] contentInBytes = TEST_FILE_CONTENT.getBytes(); try (FileOutputStream fileOutputStream = new FileOutputStream(testFile)) { fileOutputStream.write(contentInBytes); fileOutputStream.flush(); } catch (IOException e) { isWriteSuccess = false; e.printStackTrace(); } dataSizeAfter = FileSize.getInstance().getFileSizesInByte().get(FileSizeConstants.SYS); long deltaSize = dataSizeAfter - dataSizeBefore; if (isWriteSuccess) { assertEquals(contentInBytes.length, deltaSize); } else { assertEquals(0, deltaSize); } }