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


##########
core/src/test/java/kafka/server/share/SharePartitionTest.java:
##########
@@ -5419,6 +5419,72 @@ public void 
testMaybeInitializeWhenReadStateRpcReturnsZeroAvailableRecords() {
         assertEquals(734, sharePartition.endOffset());
     }
 
+    @Test
+    public void testAcquireWithWriteShareGroupStateDelay() {
+        Persister persister = Mockito.mock(Persister.class);
+        mockPersisterReadStateMethod(persister);
+        SharePartition sharePartition = SharePartitionBuilder.builder()
+            .withPersister(persister)
+            .withState(SharePartitionState.ACTIVE)
+            .build();
+
+        // Mock persister writeState method so that 
sharePartition.isWriteShareGroupStateSuccessful() returns true with a delay of 
5 sec.
+        WriteShareGroupStateResult writeShareGroupStateResult = 
Mockito.mock(WriteShareGroupStateResult.class);
+        
Mockito.when(writeShareGroupStateResult.topicsData()).thenReturn(Collections.singletonList(
+            new TopicData<>(TOPIC_ID_PARTITION.topicId(), 
Collections.singletonList(
+                PartitionFactory.newPartitionErrorData(0, Errors.NONE.code(), 
Errors.NONE.message())))));
+        Mockito.doAnswer(invocationOnMock -> {
+            CompletableFuture<WriteShareGroupStateResult> future = new 
CompletableFuture<>();
+            // Simulate a delay of 5 sec.
+            CompletableFuture.runAsync(() -> {
+                try {
+                    TimeUnit.SECONDS.sleep(5);

Review Comment:
   Hi @AndrewJSchofield , I have changed the way the future is getting 
completed for `persister.writeState()` function call and added the 
corresponding assertions before and after completion of the async function 
call. 



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

Reply via email to