dino2895 commented on code in PR #22875:
URL: https://github.com/apache/kafka/pull/22875#discussion_r3663629604


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/ClientQuotasTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.quota.ClientQuotaAlteration;
+import org.apache.kafka.common.quota.ClientQuotaEntity;
+import org.apache.kafka.common.quota.ClientQuotaFilter;
+import org.apache.kafka.common.quota.ClientQuotaFilterComponent;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.test.TestUtils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@ClusterTestDefaults(types = {Type.KRAFT})
+public class ClientQuotasTest {
+
+    private Map<ClientQuotaEntity, Map<String, Double>> alterThenDescribe(
+        Admin admin,
+        ClientQuotaEntity entity,
+        List<ClientQuotaAlteration.Op> quotas,
+        ClientQuotaFilter filter,
+        int expectCount
+    ) throws Exception {
+        AlterClientQuotasResult alterResult = 
admin.alterClientQuotas(List.of(new ClientQuotaAlteration(entity, quotas)));
+        alterResult.all().get();
+
+        TestUtils.waitForCondition(() -> {
+            Map<ClientQuotaEntity, Map<String, Double>> results = 
admin.describeClientQuotas(filter).entities().get();
+            return results.getOrDefault(entity, Map.of()).size() == 
expectCount;
+        }, "Broker never saw new client quotas");
+
+        return admin.describeClientQuotas(filter).entities().get();
+    }
+
+    private void setConsumerByteRate(Admin admin, ClientQuotaEntity entity, 
Long value) throws Exception {
+        admin.alterClientQuotas(List.of(
+            new ClientQuotaAlteration(entity, List.of(
+                new ClientQuotaAlteration.Op("consumer_byte_rate", 
value.doubleValue())))
+        )).all().get();
+    }

Review Comment:
   Thanks! I've added a blank line between the methods.



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/ClientQuotasTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.quota.ClientQuotaAlteration;
+import org.apache.kafka.common.quota.ClientQuotaEntity;
+import org.apache.kafka.common.quota.ClientQuotaFilter;
+import org.apache.kafka.common.quota.ClientQuotaFilterComponent;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.test.TestUtils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@ClusterTestDefaults(types = {Type.KRAFT})
+public class ClientQuotasTest {
+
+    private Map<ClientQuotaEntity, Map<String, Double>> alterThenDescribe(
+        Admin admin,
+        ClientQuotaEntity entity,
+        List<ClientQuotaAlteration.Op> quotas,
+        ClientQuotaFilter filter,
+        int expectCount
+    ) throws Exception {
+        AlterClientQuotasResult alterResult = 
admin.alterClientQuotas(List.of(new ClientQuotaAlteration(entity, quotas)));
+        alterResult.all().get();
+
+        TestUtils.waitForCondition(() -> {
+            Map<ClientQuotaEntity, Map<String, Double>> results = 
admin.describeClientQuotas(filter).entities().get();
+            return results.getOrDefault(entity, Map.of()).size() == 
expectCount;
+        }, "Broker never saw new client quotas");
+
+        return admin.describeClientQuotas(filter).entities().get();
+    }
+
+    private void setConsumerByteRate(Admin admin, ClientQuotaEntity entity, 
Long value) throws Exception {
+        admin.alterClientQuotas(List.of(
+            new ClientQuotaAlteration(entity, List.of(
+                new ClientQuotaAlteration.Op("consumer_byte_rate", 
value.doubleValue())))
+        )).all().get();
+    }
+    private Map<ClientQuotaEntity, Long> getConsumerByteRates(Admin admin) 
throws Exception {
+        return 
admin.describeClientQuotas(ClientQuotaFilter.contains(List.of()))
+            .entities().get()
+            .entrySet().stream()
+            .filter(entry -> 
entry.getValue().containsKey("consumer_byte_rate"))
+            .collect(Collectors.toMap(
+                Map.Entry::getKey,
+                entry -> entry.getValue().get("consumer_byte_rate").longValue()
+            ));
+    }

Review Comment:
   Thanks! I've added a blank line between the methods.



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