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.

67 lines
1.9 KiB

Merge accumulated changes related to message queue (#5098) * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * tracking topic=>broker * merge * comment
1 year ago
1 year ago
1 year ago
1 year ago
  1. package pub_balancer
  2. import (
  3. cmap "github.com/orcaman/concurrent-map/v2"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  5. "github.com/stretchr/testify/assert"
  6. "testing"
  7. )
  8. func Test_allocateOneBroker(t *testing.T) {
  9. brokers := cmap.New[*BrokerStats]()
  10. brokers.SetIfAbsent("localhost:17777", &BrokerStats{
  11. TopicPartitionCount: 0,
  12. ConsumerCount: 0,
  13. CpuUsagePercent: 0,
  14. })
  15. tests := []struct {
  16. name string
  17. args args
  18. wantAssignments []*mq_pb.BrokerPartitionAssignment
  19. }{
  20. {
  21. name: "test only one broker",
  22. args: args{
  23. brokers: brokers,
  24. partitionCount: 1,
  25. },
  26. wantAssignments: []*mq_pb.BrokerPartitionAssignment{
  27. {
  28. LeaderBroker: "localhost:17777",
  29. Partition: &mq_pb.Partition{
  30. RingSize: MaxPartitionCount,
  31. RangeStart: 0,
  32. RangeStop: MaxPartitionCount,
  33. },
  34. },
  35. },
  36. },
  37. }
  38. testThem(t, tests)
  39. }
  40. type args struct {
  41. brokers cmap.ConcurrentMap[string, *BrokerStats]
  42. partitionCount int32
  43. }
  44. func testThem(t *testing.T, tests []struct {
  45. name string
  46. args args
  47. wantAssignments []*mq_pb.BrokerPartitionAssignment
  48. }) {
  49. for _, tt := range tests {
  50. t.Run(tt.name, func(t *testing.T) {
  51. gotAssignments := allocateTopicPartitions(tt.args.brokers, tt.args.partitionCount)
  52. assert.Equal(t, len(tt.wantAssignments), len(gotAssignments))
  53. for i, gotAssignment := range gotAssignments {
  54. assert.Equal(t, tt.wantAssignments[i].LeaderBroker, gotAssignment.LeaderBroker)
  55. assert.Equal(t, tt.wantAssignments[i].Partition.RangeStart, gotAssignment.Partition.RangeStart)
  56. assert.Equal(t, tt.wantAssignments[i].Partition.RangeStop, gotAssignment.Partition.RangeStop)
  57. assert.Equal(t, tt.wantAssignments[i].Partition.RingSize, gotAssignment.Partition.RingSize)
  58. assert.Equal(t, tt.wantAssignments[i].Partition.UnixTimeNs, gotAssignment.Partition.UnixTimeNs)
  59. }
  60. })
  61. }
  62. }