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.

39 lines
825 B

  1. package topology
  2. import (
  3. _ "fmt"
  4. "strconv"
  5. "testing"
  6. )
  7. func TestXYZ(t *testing.T) {
  8. topo := NewTopology("topo", "/etc/weed.conf", "/tmp", "test", 234, 5)
  9. for i := 0; i < 5; i++ {
  10. dc := NewDataCenter("dc" + strconv.Itoa(i))
  11. dc.activeVolumeCount = i
  12. dc.maxVolumeCount = 5
  13. topo.LinkChildNode(dc)
  14. }
  15. nl := NewNodeList(topo.Children(), nil)
  16. picked, ret := nl.RandomlyPickN(1)
  17. if !ret || len(picked) != 1 {
  18. t.Errorf("need to randomly pick 1 node")
  19. }
  20. picked, ret = nl.RandomlyPickN(4)
  21. if !ret || len(picked) != 4 {
  22. t.Errorf("need to randomly pick 4 nodes")
  23. }
  24. picked, ret = nl.RandomlyPickN(5)
  25. if !ret || len(picked) != 5 {
  26. t.Errorf("need to randomly pick 5 nodes")
  27. }
  28. picked, ret = nl.RandomlyPickN(6)
  29. if ret || len(picked) != 0 {
  30. t.Errorf("can not randomly pick 6 nodes:", ret, picked)
  31. }
  32. }