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.

43 lines
918 B

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