balance_brokers_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package pub_balancer
  2. import (
  3. cmap "github.com/orcaman/concurrent-map/v2"
  4. "github.com/seaweedfs/seaweedfs/weed/mq/topic"
  5. "reflect"
  6. "testing"
  7. )
  8. func TestBalanceTopicPartitionOnBrokers(t *testing.T) {
  9. brokers := cmap.New[*BrokerStats]()
  10. broker1Stats := &BrokerStats{
  11. TopicPartitionCount: 1,
  12. CpuUsagePercent: 1,
  13. TopicPartitionStats: cmap.New[*TopicPartitionStats](),
  14. }
  15. broker1Stats.TopicPartitionStats.Set("topic1:0", &TopicPartitionStats{
  16. TopicPartition: topic.TopicPartition{
  17. Topic: topic.Topic{Namespace: "topic1", Name: "topic1"},
  18. Partition: topic.Partition{RangeStart: 0, RangeStop: 512, RingSize: 1024},
  19. },
  20. })
  21. broker2Stats := &BrokerStats{
  22. TopicPartitionCount: 2,
  23. CpuUsagePercent: 1,
  24. TopicPartitionStats: cmap.New[*TopicPartitionStats](),
  25. }
  26. broker2Stats.TopicPartitionStats.Set("topic1:1", &TopicPartitionStats{
  27. TopicPartition: topic.TopicPartition{
  28. Topic: topic.Topic{Namespace: "topic1", Name: "topic1"},
  29. Partition: topic.Partition{RangeStart: 512, RangeStop: 1024, RingSize: 1024},
  30. },
  31. })
  32. broker2Stats.TopicPartitionStats.Set("topic2:0", &TopicPartitionStats{
  33. TopicPartition: topic.TopicPartition{
  34. Topic: topic.Topic{Namespace: "topic2", Name: "topic2"},
  35. Partition: topic.Partition{RangeStart: 0, RangeStop: 1024, RingSize: 1024},
  36. },
  37. })
  38. brokers.Set("broker1", broker1Stats)
  39. brokers.Set("broker2", broker2Stats)
  40. type args struct {
  41. brokers cmap.ConcurrentMap[string, *BrokerStats]
  42. }
  43. tests := []struct {
  44. name string
  45. args args
  46. want BalanceAction
  47. }{
  48. {
  49. name: "test",
  50. args: args{
  51. brokers: brokers,
  52. },
  53. want: nil,
  54. },
  55. }
  56. for _, tt := range tests {
  57. t.Run(tt.name, func(t *testing.T) {
  58. if got := BalanceTopicPartitionOnBrokers(tt.args.brokers); !reflect.DeepEqual(got, tt.want) {
  59. t.Errorf("BalanceTopicPartitionOnBrokers() = %v, want %v", got, tt.want)
  60. }
  61. })
  62. }
  63. }