olalamichelle commented on code in PR #14078: URL: https://github.com/apache/kafka/pull/14078#discussion_r1299213816
########## clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/secured/RefreshingHttpsJwksTest.java: ########## @@ -195,4 +231,68 @@ public String getBody() { return Mockito.spy(httpsJwks); } + /** + * A mock ScheduledExecutorService just for the test. Note that this is not a generally reusable mock as it does not + * implement some interfaces like scheduleWithFixedDelay, etc. And it does not return ScheduledFuture correctly. + */ + private class MockExecutorService implements MockTime.Listener { Review Comment: Yes it is very similar but I have to create my own mock for 2 reasons: 1. MockScheduler.schedule method does not take a period parameter which schedules a periodical task. I can add this function to MockScheduler but then I will also implement the corresponding addWaiter which is pretty much just put all the MockExecutorService code into MockScheduler. I don't think it is a good idea since it will make MockScheduler very cumbersome. Moreover, if I do that its schedule interface cannot take a ExecutorService parameter and it needs to take care of the execution itself inside. See below for more details. 2. MockScheduler is really just a scheduler that does not take care of the execution. It just submits tasks to the executor service. The flakiness of the test comes from the real clock based executor service where, because of CPU scheduling, cannot be 100% accurate on timings. We need a callback-based one in the test to make sure it is reliable. It is just the logic (since there principles are the same) behind a mock scheduler and a mock executor service is the same that we have to use MockTime and be callback-based so they are very similar. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org