From 7289df54164d53da69a832cb7827876386ff7741 Mon Sep 17 00:00:00 2001 From: Dominic Evans Date: Fri, 8 Feb 2019 11:25:39 +0000 Subject: [PATCH] admin: include ReplicaAssignment in ListTopics() --- admin.go | 4 ++++ admin_test.go | 4 ++++ mockresponses.go | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/admin.go b/admin.go index c58c60ec6..18b055a46 100644 --- a/admin.go +++ b/admin.go @@ -249,6 +249,10 @@ func (ca *clusterAdmin) ListTopics() (map[string]TopicDetail, error) { NumPartitions: int32(len(topic.Partitions)), } if len(topic.Partitions) > 0 { + topicDetails.ReplicaAssignment = map[int32][]int32{} + for _, partition := range topic.Partitions { + topicDetails.ReplicaAssignment[partition.ID] = partition.Replicas + } topicDetails.ReplicationFactor = int16(len(topic.Partitions[0].Replicas)) } topicsDetailsMap[topic.Name] = topicDetails diff --git a/admin_test.go b/admin_test.go index 0c02ba893..f1299f3a1 100644 --- a/admin_test.go +++ b/admin_test.go @@ -179,6 +179,10 @@ func TestClusterAdminListTopics(t *testing.T) { if err != nil { t.Fatal(err) } + + if topic.ReplicaAssignment == nil || topic.ReplicaAssignment[0][0] != 1 { + t.Fatal(errors.New("replica assignment not found in response")) + } } func TestClusterAdminDeleteTopic(t *testing.T) { diff --git a/mockresponses.go b/mockresponses.go index 61a99e104..348c22311 100644 --- a/mockresponses.go +++ b/mockresponses.go @@ -174,17 +174,25 @@ func (mmr *MockMetadataResponse) For(reqBody versionedDecoder) encoder { for addr, brokerID := range mmr.brokers { metadataResponse.AddBroker(addr, brokerID) } + + // Generate set of replicas + replicas := []int32{} + + for _, brokerID := range mmr.brokers { + replicas = append(replicas, brokerID) + } + if len(metadataRequest.Topics) == 0 { for topic, partitions := range mmr.leaders { for partition, brokerID := range partitions { - metadataResponse.AddTopicPartition(topic, partition, brokerID, nil, nil, ErrNoError) + metadataResponse.AddTopicPartition(topic, partition, brokerID, replicas, replicas, ErrNoError) } } return metadataResponse } for _, topic := range metadataRequest.Topics { for partition, brokerID := range mmr.leaders[topic] { - metadataResponse.AddTopicPartition(topic, partition, brokerID, nil, nil, ErrNoError) + metadataResponse.AddTopicPartition(topic, partition, brokerID, replicas, replicas, ErrNoError) } } return metadataResponse