You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "m1a2st (via GitHub)" <gi...@apache.org> on 2026/06/22 15:26:14 UTC

[PR] MINOR: move DelayedProduceTest to server module [kafka]

m1a2st opened a new pull request, #22638:
URL: https://github.com/apache/kafka/pull/22638

   Rewite this test to Java, and move it to server module
   


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Move DelayedProduceTest to server module [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22638:
URL: https://github.com/apache/kafka/pull/22638#discussion_r3459874862


##########
server/src/test/java/org/apache/kafka/server/purgatory/DelayedProduceTest.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.purgatory;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+import org.apache.kafka.server.util.ServerTestUtils;
+
+import com.yammer.metrics.core.MetricName;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.function.Predicate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DelayedProduceTest {
+
+    @AfterEach
+    public void tearDown() {
+        ServerTestUtils.clearYammerMetrics();
+    }
+
+    @Test
+    public void testRemovePartitionMetrics() {
+        TopicPartition partition = new TopicPartition("test-topic", 0);
+
+        // Record an expiration so the partition metric is created
+        DelayedProduce.recordExpiration(partition);
+
+        // Verify the partition metric exists in the registry
+        Predicate<MetricName> isPartitionMetric = name ->
+                name.getMBeanName().contains("topic=test-topic")
+                        && name.getMBeanName().contains("partition=0")
+                        && name.getMBeanName().contains("name=ExpiresPerSec");
+        assertTrue(

Review Comment:
   Could we assert the result against `List.of` instead? It provides a more meaningful error message if the test fails
   
   ```java
           assertNotEquals(List.of(), KafkaYammerMetrics.defaultRegistry()
               .allMetrics()
               .keySet()
               .stream()
               .filter(isPartitionMetric).toList(), "Partition metric should exist after recordExpiration");
   ```



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Move DelayedProduceTest to server module [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #22638:
URL: https://github.com/apache/kafka/pull/22638


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Move DelayedProduceTest to server module [kafka]

Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on PR #22638:
URL: https://github.com/apache/kafka/pull/22638#issuecomment-4785149524

   Thanks for @chia7712 review, I have addressed all comments


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Move DelayedProduceTest to server module [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22638:
URL: https://github.com/apache/kafka/pull/22638#issuecomment-4779325838

   @m1a2st would you mind expanding the unit tests in this PR? The constructor, `tryComplete` and `onExpiration` need some unit tests I think


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: move DelayedProduceTest to server module [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22638:
URL: https://github.com/apache/kafka/pull/22638#discussion_r3457424897


##########
server/src/test/java/org/apache/kafka/server/purgatory/DelayedProduceTest.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.purgatory;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+import org.apache.kafka.server.util.ServerTestUtils;
+
+import com.yammer.metrics.core.MetricName;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.function.Predicate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DelayedProduceTest {
+
+    @AfterEach
+    public void tearDown() {
+        ServerTestUtils.clearYammerMetrics();
+    }
+
+    @Test
+    public void testRemovePartitionMetrics() {
+        TopicPartition partition = new TopicPartition("test-topic", 0);
+
+        // Record an expiration so the partition metric is created
+        DelayedProduce.recordExpiration(partition);
+
+        // Verify the partition metric exists in the registry
+        Predicate<MetricName> isPartitionMetric = name ->
+                name.getMBeanName().contains("topic=test-topic")
+                        && name.getMBeanName().contains("partition=0")
+                        && name.getMBeanName().contains("name=ExpiresPerSec");
+        assertTrue(
+                KafkaYammerMetrics.defaultRegistry()
+                        .allMetrics()
+                        .keySet()
+                        .stream()
+                        .anyMatch(isPartitionMetric),
+                "Partition metric should exist after recordExpiration"
+        );
+
+        Predicate<MetricName> isAggregateMetric = name ->
+                name.getMBeanName().contains("name=ExpiresPerSec")
+                        && name.getMBeanName().contains("DelayedProduceMetrics")
+                        && !name.getMBeanName().contains("topic=");
+        long aggregateCountBefore = KafkaYammerMetrics.defaultRegistry()
+                .allMetrics()
+                .keySet()
+                .stream()
+                .filter(isAggregateMetric).count();
+
+        // Remove the partition metric
+        DelayedProduce.removePartitionMetrics(partition);
+
+        // Verify the partition metric is removed from the registry
+        assertFalse(
+                KafkaYammerMetrics.defaultRegistry()

Review Comment:
   Could you adjust the indents?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org