@@ -13,27 +13,48 @@ import (
13
13
14
14
func TestBalanceStrategyRange (t * testing.T ) {
15
15
tests := []struct {
16
+ name string
16
17
members map [string ][]string
17
18
topics map [string ][]int32
18
19
expected BalanceStrategyPlan
19
20
}{
20
21
{
22
+ name : "2 members, 2 topics, 4 partitions each" ,
21
23
members : map [string ][]string {"M1" : {"T1" , "T2" }, "M2" : {"T1" , "T2" }},
22
24
topics : map [string ][]int32 {"T1" : {0 , 1 , 2 , 3 }, "T2" : {0 , 1 , 2 , 3 }},
23
25
expected : BalanceStrategyPlan {
24
- "M1" : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {2 , 3 }},
25
- "M2" : map [string ][]int32 {"T1" : {2 , 3 }, "T2" : {0 , 1 }},
26
+ "M1" : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {0 , 1 }},
27
+ "M2" : map [string ][]int32 {"T1" : {2 , 3 }, "T2" : {2 , 3 }},
26
28
},
27
29
},
28
30
{
31
+ name : "2 members, 2 topics, 4 partitions each (different member ids)" ,
32
+ members : map [string ][]string {"M3" : {"T1" , "T2" }, "M4" : {"T1" , "T2" }},
33
+ topics : map [string ][]int32 {"T1" : {0 , 1 , 2 , 3 }, "T2" : {0 , 1 , 2 , 3 }},
34
+ expected : BalanceStrategyPlan {
35
+ "M3" : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {0 , 1 }},
36
+ "M4" : map [string ][]int32 {"T1" : {2 , 3 }, "T2" : {2 , 3 }},
37
+ },
38
+ },
39
+ {
40
+ name : "3 members, 1 topic, 1 partition each" ,
41
+ members : map [string ][]string {"M1" : {"T1" }, "M2" : {"T1" }, "M3" : {"T1" }},
42
+ topics : map [string ][]int32 {"T1" : {0 }},
43
+ expected : BalanceStrategyPlan {
44
+ "M1" : map [string ][]int32 {"T1" : {0 }},
45
+ },
46
+ },
47
+ {
48
+ name : "2 members, 2 topics, 3 partitions each" ,
29
49
members : map [string ][]string {"M1" : {"T1" , "T2" }, "M2" : {"T1" , "T2" }},
30
50
topics : map [string ][]int32 {"T1" : {0 , 1 , 2 }, "T2" : {0 , 1 , 2 }},
31
51
expected : BalanceStrategyPlan {
32
- "M1" : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {2 }},
33
- "M2" : map [string ][]int32 {"T1" : {2 }, "T2" : {0 , 1 }},
52
+ "M1" : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {0 , 1 }},
53
+ "M2" : map [string ][]int32 {"T1" : {2 }, "T2" : {2 }},
34
54
},
35
55
},
36
56
{
57
+ name : "2 members, 2 topics, different subscriptions" ,
37
58
members : map [string ][]string {"M1" : {"T1" }, "M2" : {"T1" , "T2" }},
38
59
topics : map [string ][]int32 {"T1" : {0 , 1 }, "T2" : {0 , 1 }},
39
60
expected : BalanceStrategyPlan {
@@ -49,17 +70,19 @@ func TestBalanceStrategyRange(t *testing.T) {
49
70
}
50
71
51
72
for _ , test := range tests {
52
- members := make (map [string ]ConsumerGroupMemberMetadata )
53
- for memberID , topics := range test .members {
54
- members [memberID ] = ConsumerGroupMemberMetadata {Topics : topics }
55
- }
73
+ t .Run (test .name , func (t * testing.T ) {
74
+ members := make (map [string ]ConsumerGroupMemberMetadata )
75
+ for memberID , topics := range test .members {
76
+ members [memberID ] = ConsumerGroupMemberMetadata {Topics : topics }
77
+ }
56
78
57
- actual , err := strategy .Plan (members , test .topics )
58
- if err != nil {
59
- t .Errorf ("Unexpected error %v" , err )
60
- } else if ! reflect .DeepEqual (actual , test .expected ) {
61
- t .Errorf ("Plan does not match expectation\n expected: %#v\n actual: %#v" , test .expected , actual )
62
- }
79
+ actual , err := strategy .Plan (members , test .topics )
80
+ if err != nil {
81
+ t .Errorf ("Unexpected error %v" , err )
82
+ } else if ! reflect .DeepEqual (actual , test .expected ) {
83
+ t .Errorf ("Plan does not match expectation\n expected: %#v\n actual: %#v" , test .expected , actual )
84
+ }
85
+ })
63
86
}
64
87
}
65
88
0 commit comments