@@ -206,6 +206,16 @@ def consume_messages(config, queue: Queue.new, timeout:, event_count:)
206
206
207
207
208
208
describe "schema registry connection options" do
209
+ schema_registry = Manticore ::Client . new
210
+ before ( :all ) do
211
+ shutdown_schema_registry
212
+ startup_schema_registry ( schema_registry )
213
+ end
214
+
215
+ after ( :all ) do
216
+ shutdown_schema_registry
217
+ end
218
+
209
219
context "remote endpoint validation" do
210
220
it "should fail if not reachable" do
211
221
config = { 'schema_registry_url' => 'http://localnothost:8081' }
@@ -232,8 +242,7 @@ def consume_messages(config, queue: Queue.new, timeout:, event_count:)
232
242
end
233
243
234
244
after ( :each ) do
235
- schema_registry_client = Manticore ::Client . new
236
- delete_remote_schema ( schema_registry_client , SUBJECT_NAME )
245
+ delete_remote_schema ( schema_registry , SUBJECT_NAME )
237
246
end
238
247
239
248
it "should correctly complete registration phase" do
@@ -264,9 +273,25 @@ def delete_remote_schema(schema_registry_client, subject_name)
264
273
265
274
# AdminClientConfig = org.alpache.kafka.clients.admin.AdminClientConfig
266
275
276
+ def startup_schema_registry ( schema_registry , auth = false )
277
+ system ( './stop_schema_registry.sh' )
278
+ auth ? system ( './start_auth_schema_registry.sh' ) : system ( './start_schema_registry.sh' )
279
+ url = auth ? "http://barney:changeme@localhost:8081" : "http://localhost:8081"
280
+ Stud . try ( 20 . times , [ Manticore ::SocketException , StandardError , RSpec ::Expectations ::ExpectationNotMetError ] ) do
281
+ expect ( schema_registry . get ( url ) . code ) . to eq ( 200 )
282
+ end
283
+ end
284
+
267
285
describe "Schema registry API" , :integration => true do
286
+ schema_registry = Manticore ::Client . new
287
+
288
+ before ( :all ) do
289
+ startup_schema_registry ( schema_registry )
290
+ end
268
291
269
- let ( :schema_registry ) { Manticore ::Client . new }
292
+ after ( :all ) do
293
+ shutdown_schema_registry
294
+ end
270
295
271
296
context 'listing subject on clean instance' do
272
297
it "should return an empty set" do
@@ -292,37 +317,58 @@ def delete_remote_schema(schema_registry_client, subject_name)
292
317
expect ( subjects ) . to be_empty
293
318
end
294
319
end
320
+ end
321
+
322
+ def shutdown_schema_registry
323
+ system ( './stop_schema_registry.sh' )
324
+ end
325
+
326
+ describe "Deserializing with the schema registry" , :integration => true do
327
+ schema_registry = Manticore ::Client . new
328
+
329
+ shared_examples 'it reads from a topic using a schema registry' do |with_auth |
330
+
331
+ before ( :all ) do
332
+ shutdown_schema_registry
333
+ startup_schema_registry ( schema_registry , with_auth )
334
+ end
335
+
336
+ after ( :all ) do
337
+ shutdown_schema_registry
338
+ end
295
339
296
- context 'use the schema to serialize' do
297
340
after ( :each ) do
298
- expect ( schema_registry . delete ( 'http://localhost:8081/subjects/topic_avro -value' ) . code ) . to be ( 200 )
341
+ expect ( schema_registry . delete ( " #{ subject_url } / #{ avro_topic_name } -value" ) . code ) . to be ( 200 )
299
342
sleep 1
300
- expect ( schema_registry . delete ( 'http://localhost:8081/subjects/topic_avro -value?permanent=true' ) . code ) . to be ( 200 )
343
+ expect ( schema_registry . delete ( " #{ subject_url } / #{ avro_topic_name } -value?permanent=true" ) . code ) . to be ( 200 )
301
344
302
345
Stud . try ( 3 . times , [ StandardError , RSpec ::Expectations ::ExpectationNotMetError ] ) do
303
346
wait ( 10 ) . for do
304
- subjects = JSON . parse schema_registry . get ( 'http://localhost:8081/subjects' ) . body
347
+ subjects = JSON . parse schema_registry . get ( subject_url ) . body
305
348
subjects . empty?
306
349
end . to be_truthy
307
350
end
308
351
end
309
352
310
- let ( :group_id_1 ) { rand ( 36 **8 ) . to_s ( 36 ) }
311
-
312
- let ( :avro_topic_name ) { "topic_avro" }
313
-
314
- let ( :plain_config ) do
315
- { 'schema_registry_url' => 'http://localhost:8081' ,
316
- 'topics' => [ avro_topic_name ] ,
317
- 'codec' => 'plain' ,
318
- 'group_id' => group_id_1 ,
319
- 'auto_offset_reset' => 'earliest' }
353
+ let ( :base_config ) do
354
+ {
355
+ 'topics' => [ avro_topic_name ] ,
356
+ 'codec' => 'plain' ,
357
+ 'group_id' => group_id_1 ,
358
+ 'auto_offset_reset' => 'earliest'
359
+ }
320
360
end
321
361
322
- def delete_topic_if_exists ( topic_name )
362
+ let ( :group_id_1 ) { rand ( 36 **8 ) . to_s ( 36 ) }
363
+
364
+ def delete_topic_if_exists ( topic_name , user = nil , password = nil )
323
365
props = java . util . Properties . new
324
366
props . put ( Java ::org . apache . kafka . clients . admin . AdminClientConfig ::BOOTSTRAP_SERVERS_CONFIG , "localhost:9092" )
325
-
367
+ serdes_config = Java ::io . confluent . kafka . serializers . AbstractKafkaAvroSerDeConfig
368
+ unless user . nil?
369
+ props . put ( serdes_config ::BASIC_AUTH_CREDENTIALS_SOURCE , 'USER_INFO' )
370
+ props . put ( serdes_config ::USER_INFO_CONFIG , "#{ user } :#{ password } " )
371
+ end
326
372
admin_client = org . apache . kafka . clients . admin . AdminClient . create ( props )
327
373
topics_list = admin_client . listTopics ( ) . names ( ) . get ( )
328
374
if topics_list . contains ( topic_name )
@@ -331,14 +377,18 @@ def delete_topic_if_exists(topic_name)
331
377
end
332
378
end
333
379
334
- def write_some_data_to ( topic_name )
380
+ def write_some_data_to ( topic_name , user = nil , password = nil )
335
381
props = java . util . Properties . new
336
382
config = org . apache . kafka . clients . producer . ProducerConfig
337
383
338
384
serdes_config = Java ::io . confluent . kafka . serializers . AbstractKafkaAvroSerDeConfig
339
385
props . put ( serdes_config ::SCHEMA_REGISTRY_URL_CONFIG , "http://localhost:8081" )
340
386
341
387
props . put ( config ::BOOTSTRAP_SERVERS_CONFIG , "localhost:9092" )
388
+ unless user . nil?
389
+ props . put ( serdes_config ::BASIC_AUTH_CREDENTIALS_SOURCE , 'USER_INFO' )
390
+ props . put ( serdes_config ::USER_INFO_CONFIG , "#{ user } :#{ password } " )
391
+ end
342
392
props . put ( config ::KEY_SERIALIZER_CLASS_CONFIG , org . apache . kafka . common . serialization . StringSerializer . java_class )
343
393
props . put ( config ::VALUE_SERIALIZER_CLASS_CONFIG , Java ::io . confluent . kafka . serializers . KafkaAvroSerializer . java_class )
344
394
@@ -360,11 +410,11 @@ def write_some_data_to(topic_name)
360
410
end
361
411
362
412
it "stored a new schema using Avro Kafka serdes" do
363
- delete_topic_if_exists avro_topic_name
364
- write_some_data_to avro_topic_name
413
+ auth ? delete_topic_if_exists ( avro_topic_name , user , password ) : delete_topic_if_exists ( avro_topic_name )
414
+ auth ? write_some_data_to ( avro_topic_name , user , password ) : write_some_data_to ( avro_topic_name )
365
415
366
- subjects = JSON . parse schema_registry . get ( 'http://localhost:8081/subjects' ) . body
367
- expect ( subjects ) . to contain_exactly ( "topic_avro -value" )
416
+ subjects = JSON . parse schema_registry . get ( subject_url ) . body
417
+ expect ( subjects ) . to contain_exactly ( "#{ avro_topic_name } -value" )
368
418
369
419
num_events = 1
370
420
queue = consume_messages ( plain_config , timeout : 30 , event_count : num_events )
@@ -375,4 +425,43 @@ def write_some_data_to(topic_name)
375
425
expect ( elem . get ( "map_field" ) [ "inner_field" ] ) . to eq ( "inner value" )
376
426
end
377
427
end
428
+
429
+ context 'with an unauthed schema registry' do
430
+ let ( :auth ) { false }
431
+ let ( :avro_topic_name ) { "topic_avro" }
432
+ let ( :subject_url ) { "http://localhost:8081/subjects" }
433
+ let ( :plain_config ) { base_config . merge! ( { 'schema_registry_url' => "http://localhost:8081" } ) }
434
+
435
+ it_behaves_like 'it reads from a topic using a schema registry' , false
436
+ end
437
+
438
+ context 'with an authed schema registry' do
439
+ let ( :auth ) { true }
440
+ let ( :user ) { "barney" }
441
+ let ( :password ) { "changeme" }
442
+ let ( :avro_topic_name ) { "topic_avro_auth" }
443
+ let ( :subject_url ) { "http://#{ user } :#{ password } @localhost:8081/subjects" }
444
+
445
+ context 'using schema_registry_key' do
446
+ let ( :plain_config ) do
447
+ base_config . merge! ( {
448
+ 'schema_registry_url' => "http://localhost:8081" ,
449
+ 'schema_registry_key' => user ,
450
+ 'schema_registry_secret' => password
451
+ } )
452
+ end
453
+
454
+ it_behaves_like 'it reads from a topic using a schema registry' , true
455
+ end
456
+
457
+ context 'using schema_registry_url' do
458
+ let ( :plain_config ) do
459
+ base_config . merge! ( {
460
+ 'schema_registry_url' => "http://#{ user } :#{ password } @localhost:8081"
461
+ } )
462
+ end
463
+
464
+ it_behaves_like 'it reads from a topic using a schema registry' , true
465
+ end
466
+ end
378
467
end
0 commit comments