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.

126 lines
3.5 KiB

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