MCPcopy
hub / github.com/segmentio/kafka-go / TestRangeAssignGroupsUnbalanced

Function TestRangeAssignGroupsUnbalanced

groupbalancer_test.go:198–224  ·  groupbalancer_test.go::TestRangeAssignGroupsUnbalanced

For 66 members, 213 partitions, each member should get 213/66 = 3.22 partitions. This means that in practice, each member should get either 3 or 4 partitions assigned to it. Any other number is a failure.

(t *testing.T)

Source from the content-addressed store, hash-verified

196// This means that in practice, each member should get either 3 or 4 partitions
197// assigned to it. Any other number is a failure.
198func TestRangeAssignGroupsUnbalanced(t *testing.T) {
199 members := []GroupMember{}
200 for i := 0; i < 66; i++ {
201 members = append(members, GroupMember{
202 ID: strconv.Itoa(i),
203 Topics: []string{"topic-1"},
204 })
205 }
206 partitions := []Partition{}
207 for i := 0; i < 213; i++ {
208 partitions = append(partitions, Partition{
209 ID: i,
210 Topic: "topic-1",
211 })
212 }
213
214 assignments := RangeGroupBalancer{}.AssignGroups(members, partitions)
215 if len(assignments) != len(members) {
216 t.Fatalf("Assignment count mismatch: %d != %d", len(assignments), len(members))
217 }
218
219 for _, m := range assignments {
220 if len(m["topic-1"]) < 3 || len(m["topic-1"]) > 4 {
221 t.Fatalf("Expected assignment of 3 or 4 partitions, got %d", len(m["topic-1"]))
222 }
223 }
224}
225
226func TestRoundRobinAssignGroups(t *testing.T) {
227 newPartitions := func(partitionCount int, topics ...string) []Partition {

Callers

nothing calls this directly

Calls 1

AssignGroupsMethod · 0.65

Tested by

no test coverage detected