deniskuzZ commented on code in PR #4403: URL: https://github.com/apache/hive/pull/4403#discussion_r1226831651
########## itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/session/TestClearDanglingScratchDir.java: ########## @@ -129,4 +132,75 @@ public void testClearDanglingScratchDir() throws Exception { Assert.assertEquals(StringUtils.countMatches(stderr.toString(), "removed"), 1); ss.close(); } + + /** + * Testing behaviour of ClearDanglingScratchDir service over local tmp files/dirs + * @throws Exception + */ + @Test + public void testLocalDanglingFilesCleaning() throws Exception { + HiveConf conf = new HiveConf(); + conf.set("fs.default.name", "file:///"); + String tmpDir = System.getProperty("test.tmp.dir"); + conf.set("hive.exec.scratchdir", tmpDir + "/hive-27317-hdfsscratchdir"); + conf.set("hive.exec.local.scratchdir", tmpDir + "/hive-27317-localscratchdir"); + FileSystem fs = FileSystem.get(conf); + + // constants + String appId = "appId_" + System.currentTimeMillis(); + String userName = System.getProperty("user.name"); + String hdfs = "hdfs"; + String inuse = "inuse.lck"; + String l = File.separator; + + // simulating hdfs dangling dir and its inuse.lck file + // Note: Give scratch dirs all the write permissions + FsPermission allPermissions = new FsPermission((short)00777); + Path scratchDir = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIR)); + Utilities.createDirsWithPermission(conf, scratchDir, allPermissions, true); + Path hdfsRootDir = new Path(scratchDir + l + userName + l + hdfs); + Path hdfsSessionDir = new Path(hdfsRootDir + l + userName + l + appId); + Path hdfsSessionLock = new Path(hdfsSessionDir + l + inuse); + fs.create(hdfsSessionLock); + + // simulating local dangling files + Path localTmpDir = new Path (HiveConf.getVar(conf, HiveConf.ConfVars.LOCALSCRATCHDIR)); + Path localSessionDir = new Path(localTmpDir + l + appId); + Path localPipeOutFileRemove = new Path(localTmpDir + l + + appId + "-started-with-session-name.pipeout"); + Path localPipeOutFileNotRemove = new Path(localTmpDir + l + + "not-started-with-session-name-" + appId + ".pipeout"); + Path localPipeOutFileFailRemove = new Path(localTmpDir + l + + appId + "-started-with-session-name-but-fail-delete.pipeout"); + + // Create dirs/files + Utilities.createDirsWithPermission(conf, localSessionDir, allPermissions, true); + fs.create(localPipeOutFileRemove); + fs.create(localPipeOutFileNotRemove); + fs.create(localPipeOutFileFailRemove); + + // Set permission for localPipeOutFileFailRemove file as not writable + // This will avoid file to be deleted as we check whether it is writable or not first + fs.setPermission(localPipeOutFileFailRemove, FsPermission.valueOf("-r--r--r--")); + + // the main service will be identifying which session files/dirs are dangling + ClearDanglingScratchDir clearDanglingScratchDirMain = new ClearDanglingScratchDir(false, + false, true, hdfsRootDir.toString(), conf); + clearDanglingScratchDirMain.run(); + + // localSessionDir and localPipeOutFileRemove should be removed + // localPipeOutFileNotRemove and localPipeOutFileFailRemove should not be removed + Assert.assertFalse("Local session dir '" + localSessionDir + + "' still exists, should have been removed!", fs.exists(localSessionDir)); + Assert.assertFalse("Local .pipeout file '" + localPipeOutFileRemove + + "' still exists, should have been removed!", fs.exists(localPipeOutFileRemove)); + Assert.assertTrue("Local .pipeout file '" + localPipeOutFileNotRemove + + "' does not exist, should have not been removed!", fs.exists(localPipeOutFileNotRemove)); + Assert.assertTrue("Local .pipeout file '" + localPipeOutFileFailRemove + + "' does not exist, should have not been removed!", fs.exists(localPipeOutFileFailRemove)); + + // Clean-up + fs.delete(localTmpDir, true); Review Comment: should it be called within finally or in @After method? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org