-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e1f243
commit 5b949ca
Showing
12 changed files
with
293 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
memory/consumerpartitionassigner/equaldivide/balancer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 ecodeclub | ||
// | ||
// Licensed 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 equaldivide | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBalancer_AssignPartition(t *testing.T) { | ||
t.Parallel() | ||
balancer := NewBalancer() | ||
testcases := []struct { | ||
name string | ||
consumers []string | ||
partition int | ||
wantAnswer map[string][]int | ||
}{ | ||
{ | ||
name: "分区书超过consumer个数", | ||
consumers: []string{"c1", "c2", "c3", "c4"}, | ||
partition: 5, | ||
wantAnswer: map[string][]int{ | ||
"c1": {0, 1}, | ||
"c2": {2}, | ||
"c3": {3}, | ||
"c4": {4}, | ||
}, | ||
}, | ||
{ | ||
name: "分区数小于consumer个数", | ||
consumers: []string{"c1", "c2", "c3", "c4"}, | ||
partition: 3, | ||
wantAnswer: map[string][]int{ | ||
"c1": {0}, | ||
"c2": {1}, | ||
"c3": {2}, | ||
"c4": {}, | ||
}, | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
actualVal := balancer.AssignPartition(tc.consumers, tc.partition) | ||
assert.Equal(t, tc.wantAnswer, actualVal) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.