forked from DataDog/kafka-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopics_legacy_test.go
99 lines (83 loc) · 2.46 KB
/
topics_legacy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"testing"
"github.com/DataDog/kafka-kit/v4/cmd/autothrottle/internal/throttlestore"
"github.com/DataDog/kafka-kit/v4/kafkazk"
)
func TestLegacyGetTopicsWithThrottledBrokers(t *testing.T) {
rtf := &ThrottleManager{
zk: &kafkazk.Stub{},
}
// Minimally populate the ThrottleManager.
rtf.brokerOverrides = throttlestore.BrokerOverrides{
1001: throttlestore.BrokerThrottleOverride{
ID: 1001,
ReassignmentParticipant: false,
Config: throttlestore.ThrottleOverrideConfig{
Rate: 50,
},
},
// Topics that include this broker shouldn't be included; the
// BrokerThrottleOverride.Filter called in getTopicsWithThrottledBrokers
// excludes any topics mapped to brokers where ReassignmentParticipant
// == true.
1002: throttlestore.BrokerThrottleOverride{
ID: 1002,
ReassignmentParticipant: true,
Config: throttlestore.ThrottleOverrideConfig{
Rate: 50,
},
},
}
// Call.
topicThrottledBrokers, _ := rtf.legacyGetTopicsWithThrottledBrokers()
expected := topicThrottledReplicas{
"test_topic": throttled{"followers": brokerIDs{"0:1001"}},
"test_topic2": throttled{"followers": brokerIDs{"0:1001"}},
}
if len(topicThrottledBrokers) != len(expected) {
t.Fatalf("Expected len %d, got %d", len(expected), len(topicThrottledBrokers))
}
for topic := range expected {
output, exist := topicThrottledBrokers[topic]
if !exist {
t.Fatalf("Expected topic '%s' in output", topic)
}
got := output["followers"][0]
expectedOut := expected[topic]["followers"][0]
if got != expectedOut {
t.Errorf("Expected followers '%s', got '%s'", expectedOut, got)
}
}
}
/*
func TestFilter(t *testing.T) {
zk := &kafkazk.Stub{}
state, _ := zk.GetTopicState("test_topic")
topicStates := make(TopicStates)
topicStates["test_topic"] = *state
matchID := 1000
// Our filter func. returns any topic that includes matchID as a replica.
fn := func(ts mapper.TopicState) bool {
// The stub partition state here is []int{1000,1001}.
for _, id := range ts.Partitions["0"] {
if id == matchID {
return true
}
}
return false
}
// We should get back one topic.
filtered := topicStates.Filter(fn)
_, match := filtered["test_topic"]
if len(filtered) != 1 && !match {
t.Errorf("Expected key 'test_topic'")
}
matchID = 9999
// We should now have no matched topics.
filtered = topicStates.Filter(fn)
if len(filtered) != 0 {
t.Errorf("Expected nil filtered result")
}
}
*/