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.

59 lines
1.3 KiB

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(1, 0, "dc1")
  25. if !ret || len(picked) != 1 {
  26. t.Error("need to randomly pick 1 node")
  27. }
  28. if picked[0].Id() != "dc1" {
  29. t.Error("need to randomly pick 1 dc1 node")
  30. }
  31. picked, ret = nl.RandomlyPickN(2, 0, "dc1")
  32. if !ret || len(picked) != 2 {
  33. t.Error("need to randomly pick 1 node")
  34. }
  35. if picked[0].Id() != "dc1" {
  36. t.Error("need to randomly pick 2 with one dc1 node")
  37. }
  38. picked, ret = nl.RandomlyPickN(4, 0, "")
  39. if !ret || len(picked) != 4 {
  40. t.Error("need to randomly pick 4 nodes")
  41. }
  42. picked, ret = nl.RandomlyPickN(5, 0, "")
  43. if !ret || len(picked) != 5 {
  44. t.Error("need to randomly pick 5 nodes")
  45. }
  46. picked, ret = nl.RandomlyPickN(6, 0, "")
  47. if ret || len(picked) != 0 {
  48. t.Error("can not randomly pick 6 nodes:", ret, picked)
  49. }
  50. }