You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by mi...@apache.org on 2026/09/21 17:59:02 UTC

(kafka) branch 4.3 updated: MINOR: Fix share group failing tests (#23540)

This is an automated email from the ASF dual-hosted git repository.

apoorvmittal10 pushed a commit to branch 4.3
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/4.3 by this push:
     new 7f96224cf66 MINOR: Fix share group failing tests (#23540)
7f96224cf66 is described below

commit 7f96224cf6689e8a4c807f577cdfa3c800903ae4
Author: Apoorv Mittal <ap...@gmail.com>
AuthorDate: Mon Sep 21 18:48:12 2026 +0100

    MINOR: Fix share group failing tests (#23540)
    
    The yammerMetricValue implementation in trunk is changed and moved to
    another class where it propagates the exception while current
    implementation swallows. Hence moved the check to keep the changes
    minimal and least different from trunk.
    
    The SharePartitionManager fix is due to different Mockito versions and
    default return behaviour from trunk to current branch.
    
    Reviewers: TengYao Chi <fr...@apache.org>
---
 .../server/share/SharePartitionManagerTest.java     |  2 ++
 .../java/kafka/server/share/SharePartitionTest.java | 21 ++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/core/src/test/java/kafka/server/share/SharePartitionManagerTest.java b/core/src/test/java/kafka/server/share/SharePartitionManagerTest.java
index d7ed198104c..979c0518e57 100644
--- a/core/src/test/java/kafka/server/share/SharePartitionManagerTest.java
+++ b/core/src/test/java/kafka/server/share/SharePartitionManagerTest.java
@@ -367,6 +367,8 @@ public class SharePartitionManagerTest {
             .build();
 
         SharePartition sharePartition = mock(SharePartition.class);
+        when(sharePartition.releaseAcquiredRecords(any())).thenReturn(CompletableFuture.completedFuture(null));
+
         ExecutorService executor = Executors.newFixedThreadPool(2);
         try {
             for (int i = 0; i < iterations; i++) {
diff --git a/core/src/test/java/kafka/server/share/SharePartitionTest.java b/core/src/test/java/kafka/server/share/SharePartitionTest.java
index 9d03ce6102f..13b7fc600b8 100644
--- a/core/src/test/java/kafka/server/share/SharePartitionTest.java
+++ b/core/src/test/java/kafka/server/share/SharePartitionTest.java
@@ -54,6 +54,7 @@ import org.apache.kafka.common.utils.Time;
 import org.apache.kafka.coordinator.group.GroupConfig;
 import org.apache.kafka.coordinator.group.GroupConfigManager;
 import org.apache.kafka.coordinator.group.ShareGroupAutoOffsetResetStrategy;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
 import org.apache.kafka.server.share.acknowledge.ShareAcknowledgementBatch;
 import org.apache.kafka.server.share.fetch.AcquisitionLockTimerTask;
 import org.apache.kafka.server.share.fetch.DelayedShareFetchGroupKey;
@@ -88,7 +89,6 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.NoSuchElementException;
 import java.util.Optional;
 import java.util.OptionalInt;
 import java.util.OptionalLong;
@@ -12621,8 +12621,13 @@ public class SharePartitionTest {
 
         sharePartition.close();
         // close must deregister the metrics so the registry no longer references the partition.
-        assertThrows(NoSuchElementException.class, () -> yammerMetricValue(SharePartitionMetrics.IN_FLIGHT_MESSAGE_COUNT));
-        assertThrows(NoSuchElementException.class, () -> yammerMetricValue(SharePartitionMetrics.IN_FLIGHT_BATCH_COUNT));
+        // yammerMetricValue() cannot be used here as it swallows a missing metric and returns 0,
+        // which would make this assertion pass even if close() failed to deregister anything -
+        // check the registry directly instead.
+        assertTrue(KafkaYammerMetrics.defaultRegistry().allMetrics().keySet().stream()
+            .noneMatch(m -> m.getMBeanName().contains(SharePartitionMetrics.IN_FLIGHT_MESSAGE_COUNT)));
+        assertTrue(KafkaYammerMetrics.defaultRegistry().allMetrics().keySet().stream()
+            .noneMatch(m -> m.getMBeanName().contains(SharePartitionMetrics.IN_FLIGHT_BATCH_COUNT)));
 
         // close must be idempotent - a second call should not throw even though the metrics are gone.
         assertDoesNotThrow(sharePartition::close);
@@ -12640,8 +12645,14 @@ public class SharePartitionTest {
         assertEquals(0, yammerMetricValue(SharePartitionMetrics.IN_FLIGHT_MESSAGE_COUNT).intValue());
 
         sharePartition.close();
-        assertThrows(NoSuchElementException.class, () -> yammerMetricValue(SharePartitionMetrics.IN_FLIGHT_MESSAGE_COUNT));
-        assertThrows(NoSuchElementException.class, () -> yammerMetricValue(SharePartitionMetrics.IN_FLIGHT_BATCH_COUNT));
+        // close must deregister the metrics so the registry no longer references the partition.
+        // yammerMetricValue() cannot be used here as it swallows a missing metric and returns 0,
+        // which would make this assertion pass even if close() failed to deregister anything -
+        // check the registry directly instead.
+        assertTrue(KafkaYammerMetrics.defaultRegistry().allMetrics().keySet().stream()
+            .noneMatch(m -> m.getMBeanName().contains(SharePartitionMetrics.IN_FLIGHT_MESSAGE_COUNT)));
+        assertTrue(KafkaYammerMetrics.defaultRegistry().allMetrics().keySet().stream()
+            .noneMatch(m -> m.getMBeanName().contains(SharePartitionMetrics.IN_FLIGHT_BATCH_COUNT)));
     }
 
     private static GroupConfigManager groupConfigManagerWithRenewDisabled() {