consistent_distribution_test.go 546 B

1234567891011121314151617181920212223242526272829303132
  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. }