You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
546 B

5 years ago
5 years ago
  1. package broker
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestPickMember(t *testing.T) {
  7. servers := []string{
  8. "s1:port",
  9. "s2:port",
  10. "s3:port",
  11. "s5:port",
  12. "s4:port",
  13. }
  14. total := 1000
  15. distribution := make(map[string]int)
  16. for i := 0; i < total; i++ {
  17. tp := fmt.Sprintf("tp:%2d", i)
  18. m := PickMember(servers, []byte(tp))
  19. // println(tp, "=>", m)
  20. distribution[m]++
  21. }
  22. for member, count := range distribution {
  23. fmt.Printf("member: %s, key count: %d load=%.2f\n", member, count, float64(count*100)/float64(total/len(servers)))
  24. }
  25. }