@@ -41,9 +41,11 @@ func invalidMessage() *cb.ConfigValue {
41
41
}
42
42
}
43
43
44
- // A temporary method while ConfigItem is being deprecated
45
- func itemToValue (configItem * cb.ConfigItem ) (string , * cb.ConfigValue ) {
46
- return configItem .Key , & cb.ConfigValue {Value : configItem .Value }
44
+ func groupToKeyValue (configGroup * cb.ConfigGroup ) (string , * cb.ConfigValue ) {
45
+ for key , value := range configGroup .Groups [GroupKey ].Values {
46
+ return key , value
47
+ }
48
+ panic ("No value encoded" )
47
49
}
48
50
49
51
func doesFuncCrash (crasher func (), test string ) bool {
@@ -102,7 +104,7 @@ func TestConsensusType(t *testing.T) {
102
104
m := NewManagerImpl (nil )
103
105
m .BeginConfig ()
104
106
105
- err := m .ProposeConfig (itemToValue (validMessage ))
107
+ err := m .ProposeConfig (groupToKeyValue (validMessage ))
106
108
if err != nil {
107
109
t .Fatalf ("Error applying valid config: %s" , err )
108
110
}
@@ -115,12 +117,12 @@ func TestConsensusType(t *testing.T) {
115
117
t .Fatalf ("Should have failed on invalid message" )
116
118
}
117
119
118
- err = m .ProposeConfig (itemToValue (validMessage ))
120
+ err = m .ProposeConfig (groupToKeyValue (validMessage ))
119
121
if err != nil {
120
122
t .Fatalf ("Error re-applying valid config: %s" , err )
121
123
}
122
124
123
- err = m .ProposeConfig (itemToValue (otherValidMessage ))
125
+ err = m .ProposeConfig (groupToKeyValue (otherValidMessage ))
124
126
if err == nil {
125
127
t .Fatalf ("Should not have applied config with different consensus type after it was initially set" )
126
128
}
@@ -142,7 +144,7 @@ func TestBatchSize(t *testing.T) {
142
144
m := NewManagerImpl (nil )
143
145
m .BeginConfig ()
144
146
err := m .ProposeConfig (
145
- itemToValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validPreferredMaxBytes })),
147
+ groupToKeyValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validPreferredMaxBytes })),
146
148
)
147
149
assert .Nil (t , err , "Error applying valid config: %s" , err )
148
150
m .CommitConfig ()
@@ -168,23 +170,23 @@ func TestBatchSize(t *testing.T) {
168
170
t .Run ("ZeroMaxMessageCount" , func (t * testing.T ) {
169
171
m := NewManagerImpl (nil )
170
172
m .BeginConfig ()
171
- err := m .ProposeConfig (itemToValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : 0 , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validPreferredMaxBytes })))
173
+ err := m .ProposeConfig (groupToKeyValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : 0 , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validPreferredMaxBytes })))
172
174
assert .NotNil (t , err , "Should have rejected batch size max message count of 0" )
173
175
m .CommitConfig ()
174
176
})
175
177
176
178
t .Run ("ZeroAbsoluteMaxBytes" , func (t * testing.T ) {
177
179
m := NewManagerImpl (nil )
178
180
m .BeginConfig ()
179
- err := m .ProposeConfig (itemToValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : 0 , PreferredMaxBytes : validPreferredMaxBytes })))
181
+ err := m .ProposeConfig (groupToKeyValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : 0 , PreferredMaxBytes : validPreferredMaxBytes })))
180
182
assert .NotNil (t , err , "Should have rejected batch size absolute max message bytes of 0" )
181
183
m .CommitConfig ()
182
184
})
183
185
184
186
t .Run ("TooLargePreferredMaxBytes" , func (t * testing.T ) {
185
187
m := NewManagerImpl (nil )
186
188
m .BeginConfig ()
187
- err := m .ProposeConfig (itemToValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validAbsoluteMaxBytes + 1 })))
189
+ err := m .ProposeConfig (groupToKeyValue (TemplateBatchSize (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : validAbsoluteMaxBytes , PreferredMaxBytes : validAbsoluteMaxBytes + 1 })))
188
190
assert .NotNil (t , err , "Should have rejected batch size preferred max message bytes greater than absolute max message bytes" )
189
191
m .CommitConfig ()
190
192
})
@@ -200,7 +202,7 @@ func TestBatchTimeout(t *testing.T) {
200
202
m := NewManagerImpl (nil )
201
203
m .BeginConfig ()
202
204
203
- err := m .ProposeConfig (itemToValue (validMessage ))
205
+ err := m .ProposeConfig (groupToKeyValue (validMessage ))
204
206
if err != nil {
205
207
t .Fatalf ("Error applying valid config: %s" , err )
206
208
}
@@ -210,12 +212,12 @@ func TestBatchTimeout(t *testing.T) {
210
212
t .Fatalf ("Should have failed on invalid message" )
211
213
}
212
214
213
- err = m .ProposeConfig (itemToValue (negativeBatchTimeout ))
215
+ err = m .ProposeConfig (groupToKeyValue (negativeBatchTimeout ))
214
216
if err == nil {
215
217
t .Fatalf ("Should have rejected negative batch timeout: %s" , err )
216
218
}
217
219
218
- err = m .ProposeConfig (itemToValue (zeroBatchTimeout ))
220
+ err = m .ProposeConfig (groupToKeyValue (zeroBatchTimeout ))
219
221
if err == nil {
220
222
t .Fatalf ("Should have rejected batch timeout of 0" )
221
223
}
@@ -233,7 +235,7 @@ func TestKafkaBrokers(t *testing.T) {
233
235
invalidMessage := invalidMessage ()
234
236
zeroBrokers := TemplateKafkaBrokers ([]string {})
235
237
badList := []string {"127.0.0.1" , "foo.bar" , "127.0.0.1:-1" , "localhost:65536" , "foo.bar.:9092" , ".127.0.0.1:9092" , "-foo.bar:9092" }
236
- badMessages := []* cb.ConfigItem {}
238
+ badMessages := []* cb.ConfigGroup {}
237
239
for _ , badAddress := range badList {
238
240
badMessages = append (badMessages , TemplateKafkaBrokers ([]string {badAddress }))
239
241
}
@@ -243,7 +245,7 @@ func TestKafkaBrokers(t *testing.T) {
243
245
m := NewManagerImpl (nil )
244
246
m .BeginConfig ()
245
247
246
- err := m .ProposeConfig (itemToValue (validMessage ))
248
+ err := m .ProposeConfig (groupToKeyValue (validMessage ))
247
249
if err != nil {
248
250
t .Fatalf ("Error applying valid config: %s" , err )
249
251
}
@@ -253,13 +255,13 @@ func TestKafkaBrokers(t *testing.T) {
253
255
t .Fatalf ("Should have failed on invalid message" )
254
256
}
255
257
256
- err = m .ProposeConfig (itemToValue (zeroBrokers ))
258
+ err = m .ProposeConfig (groupToKeyValue (zeroBrokers ))
257
259
if err == nil {
258
260
t .Fatalf ("Should have rejected empty brokers list" )
259
261
}
260
262
261
263
for i := range badMessages {
262
- err = m .ProposeConfig (itemToValue (badMessages [i ]))
264
+ err = m .ProposeConfig (groupToKeyValue (badMessages [i ]))
263
265
if err == nil {
264
266
t .Fatalf ("Should have rejected broker address which is obviously malformed" )
265
267
}
@@ -276,14 +278,14 @@ func TestKafkaBrokers(t *testing.T) {
276
278
}
277
279
}
278
280
279
- func testPolicyNames (m * ManagerImpl , key string , initializer func (val []string ) * cb.ConfigItem , retriever func () []string , t * testing.T ) {
281
+ func testPolicyNames (m * ManagerImpl , key string , initializer func (val []string ) * cb.ConfigGroup , retriever func () []string , t * testing.T ) {
280
282
endPolicy := []string {"foo" , "bar" }
281
283
invalidMessage := invalidMessage ()
282
284
validMessage := initializer (endPolicy )
283
285
284
286
m .BeginConfig ()
285
287
286
- err := m .ProposeConfig (itemToValue (validMessage ))
288
+ err := m .ProposeConfig (groupToKeyValue (validMessage ))
287
289
if err != nil {
288
290
t .Fatalf ("Error applying valid config: %s" , err )
289
291
}
@@ -296,7 +298,7 @@ func testPolicyNames(m *ManagerImpl, key string, initializer func(val []string)
296
298
t .Fatalf ("Should have failed on invalid message" )
297
299
}
298
300
299
- err = m .ProposeConfig (itemToValue (validMessage ))
301
+ err = m .ProposeConfig (groupToKeyValue (validMessage ))
300
302
if err != nil {
301
303
t .Fatalf ("Error re-applying valid config: %s" , err )
302
304
}
@@ -328,7 +330,7 @@ func TestEmptyChainCreationPolicyNames(t *testing.T) {
328
330
329
331
m .BeginConfig ()
330
332
331
- err := m .ProposeConfig (itemToValue (TemplateChainCreationPolicyNames (nil )))
333
+ err := m .ProposeConfig (groupToKeyValue (TemplateChainCreationPolicyNames (nil )))
332
334
if err != nil {
333
335
t .Fatalf ("Error applying valid config: %s" , err )
334
336
}
0 commit comments