abstractdog commented on code in PR #6161:
URL: https://github.com/apache/hive/pull/6161#discussion_r2613180386


##########
ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestTezSessionState.java:
##########
@@ -50,4 +57,37 @@ public void testSymlinkedLocalFilesAreLocalizedOnce() throws 
Exception {
     // local resources point to the same original resource
     Assert.assertEquals(l1.getResource().toPath(), l2.getResource().toPath());
   }
+
+  @Test
+  public void testScratchDirDeletedInTheEventOfExceptionWhileOpeningSession() 
throws Exception {
+    HiveConf hiveConf = new HiveConfForTest(getClass());
+    hiveConf.set("hive.security.authorization.manager",
+        
"org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory");
+    SessionState.start(hiveConf);
+
+    final AtomicReference<String> scratchDirPath = new AtomicReference<>();
+
+    TezSessionState sessionState = new 
TezSessionState(SessionState.get().getSessionId(), hiveConf) {
+      @Override
+      void openInternalUnsafe(boolean isAsync, SessionState.LogHelper console) 
throws TezException, IOException {
+        super.openInternalUnsafe(isAsync, console);
+        // save scratch dir here as it's nullified while calling the cleanup
+        scratchDirPath.set(tezScratchDir.toUri().getPath());
+        throw new RuntimeException("fake exception in openInternalUnsafe");
+      }
+    };
+
+    TezSessionState.HiveResources resources =
+        new TezSessionState.HiveResources(new 
org.apache.hadoop.fs.Path("/tmp"));
+
+    try {
+      sessionState.open(resources);
+      Assert.fail("An exception should have been thrown while calling 
openInternal");
+    } catch (Exception e) {
+      Assert.assertTrue(e.getMessage().equalsIgnoreCase("fake exception in 
openInternalUnsafe"));
+    }
+    LOG.info("Checking if scratch dir exists: {}", scratchDirPath.get());
+    Assert.assertFalse("Scratch dir is not supposed to exist after cleanup: " 
+ scratchDirPath.get(),

Review Comment:
   this is a unit test, which is supposed to fail with an assertion under 
normal testing circumstances



-- 
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]

Reply via email to