2020-05-08 09:47:22 +00:00
|
|
|
package broker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPickMember(t *testing.T) {
|
|
|
|
|
|
|
|
servers := []string{
|
|
|
|
"s1:port",
|
|
|
|
"s2:port",
|
|
|
|
"s3:port",
|
|
|
|
"s5:port",
|
|
|
|
"s4:port",
|
|
|
|
}
|
|
|
|
|
|
|
|
total := 1000
|
|
|
|
|
|
|
|
distribution := make(map[string]int)
|
2020-05-10 10:50:30 +00:00
|
|
|
for i := 0; i < total; i++ {
|
2020-05-08 09:47:22 +00:00
|
|
|
tp := fmt.Sprintf("tp:%2d", i)
|
|
|
|
m := PickMember(servers, []byte(tp))
|
|
|
|
// println(tp, "=>", m)
|
|
|
|
distribution[m]++
|
|
|
|
}
|
|
|
|
|
|
|
|
for member, count := range distribution {
|
|
|
|
fmt.Printf("member: %s, key count: %d load=%.2f\n", member, count, float64(count*100)/float64(total/len(servers)))
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:50:30 +00:00
|
|
|
}
|