apoorvmittal10 commented on code in PR #15234:
URL: https://github.com/apache/kafka/pull/15234#discussion_r1461791492


##########
server/src/test/java/org/apache/kafka/server/ClientMetricsManagerTest.java:
##########
@@ -919,4 +922,101 @@ public void 
testPushTelemetryConcurrentRequestAfterSubscriptionUpdate() throws U
         // 1 request should fail with throttling error.
         assertEquals(1, throttlingErrorCount);
     }
+
+    @Test
+    public void testCacheEviction() throws UnknownHostException, 
InterruptedException {
+        Properties properties = new Properties();
+        properties.put("metrics", 
ClientMetricsConfigs.ALL_SUBSCRIBED_METRICS_CONFIG);
+        properties.put(ClientMetricsConfigs.PUSH_INTERVAL_MS, "100");
+        clientMetricsManager.updateSubscription("sub-1", properties);
+
+        GetTelemetrySubscriptionsRequest request = new 
GetTelemetrySubscriptionsRequest.Builder(
+            new GetTelemetrySubscriptionsRequestData(), true).build();
+
+        GetTelemetrySubscriptionsResponse response = 
clientMetricsManager.processGetTelemetrySubscriptionRequest(
+            request, ClientMetricsTestUtils.requestContext());
+        assertEquals(Errors.NONE, response.error());
+
+        
assertNotNull(clientMetricsManager.clientInstance(response.data().clientInstanceId()));
+        assertEquals(1, clientMetricsManager.expirationTimer().size());
+        // Advance the clock to trigger cache eviction, cache expiry should be 
100 * 3 = 300 ms.
+        clientMetricsManager.expirationTimer().advanceClock(300);
+        assertTimeoutPreemptively(Duration.ofMillis(300), () -> {

Review Comment:
   Though I cannot see the tests fail when waiting for 350ms but I did see a 
failure in PR run hence kept the preemptive wait time of 600ms which will not 
make this test flaky. Though that's the maximum wait time.



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