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.

47 lines
1.3 KiB

3 years ago
  1. package cluster
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. )
  7. func TestClusterAddRemoveNodes(t *testing.T) {
  8. c := NewCluster()
  9. c.AddClusterNode("filer", pb.ServerAddress("111:1"), "23.45")
  10. c.AddClusterNode("filer", pb.ServerAddress("111:2"), "23.45")
  11. assert.Equal(t, []pb.ServerAddress{
  12. pb.ServerAddress("111:1"),
  13. pb.ServerAddress("111:2"),
  14. }, c.filerLeaders.GetLeaders())
  15. c.AddClusterNode("filer", pb.ServerAddress("111:3"), "23.45")
  16. c.AddClusterNode("filer", pb.ServerAddress("111:4"), "23.45")
  17. assert.Equal(t, []pb.ServerAddress{
  18. pb.ServerAddress("111:1"),
  19. pb.ServerAddress("111:2"),
  20. pb.ServerAddress("111:3"),
  21. }, c.filerLeaders.GetLeaders())
  22. c.AddClusterNode("filer", pb.ServerAddress("111:5"), "23.45")
  23. c.AddClusterNode("filer", pb.ServerAddress("111:6"), "23.45")
  24. c.RemoveClusterNode("filer", pb.ServerAddress("111:4"))
  25. assert.Equal(t, []pb.ServerAddress{
  26. pb.ServerAddress("111:1"),
  27. pb.ServerAddress("111:2"),
  28. pb.ServerAddress("111:3"),
  29. }, c.filerLeaders.GetLeaders())
  30. // remove oldest
  31. c.RemoveClusterNode("filer", pb.ServerAddress("111:1"))
  32. assert.Equal(t, []pb.ServerAddress{
  33. pb.ServerAddress("111:6"),
  34. pb.ServerAddress("111:2"),
  35. pb.ServerAddress("111:3"),
  36. }, c.filerLeaders.GetLeaders())
  37. // remove oldest
  38. c.RemoveClusterNode("filer", pb.ServerAddress("111:1"))
  39. }