forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter_client_quotas_request_test.go
154 lines (143 loc) · 4.59 KB
/
alter_client_quotas_request_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package sarama
import "testing"
var (
alterClientQuotasRequestSingleOp = []byte{
0, 0, 0, 1, // entries len
0, 0, 0, 1, // entity len
0, 4, 'u', 's', 'e', 'r', // entity type
255, 255, // entity value
0, 0, 0, 1, // ops len
0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
65, 46, 132, 128, 0, 0, 0, 0, // op value (1000000)
0, // remove
0, // validate only
}
alterClientQuotasRequestRemoveSingleOp = []byte{
0, 0, 0, 1, // entries len
0, 0, 0, 1, // entity len
0, 4, 'u', 's', 'e', 'r', // entity type
255, 255, // entity value
0, 0, 0, 1, // ops len
0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
0, 0, 0, 0, 0, 0, 0, 0, // op value (ignored)
1, // remove
1, // validate only
}
alterClientQuotasRequestMultipleOps = []byte{
0, 0, 0, 1, // entries len
0, 0, 0, 1, // entity len
0, 4, 'u', 's', 'e', 'r', // entity type
255, 255, // entity value
0, 0, 0, 2, // ops len
0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
65, 46, 132, 128, 0, 0, 0, 0, // op value (1000000)
0, // remove
0, 18, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
65, 46, 132, 128, 0, 0, 0, 0, // op value (1000000)
0, // remove
0, // validate only
}
alterClientQuotasRequestMultipleQuotasEntries = []byte{
0, 0, 0, 2, // entries len
0, 0, 0, 1, // entity len
0, 4, 'u', 's', 'e', 'r', // entity type
255, 255, // entity value
0, 0, 0, 1, // ops len
0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
65, 46, 132, 128, 0, 0, 0, 0, // op value (1000000)
0, // remove
0, 0, 0, 1, // entity len
0, 9, 'c', 'l', 'i', 'e', 'n', 't', '-', 'i', 'd', // entity type
255, 255, // entity value
0, 0, 0, 1, // ops len
0, 18, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e', // op key
65, 46, 132, 128, 0, 0, 0, 0, // op value (1000000)
0, // remove
0, // validate only
}
)
func TestAlterClientQuotasRequest(t *testing.T) {
// default user
defaultUserComponent := QuotaEntityComponent{
EntityType: QuotaEntityUser,
MatchType: QuotaMatchDefault,
}
// default client-id
defaultClientIDComponent := QuotaEntityComponent{
EntityType: QuotaEntityClientID,
MatchType: QuotaMatchDefault,
}
// Add Quota to default user
op := ClientQuotasOp{
Key: "producer_byte_rate",
Value: 1000000,
Remove: false,
}
entry := AlterClientQuotasEntry{
Entity: []QuotaEntityComponent{defaultUserComponent},
Ops: []ClientQuotasOp{op},
}
req := &AlterClientQuotasRequest{
Entries: []AlterClientQuotasEntry{entry},
ValidateOnly: false,
}
testRequest(t, "Add single Quota op", req, alterClientQuotasRequestSingleOp)
// Remove Quota from default user
op = ClientQuotasOp{
Key: "producer_byte_rate",
Remove: true,
}
entry = AlterClientQuotasEntry{
Entity: []QuotaEntityComponent{defaultUserComponent},
Ops: []ClientQuotasOp{op},
}
req = &AlterClientQuotasRequest{
Entries: []AlterClientQuotasEntry{entry},
ValidateOnly: true,
}
testRequest(t, "Remove single Quota op", req, alterClientQuotasRequestRemoveSingleOp)
// Add multiple Quotas ops
op1 := ClientQuotasOp{
Key: "producer_byte_rate",
Value: 1000000,
Remove: false,
}
op2 := ClientQuotasOp{
Key: "consumer_byte_rate",
Value: 1000000,
Remove: false,
}
entry = AlterClientQuotasEntry{
Entity: []QuotaEntityComponent{defaultUserComponent},
Ops: []ClientQuotasOp{op1, op2},
}
req = &AlterClientQuotasRequest{
Entries: []AlterClientQuotasEntry{entry},
ValidateOnly: false,
}
testRequest(t, "Add multiple Quota ops", req, alterClientQuotasRequestMultipleOps)
// Add multiple Quotas Entries
op1 = ClientQuotasOp{
Key: "producer_byte_rate",
Value: 1000000,
Remove: false,
}
entry1 := AlterClientQuotasEntry{
Entity: []QuotaEntityComponent{defaultUserComponent},
Ops: []ClientQuotasOp{op1},
}
op2 = ClientQuotasOp{
Key: "consumer_byte_rate",
Value: 1000000,
Remove: false,
}
entry2 := AlterClientQuotasEntry{
Entity: []QuotaEntityComponent{defaultClientIDComponent},
Ops: []ClientQuotasOp{op2},
}
req = &AlterClientQuotasRequest{
Entries: []AlterClientQuotasEntry{entry1, entry2},
ValidateOnly: false,
}
testRequest(t, "Add multiple Quotas Entries", req, alterClientQuotasRequestMultipleQuotasEntries)
}