apoorvmittal10 commented on code in PR #16431:
URL: https://github.com/apache/kafka/pull/16431#discussion_r1650896425
##########
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);
Review Comment:
I don't think it's a good idea to sleep. Can't we use mocktimer?
##########
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:
nit: It can be a lambda method.
##########
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();
Review Comment:
Why do we require a persister mock when we are not using the mock instance?
--
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]