adixitconfluent commented on code in PR #16431:
URL: https://github.com/apache/kafka/pull/16431#discussion_r1650928682


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -1221,6 +1224,36 @@ public void testReplicaManagerFetchShouldProceed() {
             any(), any(), any(ReplicaQuota.class), any());
     }
 
+    @Test
+    public void testCloseSharePartitionManager() throws Exception {
+        SharePartitionManager sharePartitionManager = 
SharePartitionManagerBuilder.builder()
+                .withShareGroupPersister(mock(Persister.class)).build();
+
+        List<Integer> mockList = new ArrayList<>();
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Allowing first timer task to expire. The timer task will add an 
element to mockList.
+        TestUtils.waitForCondition(
+                () -> mockList.size() == 1,
+                DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS,
+                () -> "Timer task never got timed out.");
+
+        sharePartitionManager.timer().add(createTimerTask(mockList));
+        // Closing the sharePartitionManager closes timer object in 
sharePartitionManager.
+        sharePartitionManager.close();
+        // Allowing second timer task to expire. It won't be able to add an 
element to mockList.
+        Thread.sleep(DEFAULT_MAX_WAIT_TIMER_TASK_TIMEOUT_MS);
+        assertEquals(1, mockList.size());
+    }
+
+    private TimerTask createTimerTask(List<Integer> mockList) {
+        return new TimerTask(100) {
+            @Override

Review Comment:
   since, this functionality is required at 2 places, I thought to create it as 
a different function `createTimerTask`



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

Reply via email to