yuqi1129 commented on code in PR #9559:
URL: https://github.com/apache/gravitino/pull/9559#discussion_r2647701501
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -114,23 +114,53 @@ public static void setUp() throws IllegalAccessException {
JobManager jm = new JobManager(config, entityStore, idGenerator,
jobExecutor);
jobManager = Mockito.spy(jm);
+ // Stop the background schedulers to prevent interference with tests
+ ScheduledExecutorService cleanUpExecutor =
+ (ScheduledExecutorService) FieldUtils.readField(jobManager,
"cleanUpExecutor", true);
+ if (cleanUpExecutor != null) {
+ cleanUpExecutor.shutdownNow();
+ }
+
+ cleanUpExecutor.shutdown();
+ try {
+ if (!cleanUpExecutor.awaitTermination(100, TimeUnit.MILLISECONDS)) {
+ cleanUpExecutor.shutdownNow();
+ }
+ } catch (InterruptedException e) {
+ cleanUpExecutor.shutdownNow();
+ Thread.currentThread().interrupt();
+ }
+
+ ScheduledExecutorService statusPullExecutor =
+ (ScheduledExecutorService) FieldUtils.readField(jobManager,
"statusPullExecutor", true);
+ if (statusPullExecutor != null) {
+ statusPullExecutor.shutdown();
+ try {
+ if (!statusPullExecutor.awaitTermination(100, TimeUnit.MILLISECONDS)) {
+ statusPullExecutor.shutdownNow();
+ }
+ } catch (InterruptedException e) {
+ statusPullExecutor.shutdownNow();
+ Thread.currentThread().interrupt();
+ }
+ }
Review Comment:
> Why do you shutdown the executor before each test, not after? This doesn't
logically make sense.
It's suggested by the Copilot, and those thread pools were not used in the
tests and can be shut down beforehand to reduce possible interference with the
tests.
> do you need to do this here using reflection?
They are `private` values, of course, we can also check them as the package
access level to avoid reflection.
--
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]