majialoong commented on PR #20205:
URL: https://github.com/apache/kafka/pull/20205#issuecomment-3109487326

   Add unit tests `testBuildFilteredLeaderEpochMapModify` in 
`RemoteLogManagerTest` to verify the output consistency of the method before 
and after optimization.
   
   Randomly generate leaderEpochs and iterate 100000 times for verification.
   
   ``` 
       @Test
       public void testBuildFilteredLeaderEpochMapModify() {
           int testIterations = 100000;
   
           for (int i = 0; i < testIterations; i++) {
               TreeMap<Integer, Long> leaderEpochToStartOffset = 
generateRandomLeaderEpochAndStartOffset();
   
               // before optimize
               NavigableMap<Integer, Long> optimizeBefore = 
RemoteLogManager.buildFilteredLeaderEpochMap(leaderEpochToStartOffset);
   
               // after optimize
               NavigableMap<Integer, Long> optimizeAfter = 
RemoteLogManager.buildFilteredLeaderEpochMap2(leaderEpochToStartOffset);
   
               assertEquals(optimizeBefore, optimizeAfter);
           }
       }
   
       private static TreeMap<Integer, Long> 
generateRandomLeaderEpochAndStartOffset() {
           TreeMap<Integer, Long> map = new TreeMap<>();
           Random random = new Random();
           int numEntries = random.nextInt(100000);
           long lastStartOffset = 0;
   
           for (int i = 0; i < numEntries; i++) {
               // generate a leader epoch
               int leaderEpoch = random.nextInt(100000);
               long startOffset;
   
               // generate a random start offset , or use the last start offset
               if (i > 0 && random.nextDouble() < 0.2) {
                   startOffset = lastStartOffset;
               } else {
                   startOffset = Math.abs(random.nextLong()) % 100000;
               }
               lastStartOffset = startOffset;
   
               map.put(leaderEpoch, startOffset);
           }
           return map;
       }
   ```
   
   Command: 
   ``` ./gradlew storage:test --tests RemoteLogManagerTest```
   
   Result:
   All unit tests passed.
   
   <img width="1258" height="424" alt="image" 
src="https://github.com/user-attachments/assets/7d9fc3b5-3bbc-440f-b1cf-3a2a5f97557a";
 />
   <img width="411" height="66" alt="image" 
src="https://github.com/user-attachments/assets/22a0b443-88e8-43d2-a3f2-51266935ed34";
 />
   
   


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