2012-09-03 08:50:04 +00:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2013-01-17 08:15:05 +00:00
|
|
|
_ "fmt"
|
2012-09-03 08:50:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestXYZ(t *testing.T) {
|
2013-01-17 08:15:05 +00:00
|
|
|
topo := NewTopology("topo","/etc/weed.conf", "/tmp","test",234,5)
|
2012-09-03 08:50:04 +00:00
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
dc := NewDataCenter("dc" + strconv.Itoa(i))
|
|
|
|
dc.activeVolumeCount = i
|
|
|
|
dc.maxVolumeCount = 5
|
|
|
|
topo.LinkChildNode(dc)
|
|
|
|
}
|
2013-01-17 08:15:05 +00:00
|
|
|
nl := NewNodeList(topo.Children(),nil)
|
2012-09-03 08:50:04 +00:00
|
|
|
|
2013-01-17 08:15:05 +00:00
|
|
|
picked, ret := nl.RandomlyPickN(1)
|
|
|
|
if !ret || len(picked)!=1 {
|
|
|
|
t.Errorf("need to randomly pick 1 node")
|
|
|
|
}
|
2012-09-03 08:50:04 +00:00
|
|
|
|
|
|
|
picked, ret = nl.RandomlyPickN(4)
|
2013-01-17 08:15:05 +00:00
|
|
|
if !ret || len(picked)!=4 {
|
|
|
|
t.Errorf("need to randomly pick 4 nodes")
|
2012-09-03 08:50:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 08:15:05 +00:00
|
|
|
picked, ret = nl.RandomlyPickN(5)
|
|
|
|
if !ret || len(picked)!=5 {
|
|
|
|
t.Errorf("need to randomly pick 5 nodes")
|
|
|
|
}
|
2012-09-03 08:50:04 +00:00
|
|
|
|
2013-01-17 08:15:05 +00:00
|
|
|
picked, ret = nl.RandomlyPickN(6)
|
|
|
|
if ret || len(picked)!=0 {
|
|
|
|
t.Errorf("can not randomly pick 6 nodes:", ret, picked)
|
|
|
|
}
|
2012-09-03 08:50:04 +00:00
|
|
|
|
|
|
|
}
|