seaweedfs/weed/cluster/cluster_test.go

48 lines
1.4 KiB
Go
Raw Normal View History

2021-11-08 07:52:40 +00:00
package cluster
2021-11-04 07:54:38 +00:00
import (
"github.com/chrislusf/seaweedfs/weed/pb"
"github.com/stretchr/testify/assert"
"testing"
)
func TestClusterAddRemoveNodes(t *testing.T) {
c := NewCluster()
2022-05-02 06:14:04 +00:00
c.AddClusterNode("", "filer", pb.ServerAddress("111:1"), "23.45")
c.AddClusterNode("", "filer", pb.ServerAddress("111:2"), "23.45")
2021-11-04 07:54:38 +00:00
assert.Equal(t, []pb.ServerAddress{
pb.ServerAddress("111:1"),
pb.ServerAddress("111:2"),
2022-05-02 06:15:58 +00:00
}, c.getFilers("", false).leaders.GetLeaders())
2021-11-04 07:54:38 +00:00
2022-05-02 06:14:04 +00:00
c.AddClusterNode("", "filer", pb.ServerAddress("111:3"), "23.45")
c.AddClusterNode("", "filer", pb.ServerAddress("111:4"), "23.45")
2021-11-04 07:54:38 +00:00
assert.Equal(t, []pb.ServerAddress{
pb.ServerAddress("111:1"),
pb.ServerAddress("111:2"),
pb.ServerAddress("111:3"),
2022-05-02 06:15:58 +00:00
}, c.getFilers("", false).leaders.GetLeaders())
2021-11-04 07:54:38 +00:00
2022-05-02 06:14:04 +00:00
c.AddClusterNode("", "filer", pb.ServerAddress("111:5"), "23.45")
c.AddClusterNode("", "filer", pb.ServerAddress("111:6"), "23.45")
c.RemoveClusterNode("", "filer", pb.ServerAddress("111:4"))
2021-11-04 07:54:38 +00:00
assert.Equal(t, []pb.ServerAddress{
pb.ServerAddress("111:1"),
pb.ServerAddress("111:2"),
pb.ServerAddress("111:3"),
2022-05-02 06:15:58 +00:00
}, c.getFilers("", false).leaders.GetLeaders())
2021-11-04 07:54:38 +00:00
// remove oldest
2022-05-02 06:14:04 +00:00
c.RemoveClusterNode("", "filer", pb.ServerAddress("111:1"))
2021-11-04 07:54:38 +00:00
assert.Equal(t, []pb.ServerAddress{
pb.ServerAddress("111:6"),
pb.ServerAddress("111:2"),
pb.ServerAddress("111:3"),
2022-05-02 06:15:58 +00:00
}, c.getFilers("", false).leaders.GetLeaders())
2021-11-04 07:54:38 +00:00
// remove oldest
2022-05-02 06:14:04 +00:00
c.RemoveClusterNode("", "filer", pb.ServerAddress("111:1"))
2021-11-04 07:54:38 +00:00
}