seaweedfs/go/topology/node_list_test.go

60 lines
1.3 KiB
Go
Raw Normal View History

2012-09-03 08:50:04 +00:00
package topology
import (
2013-01-17 08:56:56 +00:00
_ "fmt"
2012-09-03 08:50:04 +00:00
"strconv"
"testing"
)
func TestXYZ(t *testing.T) {
2013-02-27 06:54:22 +00:00
topo, err := NewTopology("topo", "/etc/weed.conf", "/tmp", "test", 234, 5)
if err != nil {
t.Error("cannot create new topology:", err)
t.FailNow()
}
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:56:56 +00:00
nl := NewNodeList(topo.Children(), nil)
2012-09-03 08:50:04 +00:00
picked, ret := nl.RandomlyPickN(1, 0, "")
2013-01-17 08:56:56 +00:00
if !ret || len(picked) != 1 {
2013-02-10 17:44:44 +00:00
t.Error("need to randomly pick 1 node")
2013-01-17 08:56:56 +00:00
}
2012-09-03 08:50:04 +00:00
picked, ret = nl.RandomlyPickN(1, 0, "dc1")
if !ret || len(picked) != 1 {
t.Error("need to randomly pick 1 node")
}
if picked[0].Id() != "dc1" {
t.Error("need to randomly pick 1 dc1 node")
}
picked, ret = nl.RandomlyPickN(2, 0, "dc1")
if !ret || len(picked) != 2 {
t.Error("need to randomly pick 1 node")
}
if picked[0].Id() != "dc1" {
t.Error("need to randomly pick 2 with one dc1 node")
}
picked, ret = nl.RandomlyPickN(4, 0, "")
2013-01-17 08:56:56 +00:00
if !ret || len(picked) != 4 {
2013-02-10 17:44:44 +00:00
t.Error("need to randomly pick 4 nodes")
2012-09-03 08:50:04 +00:00
}
picked, ret = nl.RandomlyPickN(5, 0, "")
2013-01-17 08:56:56 +00:00
if !ret || len(picked) != 5 {
2013-02-10 17:44:44 +00:00
t.Error("need to randomly pick 5 nodes")
2013-01-17 08:56:56 +00:00
}
2012-09-03 08:50:04 +00:00
picked, ret = nl.RandomlyPickN(6, 0, "")
2013-01-17 08:56:56 +00:00
if ret || len(picked) != 0 {
2013-02-10 17:44:44 +00:00
t.Error("can not randomly pick 6 nodes:", ret, picked)
2013-01-17 08:56:56 +00:00
}
2012-09-03 08:50:04 +00:00
}