squah-confluent commented on code in PR #23733:
URL: https://github.com/apache/kafka/pull/23733#discussion_r4264982735


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/assignor/uniform2/QuotasTest.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.coordinator.group.assignor.uniform2;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.coordinator.group.assignor.uniform2.util.IntList;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.function.IntUnaryOperator;
+import java.util.stream.IntStream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Tests of {@link Quotas}.
+ *
+ * <p>The member ids sort as A &lt; B &lt; C, so that A is member 0, B is 
member 1 and C is member
+ * 2, and the topic ids as T1 &lt; T2 &lt; T3, so that T1 is topic 0, T2 is 
topic 1 and T3 is
+ * topic 2 when all of them are subscribed.
+ */
+public class QuotasTest {
+    private static final Uuid T1 = new Uuid(1L, 1L);
+    private static final Uuid T2 = new Uuid(2L, 1L);
+    private static final Uuid T3 = new Uuid(3L, 1L);
+
+    private static final int A = 0;
+    private static final int B = 1;
+
+    /**
+     * 3 partitions over 2 subscribers give a minimum quota of 1 and 1 extra 
partition; 7 over 3
+     * a minimum quota of 2 and 1 extra partition; 2 over 3 a minimum quota of 
0 and 2 extra
+     * partitions. The members of cohort 0, A and B, subscribe to all three 
topics and get at least
+     * 1 + 2 + 0 = 3 partitions each; the member of cohort 1, C, subscribes to 
T2 and T3 and gets
+     * at least 2 + 0 = 2.
+     */
+    @Test
+    public void testMinQuotaAndExtraPartitions() {
+        var spec = new GroupSpecFixture()
+            .withMember("A", Set.of(T1, T2, T3))
+            .withMember("B", Set.of(T1, T2, T3))
+            .withMember("C", Set.of(T2, T3))
+            .build();
+        var describer = new TopicsFixture()
+            .withTopic(T1, 3)
+            .withTopic(T2, 7)
+            .withTopic(T3, 2)
+            .build();
+        var group = new IndexedGroup(spec, describer);
+
+        var quotas = new Quotas(group);
+
+        assertEquals(List.of(1, 2, 0), values(group.topicCount(), 
quotas::minQuota));
+        assertEquals(List.of(1, 1, 2), values(group.topicCount(), 
quotas::extraPartitions));
+        assertEquals(List.of(3, 2), values(group.cohortCount(), 
quotas::minAssignmentSize));
+        assertEquals(List.of(3, 3, 2), values(group.memberCount(), 
quotas::assignmentSize));
+        assertEquals(List.of(0, 0, 0), values(group.memberCount(), 
quotas::extraPartitionCount));
+        assertEquals(List.of(List.of(), List.of(), List.of()), 
membersWithExtraPartition(group, quotas));
+    }
+
+    /**
+     * A and B subscribe to T1, of 3 partitions, and T2, of 2: T1 has 1 extra 
partition, which A
+     * gets, and T2 none. Neither a second extra partition of T1 nor one of T2 
can be given, and an
+     * extra partition of T1 cannot move from B, which has none: A keeps its 
only extra partition,
+     * and the assignment sizes are 3 and 2.
+     */
+    @Test
+    public void testExtraPartitionsBeyondThoseOfTheTopicAreRejected() {

Review Comment:
   This test actually tests three things which we all care about:
   * The happy path for `giveExtraPartition`
   * The exceptional path for `giveExtraPartition` where we try to over-give 
extra partitions
   * `moveExtraPartition` from a member which does not have one.
   
   The name only captures the 2nd item. Perhaps we could rename this to 
`testGiveExtraPartition` and move the `moveExtraPartition` assert into 
`testMoveExtraPartition`.



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