@Test public void testAction() throws Exception { Path path = new Path("/test/small_files/"); dfs.mkdirs(path); long sumFileLen = 0L; List<String> smallFileList = new ArrayList<>(); for (int i = 0; i < 3; i++) { String fileName = "/test/small_files/file_" + i; FSDataOutputStream out = dfs.create(new Path(fileName), (short) 1); long fileLen = 10 + (int) (Math.random() * 11); byte[] buf = new byte[20]; Random rb = new Random(2018); int bytesRemaining = (int) fileLen; while (bytesRemaining > 0) { rb.nextBytes(buf); int bytesToWrite = (bytesRemaining < buf.length) ? bytesRemaining : buf.length; out.write(buf, 0, bytesToWrite); bytesRemaining -= bytesToWrite; } out.close(); sumFileLen += fileLen; smallFileList.add(fileName); } Assert.assertTrue(dfsClient.exists("/test/small_files/file_0")); Assert.assertTrue(dfsClient.exists("/test/small_files/file_1")); Assert.assertTrue(dfsClient.exists("/test/small_files/file_2")); SmallFileCompactAction smallFileCompactAction = new SmallFileCompactAction(); smallFileCompactAction.setDfsClient(dfsClient); smallFileCompactAction.setContext(smartContext); Map<String , String> args = new HashMap<>(); args.put(SmallFileCompactAction.FILE_PATH , new Gson().toJson(smallFileList)); args.put(SmallFileCompactAction.CONTAINER_FILE, "/test/small_files/container_file"); smallFileCompactAction.init(args); smallFileCompactAction.run(); Assert.assertTrue(dfsClient.exists("/test/small_files/container_file")); HdfsFileStatus containerFileInfo = dfsClient.getFileInfo( "/test/small_files/container_file"); Assert.assertEquals(sumFileLen, containerFileInfo.getLen()); }
@Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.xAttrName = SmartConstants.SMART_FILE_STATE_XATTR_NAME; this.smallFiles = args.get(FILE_PATH); this.containerFile = args.get(CONTAINER_FILE); this.containerFilePermission = args.get(CONTAINER_FILE_PERMISSION); }
SmallFileCompactAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.xAttrName = SmartConstants.SMART_FILE_STATE_XATTR_NAME; this.smallFiles = args.get(FILE_PATH); this.containerFile = args.get(CONTAINER_FILE); this.containerFilePermission = args.get(CONTAINER_FILE_PERMISSION); } }
SmallFileCompactAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.xAttrName = SmartConstants.SMART_FILE_STATE_XATTR_NAME; this.smallFiles = args.get(FILE_PATH); this.containerFile = args.get(CONTAINER_FILE); this.containerFilePermission = args.get(CONTAINER_FILE_PERMISSION); }  }
SmallFileCompactAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.xAttrName = SmartConstants.SMART_FILE_STATE_XATTR_NAME; this.smallFiles = args.get(FILE_PATH); this.containerFile = args.get(CONTAINER_FILE); this.containerFilePermission = args.get(CONTAINER_FILE_PERMISSION); }  @Override void init(Map<String, String> args); @Override float getProgress(); }
SmallFileCompactAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.xAttrName = SmartConstants.SMART_FILE_STATE_XATTR_NAME; this.smallFiles = args.get(FILE_PATH); this.containerFile = args.get(CONTAINER_FILE); this.containerFilePermission = args.get(CONTAINER_FILE_PERMISSION); }  @Override void init(Map<String, String> args); @Override float getProgress(); static final String CONTAINER_FILE; static final String CONTAINER_FILE_PERMISSION; }