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.

124 lines
3.4 KiB

13 years ago
13 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package topology
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  4. "github.com/chrislusf/seaweedfs/weed/sequence"
  5. "github.com/chrislusf/seaweedfs/weed/storage"
  6. "testing"
  7. )
  8. func TestRemoveDataCenter(t *testing.T) {
  9. topo := setup(topologyLayout)
  10. topo.UnlinkChildNode(NodeId("dc2"))
  11. if topo.GetActiveVolumeCount() != 15 {
  12. t.Fail()
  13. }
  14. topo.UnlinkChildNode(NodeId("dc3"))
  15. if topo.GetActiveVolumeCount() != 12 {
  16. t.Fail()
  17. }
  18. }
  19. func TestHandlingVolumeServerHeartbeat(t *testing.T) {
  20. topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
  21. dc := topo.GetOrCreateDataCenter("dc1")
  22. rack := dc.GetOrCreateRack("rack1")
  23. dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
  24. {
  25. volumeCount := 7
  26. var volumeMessages []*master_pb.VolumeInformationMessage
  27. for k := 1; k <= volumeCount; k++ {
  28. volumeMessage := &master_pb.VolumeInformationMessage{
  29. Id: uint32(k),
  30. Size: uint64(25432),
  31. Collection: "",
  32. FileCount: uint64(2343),
  33. DeleteCount: uint64(345),
  34. DeletedByteCount: 34524,
  35. ReadOnly: false,
  36. ReplicaPlacement: uint32(0),
  37. Version: uint32(1),
  38. Ttl: 0,
  39. }
  40. volumeMessages = append(volumeMessages, volumeMessage)
  41. }
  42. topo.SyncDataNodeRegistration(volumeMessages, dn)
  43. assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
  44. assert(t, "volumeCount", topo.volumeCount, volumeCount)
  45. }
  46. {
  47. volumeCount := 7 - 1
  48. var volumeMessages []*master_pb.VolumeInformationMessage
  49. for k := 1; k <= volumeCount; k++ {
  50. volumeMessage := &master_pb.VolumeInformationMessage{
  51. Id: uint32(k),
  52. Size: uint64(254320),
  53. Collection: "",
  54. FileCount: uint64(2343),
  55. DeleteCount: uint64(345),
  56. DeletedByteCount: 345240,
  57. ReadOnly: false,
  58. ReplicaPlacement: uint32(0),
  59. Version: uint32(1),
  60. Ttl: 0,
  61. }
  62. volumeMessages = append(volumeMessages, volumeMessage)
  63. }
  64. topo.SyncDataNodeRegistration(volumeMessages, dn)
  65. assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
  66. assert(t, "volumeCount", topo.volumeCount, volumeCount)
  67. }
  68. topo.UnRegisterDataNode(dn)
  69. assert(t, "activeVolumeCount2", topo.activeVolumeCount, 0)
  70. }
  71. func assert(t *testing.T, message string, actual, expected int) {
  72. if actual != expected {
  73. t.Fatalf("unexpected %s: %d, expected: %d", message, actual, expected)
  74. }
  75. }
  76. func TestAddRemoveVolume(t *testing.T) {
  77. topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
  78. dc := topo.GetOrCreateDataCenter("dc1")
  79. rack := dc.GetOrCreateRack("rack1")
  80. dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
  81. v := storage.VolumeInfo{
  82. Id: storage.VolumeId(1),
  83. Size: 100,
  84. Collection: "xcollection",
  85. FileCount: 123,
  86. DeleteCount: 23,
  87. DeletedByteCount: 45,
  88. ReadOnly: false,
  89. Version: storage.CurrentVersion,
  90. ReplicaPlacement: &storage.ReplicaPlacement{},
  91. Ttl: storage.EMPTY_TTL,
  92. }
  93. dn.UpdateVolumes([]storage.VolumeInfo{v})
  94. topo.RegisterVolumeLayout(v, dn)
  95. if _, hasCollection := topo.FindCollection(v.Collection); !hasCollection {
  96. t.Errorf("collection %v should exist", v.Collection)
  97. }
  98. topo.UnRegisterVolumeLayout(v, dn)
  99. if _, hasCollection := topo.FindCollection(v.Collection); hasCollection {
  100. t.Errorf("collection %v should not exist", v.Collection)
  101. }
  102. }