linghengqian commented on code in PR #2475: URL: https://github.com/apache/shardingsphere-elasticjob/pull/2475#discussion_r2338888302
########## test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java: ########## @@ -305,4 +308,45 @@ void testShardingStatisticsAPI() { }); job.shutdown(); } + + @Test + void testWhenShutdownThenTaskCanCaptureInterruptedException() throws Exception { + testCaptureInterruptedException(1); + testCaptureInterruptedException(2); + } + + private void testCaptureInterruptedException(final int shardingTotalCount) throws Exception { + String jobName = "testTaskCaptureInterruptedTask" + shardingTotalCount; + AtomicBoolean captured = new AtomicBoolean(false); + AtomicBoolean running = new AtomicBoolean(false); + LocalTime oneSecondsLater = LocalTime.now().plusSeconds(1); + String cronExpression = String.format("%d %d %d * * ?", oneSecondsLater.getSecond(), oneSecondsLater.getMinute(), oneSecondsLater.getHour()); + SimpleJob captureInterruptedTask = shardingContext -> { + try { + running.set(true); + + while (true) { + if (Thread.currentThread().isInterrupted()) { + captured.set(true); + running.set(false); + break; + } Review Comment: - From what I can see in my testing, the unit test never actually executes the logic inside the `if` block. Does this make any sense? -- 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: notifications-unsubscr...@shardingsphere.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org