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.

87 lines
2.4 KiB

13 years ago
13 years ago
7 years ago
7 years ago
  1. package topology
  2. import (
  3. "testing"
  4. "github.com/chrislusf/seaweedfs/weed/sequence"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. )
  7. func TestRemoveDataCenter(t *testing.T) {
  8. topo := setup(topologyLayout)
  9. topo.UnlinkChildNode(NodeId("dc2"))
  10. if topo.GetActiveVolumeCount() != 15 {
  11. t.Fail()
  12. }
  13. topo.UnlinkChildNode(NodeId("dc3"))
  14. if topo.GetActiveVolumeCount() != 12 {
  15. t.Fail()
  16. }
  17. }
  18. func TestHandlingVolumeServerHeartbeat(t *testing.T) {
  19. topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
  20. dc := topo.GetOrCreateDataCenter("dc1")
  21. rack := dc.GetOrCreateRack("rack1")
  22. dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
  23. {
  24. volumeCount := 700
  25. var volumeMessages []*master_pb.VolumeInformationMessage
  26. for k := 1; k <= volumeCount; k++ {
  27. volumeMessage := &master_pb.VolumeInformationMessage{
  28. Id: uint32(k),
  29. Size: uint64(25432),
  30. Collection: "",
  31. FileCount: uint64(2343),
  32. DeleteCount: uint64(345),
  33. DeletedByteCount: 34524,
  34. ReadOnly: false,
  35. ReplicaPlacement: uint32(0),
  36. Version: uint32(1),
  37. Ttl: 0,
  38. }
  39. volumeMessages = append(volumeMessages, volumeMessage)
  40. }
  41. topo.SyncDataNodeRegistration(volumeMessages, dn)
  42. assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
  43. assert(t, "volumeCount", topo.volumeCount, volumeCount)
  44. }
  45. {
  46. volumeCount := 700 - 1
  47. var volumeMessages []*master_pb.VolumeInformationMessage
  48. for k := 1; k <= volumeCount; k++ {
  49. volumeMessage := &master_pb.VolumeInformationMessage{
  50. Id: uint32(k),
  51. Size: uint64(254320),
  52. Collection: "",
  53. FileCount: uint64(2343),
  54. DeleteCount: uint64(345),
  55. DeletedByteCount: 345240,
  56. ReadOnly: false,
  57. ReplicaPlacement: uint32(0),
  58. Version: uint32(1),
  59. Ttl: 0,
  60. }
  61. volumeMessages = append(volumeMessages, volumeMessage)
  62. }
  63. topo.SyncDataNodeRegistration(volumeMessages, dn)
  64. assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
  65. assert(t, "volumeCount", topo.volumeCount, volumeCount)
  66. }
  67. topo.UnRegisterDataNode(dn)
  68. assert(t, "activeVolumeCount2", topo.activeVolumeCount, 0)
  69. }
  70. func assert(t *testing.T, message string, actual, expected int) {
  71. if actual != expected {
  72. t.Fatalf("unexpected %s: %d, expected: %d", message, actual, expected)
  73. }
  74. }