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.

60 lines
1.4 KiB

12 years ago
12 years ago
12 years ago
12 years ago
  1. package topology
  2. import (
  3. "code.google.com/p/weed-fs/go/sequence"
  4. _ "fmt"
  5. "strconv"
  6. "testing"
  7. )
  8. func TestXYZ(t *testing.T) {
  9. topo, err := NewTopology("topo", "/etc/weed.conf", sequence.NewMemorySequencer(), 234, 5)
  10. if err != nil {
  11. t.Error("cannot create new topology:", err)
  12. t.FailNow()
  13. }
  14. for i := 0; i < 5; i++ {
  15. dc := NewDataCenter("dc" + strconv.Itoa(i))
  16. dc.activeVolumeCount = i
  17. dc.maxVolumeCount = 5
  18. topo.LinkChildNode(dc)
  19. }
  20. nl := NewNodeList(topo.Children(), nil)
  21. picked, ret := nl.RandomlyPickN(1, 0, "")
  22. if !ret || len(picked) != 1 {
  23. t.Error("need to randomly pick 1 node")
  24. }
  25. picked, ret = nl.RandomlyPickN(1, 0, "dc1")
  26. if !ret || len(picked) != 1 {
  27. t.Error("need to randomly pick 1 node")
  28. }
  29. if picked[0].Id() != "dc1" {
  30. t.Error("need to randomly pick 1 dc1 node")
  31. }
  32. picked, ret = nl.RandomlyPickN(2, 0, "dc1")
  33. if !ret || len(picked) != 2 {
  34. t.Error("need to randomly pick 1 node")
  35. }
  36. if picked[0].Id() != "dc1" {
  37. t.Error("need to randomly pick 2 with one dc1 node")
  38. }
  39. picked, ret = nl.RandomlyPickN(4, 0, "")
  40. if !ret || len(picked) != 4 {
  41. t.Error("need to randomly pick 4 nodes")
  42. }
  43. picked, ret = nl.RandomlyPickN(5, 0, "")
  44. if !ret || len(picked) != 5 {
  45. t.Error("need to randomly pick 5 nodes")
  46. }
  47. picked, ret = nl.RandomlyPickN(6, 0, "")
  48. if ret || len(picked) != 0 {
  49. t.Error("can not randomly pick 6 nodes:", ret, picked)
  50. }
  51. }