veghlaci05 commented on code in PR #4293:
URL: https://github.com/apache/hive/pull/4293#discussion_r1219703232
##########
ql/src/test/org/apache/hadoop/hive/ql/cleanup/TestCleanupService.java:
##########
@@ -77,6 +83,54 @@ public void
testEventualCleanupService_finishesCleanupBeforeExit() throws IOExce
assertTrue(cleanupService.await(1, TimeUnit.MINUTES));
}
+ /**
+ * Testing behaviour of ClearDanglingScratchDir service over local tmp
files/dirs
+ * @throws Exception
+ */
+ @Test
+ public void localDanglingFilesCleaning() throws Exception {
+ HiveConf conf = new HiveConf();
+ conf.set("fs.default.name", "file:///");
+ 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
+ Path hdfsRootDir = new Path( HiveConf.getVar(conf,
HiveConf.ConfVars.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
+ String localTmpDir = 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");
+ fs.mkdirs(localSessionDir);
+ fs.create(localPipeOutFileRemove);
+ fs.create(localPipeOutFileNotRemove);
+
+ // running only the new method, the main service will be identifying which
session files/dirs are dangling
+ ClearDanglingScratchDir clearDanglingScratchDirMain = new
ClearDanglingScratchDir(false,
+ false, true, hdfsRootDir.toString(), conf);
+ clearDanglingScratchDirMain.run();
+
+ // should remove all except localPipeOutFileNotRemove, because it does not
start with session name
+ 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));
Review Comment:
I meant the following: It would be nice to test if the delete fails for a
particular file for whatever reason (the file is being used, different owner,
etc), the loop does not terminate and the remaining files are still being
cleaned up. I know the method now fulfills this (wit the canWrite check), but
the test should also cover this edge case, so subsequent modifications won't
break this without notice.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]