@Test public void testSetFileLen() throws IOException, InterruptedException { final String srcPath = "/test"; final String file = "file"; dfs.mkdirs(new Path(srcPath)); FSDataOutputStream out = dfs.create(new Path(srcPath + "/" + file)); for (int i = 0; i < 50; i++) { out.writeByte(1); } out.close(); dfs.setXAttr(new Path(srcPath + "/" + file), "user.coldloc", "test".getBytes(), EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE)); FileStatus oldFileStatus = dfs.getFileStatus(new Path(srcPath + "/" + file)); Map<String, byte[]> oldXAttrs = dfs.getXAttrs(new Path(srcPath + "/" + file)); Truncate0Action setLen2ZeroAction = new Truncate0Action(); setLen2ZeroAction.setDfsClient(dfsClient); setLen2ZeroAction.setContext(smartContext); Map<String, String> args = new HashMap<>(); args.put(Truncate0Action.FILE_PATH, srcPath + "/" + file); setLen2ZeroAction.init(args); setLen2ZeroAction.run(); Assert.assertTrue(setLen2ZeroAction.getExpectedAfterRun()); FileStatus newFileStatus = dfs.getFileStatus(new Path(srcPath + "/" + file)); Map<String, byte[]> newXAttrs = dfs.getXAttrs(new Path(srcPath + "/" + file)); Assert.assertTrue(newFileStatus.getLen()==0); Assert.assertTrue(oldFileStatus.getOwner().equals(newFileStatus.getOwner())); Assert.assertTrue(oldFileStatus.getGroup().equals(newFileStatus.getGroup())); Assert.assertTrue(oldFileStatus.getPermission().equals(newFileStatus.getPermission())); Assert.assertTrue(oldFileStatus.getReplication()==newFileStatus.getReplication()); Assert.assertTrue(oldXAttrs.size()==newXAttrs.size()); for(Map.Entry<String, byte[]> oldXAttr : oldXAttrs.entrySet()){ Assert.assertTrue(Arrays.equals(oldXAttr.getValue(),newXAttrs.get(oldXAttr.getKey()))); } }
@Override public void init(Map<String, String> args) { super.init(args); srcPath = args.get(FILE_PATH); }
Truncate0Action extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); srcPath = args.get(FILE_PATH); } }
Truncate0Action extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); srcPath = args.get(FILE_PATH); }  }
Truncate0Action extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); srcPath = args.get(FILE_PATH); }  @Override void init(Map<String, String> args); }
Truncate0Action extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); srcPath = args.get(FILE_PATH); }  @Override void init(Map<String, String> args);  }