homatthew commented on code in PR #3711:
URL: https://github.com/apache/gobblin/pull/3711#discussion_r1243158430


##########
gobblin-cluster/src/test/java/org/apache/gobblin/cluster/GobblinHelixJobLauncherTest.java:
##########
@@ -299,6 +301,25 @@ public void testTimeout() throws Exception {
     Assert.assertThrows(JobException.class, () -> 
gobblinHelixJobLauncher.launchJobImpl(null));
   }
 
+  public void testExitCancelsJob() throws Exception {
+    final ConcurrentHashMap<String, Boolean> runningMap = new 
ConcurrentHashMap<>();
+
+    final Properties props = generateJobProperties(this.baseConfig, 
"testTimeoutTest", "_12345");
+    
props.setProperty(GobblinClusterConfigurationKeys.HELIX_WORKFLOW_SUBMISSION_TIMEOUT_SECONDS,
 "0");
+    
props.setProperty(GobblinClusterConfigurationKeys.HELIX_WORKFLOW_CANCEL_ON_EXIT,
 "true");
+
+    final GobblinHelixJobLauncher gobblinHelixJobLauncher = 
this.closer.register(
+        new GobblinHelixJobLauncher(props, this.helixManager, this.appWorkDir, 
ImmutableList.<Tag<?>>of(), runningMap,
+            java.util.Optional.empty()));
+
+    // The launchJob will throw an exception (see testTimeout test) and we 
expect the launcher to swallow the exception,
+    // then call still properly call cancel. We use the listener to confirm 
the cancel hook was correctly called once
+    JobListener mockListener = Mockito.mock(JobListener.class);
+    gobblinHelixJobLauncher.launchJob(mockListener);
+    
Mockito.verify(mockListener).onJobCancellation(Mockito.any(JobContext.class));

Review Comment:
   Fun fact: verify without a parameter verifies the method is called exactly 
once! 😃



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

Reply via email to