andrew4699 commented on code in PR #423:
URL: https://github.com/apache/polaris/pull/423#discussion_r1831777273


##########
polaris-service/src/test/java/org/apache/polaris/service/ratelimiter/RateLimiterFilterTest.java:
##########
@@ -70,20 +75,58 @@ public static void setup(
     RateLimiterFilterTest.userToken = userToken.token();
   }
 
+  @BeforeEach
+  @AfterEach
+  public void resetRateLimiter() {
+    clock.add(
+        Duration.ofSeconds(2 * WINDOW_SECONDS)); // Clear any counters from 
before/after this test
+  }
+
   @Test
   public void testRateLimiter() {
     Consumer<Response.Status> requestAsserter =
         TestUtil.constructRequestAsserter(EXT, userToken, realm);
-    CallContext.setCurrentContext(CallContext.of(() -> "myrealm", null));
 
-    MutableClock clock = MockRealmTokenBucketRateLimiter.CLOCK;
-    clock.add(Duration.ofSeconds(2 * WINDOW_SECONDS)); // Clear any counters 
from before this test
+    for (int i = 0; i < REQUESTS_PER_SECOND * WINDOW_SECONDS; i++) {
+      requestAsserter.accept(Response.Status.OK);
+    }
+    requestAsserter.accept(Response.Status.TOO_MANY_REQUESTS);
+
+    // Ensure that a different realm identifier gets a separate limit
+    Consumer<Response.Status> requestAsserter2 =
+        TestUtil.constructRequestAsserter(EXT, userToken, realm + "2");
+    requestAsserter2.accept(Response.Status.OK);
+  }
+
+  @Test
+  public void testMetricsAreEmittedWhenRateLimiting() {
+    Consumer<Response.Status> requestAsserter =
+        TestUtil.constructRequestAsserter(EXT, userToken, realm);
 
     for (int i = 0; i < REQUESTS_PER_SECOND * WINDOW_SECONDS; i++) {
       requestAsserter.accept(Response.Status.OK);
     }
     requestAsserter.accept(Response.Status.TOO_MANY_REQUESTS);
 
-    clock.add(Duration.ofSeconds(4 * WINDOW_SECONDS)); // Clear any counters 
from during this test
+    assertTrue(
+        getCounter(
+                
"polaris_principal_roles_listPrincipalRoles_error_total{HTTP_RESPONSE_CODE=\"429\"}")
+            > 0);
+  }
+
+  private double getCounter(String metricName) {

Review Comment:
   Will replace this with 
https://github.com/apache/polaris/blob/cfd908ad3bc7527d5fbd2127f8eb7bce54a0acbd/polaris-service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java
 once my other PR is merged



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