You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "showuon (via GitHub)" <gi...@apache.org> on 2024/03/22 00:33:59 UTC

Re: [PR] KAFKA-16323: fix testRemoteFetchExpiresPerSecMetric [kafka]

showuon commented on code in PR #15463:
URL: https://github.com/apache/kafka/pull/15463#discussion_r1534892451


##########
core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala:
##########
@@ -4164,16 +4166,12 @@ class ReplicaManagerTest {
         mock(classOf[FetchDataInfo])
       }).when(spyRLM).read(any())
 
-      // Get the current type=DelayedRemoteFetchMetrics,name=ExpiresPerSec metric value before fetching
-      val curExpiresPerSec = safeYammerMetricValue("type=DelayedRemoteFetchMetrics,name=ExpiresPerSec").asInstanceOf[Long]
       replicaManager.fetchMessages(params, Seq(tidp0 -> new PartitionData(topicId, fetchOffset, 0, 100000, Optional.of[Integer](leaderEpoch), Optional.of[Integer](leaderEpoch))), UnboundedQuota, fetchCallback)
       // advancing the clock to expire the delayed remote fetch
       timer.advanceClock(2000L)
 
-      // verify the metric value is incremented since the delayed remote fetch is expired
-      TestUtils.waitUntilTrue(() => curExpiresPerSec + 1 == safeYammerMetricValue("type=DelayedRemoteFetchMetrics,name=ExpiresPerSec").asInstanceOf[Long],
-        "The ExpiresPerSec value is not incremented. Current value is: " +
-          safeYammerMetricValue("type=DelayedRemoteFetchMetrics,name=ExpiresPerSec").asInstanceOf[Long])
+      // verify the DelayedRemoteFetchMetrics.expiredRequestMeter.mark is called since the delayed remote fetch is expired
+      verify(mockDelayedRemoteFetchMetricsMeter, times(1)).mark()

Review Comment:
   Yes, it indeed fixed the issue. But I found there's a better way to verify it without changing `expiredRequestMeter` from `val` to `var`. We can verify like this:
   
   ```
   val curExpiresPerSec = DelayedRemoteFetchMetrics.expiredRequestMeter.count()
   replicaManager.fetchMessages(params, Seq(tidp0 -> new PartitionData(...)
   timer.advanceClock(2000L)
   assertTrue(curExpiresPerSec + 1, DelayedRemoteFetchMetrics.expiredRequestMeter.count())
   ```
   
   Had a test, and it works. Would you please give it a try?
   Thanks.



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