mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-25 11:39:12 +08:00
add test for volume registeration at master
This commit is contained in:
parent
cb19a7da99
commit
018a9a20be
@ -2,6 +2,9 @@ package topology
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/chrislusf/seaweedfs/weed/sequence"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
)
|
||||
|
||||
func TestRemoveDataCenter(t *testing.T) {
|
||||
@ -15,3 +18,96 @@ func TestRemoveDataCenter(t *testing.T) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlingVolumeServerHeartbeat(t *testing.T) {
|
||||
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
|
||||
|
||||
dc := topo.GetOrCreateDataCenter("dc1")
|
||||
rack := dc.GetOrCreateRack("rack1")
|
||||
dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
|
||||
|
||||
{
|
||||
volumeCount := 700
|
||||
var volumeMessages []*master_pb.VolumeInformationMessage
|
||||
for k := 1; k <= volumeCount; k++ {
|
||||
volumeMessage := &master_pb.VolumeInformationMessage{
|
||||
Id: uint32(k),
|
||||
Size: uint64(25432),
|
||||
Collection: "",
|
||||
FileCount: uint64(2343),
|
||||
DeleteCount: uint64(345),
|
||||
DeletedByteCount: 34524,
|
||||
ReadOnly: false,
|
||||
ReplicaPlacement: uint32(0),
|
||||
Version: uint32(1),
|
||||
Ttl: 0,
|
||||
}
|
||||
volumeMessages = append(volumeMessages, volumeMessage)
|
||||
}
|
||||
var volumeInfos []storage.VolumeInfo
|
||||
for _, v := range volumeMessages {
|
||||
if vi, err := storage.NewVolumeInfo(v); err == nil {
|
||||
volumeInfos = append(volumeInfos, vi)
|
||||
}
|
||||
}
|
||||
|
||||
deletedVolumes := dn.UpdateVolumes(volumeInfos)
|
||||
for _, v := range volumeInfos {
|
||||
topo.RegisterVolumeLayout(v, dn)
|
||||
}
|
||||
for _, v := range deletedVolumes {
|
||||
topo.UnRegisterVolumeLayout(v, dn)
|
||||
}
|
||||
|
||||
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
||||
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
||||
}
|
||||
|
||||
{
|
||||
volumeCount := 700 - 1
|
||||
var volumeMessages []*master_pb.VolumeInformationMessage
|
||||
for k := 1; k <= volumeCount; k++ {
|
||||
volumeMessage := &master_pb.VolumeInformationMessage{
|
||||
Id: uint32(k),
|
||||
Size: uint64(254320),
|
||||
Collection: "",
|
||||
FileCount: uint64(2343),
|
||||
DeleteCount: uint64(345),
|
||||
DeletedByteCount: 345240,
|
||||
ReadOnly: false,
|
||||
ReplicaPlacement: uint32(0),
|
||||
Version: uint32(1),
|
||||
Ttl: 0,
|
||||
}
|
||||
volumeMessages = append(volumeMessages, volumeMessage)
|
||||
}
|
||||
var volumeInfos []storage.VolumeInfo
|
||||
for _, v := range volumeMessages {
|
||||
if vi, err := storage.NewVolumeInfo(v); err == nil {
|
||||
volumeInfos = append(volumeInfos, vi)
|
||||
}
|
||||
}
|
||||
|
||||
deletedVolumes := dn.UpdateVolumes(volumeInfos)
|
||||
for _, v := range volumeInfos {
|
||||
topo.RegisterVolumeLayout(v, dn)
|
||||
}
|
||||
for _, v := range deletedVolumes {
|
||||
topo.UnRegisterVolumeLayout(v, dn)
|
||||
}
|
||||
|
||||
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
||||
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
||||
}
|
||||
|
||||
topo.UnRegisterDataNode(dn)
|
||||
|
||||
assert(t, "activeVolumeCount2", topo.activeVolumeCount, 0)
|
||||
|
||||
}
|
||||
|
||||
func assert(t *testing.T, message string, actual, expected int) {
|
||||
if actual != expected {
|
||||
t.Fatalf("unexpected %s: %d, expected: %d", message, actual, expected)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user