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


##########
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:
   I would tend to avoid this kind of pattern if possible. What you really want 
is to execute the assertions in the rest of this test before the future is 
completed. You could code that in a more straightforward way if you used 
something like a countdown latch so you could explicitly cause the completion 
of the future, and then even do some more checking once it's completed to 
ensure that everything ended up in the right state.



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