@@ -12,7 +12,11 @@ import stringify from 'json-stringify-deterministic';
12
12
import { v4 } from 'uuid' ;
13
13
14
14
let schemaRegistryClient : SchemaRegistryClient ;
15
- let producer : any ;
15
+ let serializerConfig : AvroSerializerConfig ;
16
+ let serializer : AvroSerializer ;
17
+ let deserializer : AvroDeserializer ;
18
+ let producer : KafkaJS . Producer ;
19
+ let consumer : KafkaJS . Consumer ;
16
20
17
21
const kafkaBrokerList = 'localhost:9092' ;
18
22
const kafka = new KafkaJS . Kafka ( {
@@ -48,11 +52,6 @@ const schemaInfo: SchemaInfo = {
48
52
metadata : metadata
49
53
} ;
50
54
51
- let serializerConfig : AvroSerializerConfig ;
52
- let serializer : AvroSerializer ;
53
- let deserializer : AvroDeserializer ;
54
- let consumer : KafkaJS . Consumer ;
55
-
56
55
describe ( 'Schema Registry Avro Integration Test' , ( ) => {
57
56
58
57
beforeEach ( async ( ) => {
@@ -78,15 +77,14 @@ describe('Schema Registry Avro Integration Test', () => {
78
77
79
78
afterEach ( async ( ) => {
80
79
await producer . disconnect ( ) ;
81
- producer = null ;
82
80
} ) ;
83
81
84
82
it ( "Should serialize and deserialize Avro" , async ( ) => {
85
- const testTopic = 'test-topic-' + v4 ( ) ;
83
+ const testTopic = v4 ( ) ;
86
84
87
- await schemaRegistryClient . register ( testTopic , schemaInfo ) ;
85
+ await schemaRegistryClient . register ( testTopic + "-value" , schemaInfo ) ;
88
86
89
- serializerConfig = { autoRegisterSchemas : true } ;
87
+ serializerConfig = { useLatestVersion : true } ;
90
88
serializer = new AvroSerializer ( schemaRegistryClient , SerdeType . VALUE , serializerConfig ) ;
91
89
deserializer = new AvroDeserializer ( schemaRegistryClient , SerdeType . VALUE , { } ) ;
92
90
@@ -123,28 +121,8 @@ describe('Schema Registry Avro Integration Test', () => {
123
121
await consumer . disconnect ( ) ;
124
122
} , 30000 ) ;
125
123
126
- it ( " Should serialize with UseLatestVersion enabled" , async ( ) => {
124
+ it ( ' Should fail to serialize with useLatestVersion enabled and autoRegisterSchemas disabled' , async ( ) => {
127
125
const testTopic = v4 ( ) ;
128
- await schemaRegistryClient . register ( testTopic , schemaInfo ) ;
129
-
130
- serializerConfig = { autoRegisterSchemas : true , useLatestVersion : true } ;
131
- serializer = new AvroSerializer ( schemaRegistryClient , SerdeType . VALUE , serializerConfig ) ;
132
-
133
- const outgoingMessage = {
134
- key : 'key' ,
135
- value : await serializer . serialize ( testTopic , messageValue )
136
- } ;
137
-
138
- await producer . send ( {
139
- topic : testTopic ,
140
- messages : [ outgoingMessage ]
141
- } ) ;
142
-
143
- } , 30000 ) ;
144
-
145
- it ( 'Should fail to serialize with UseLatestVersion enabled and autoRegisterSchemas disabled' , async ( ) => {
146
- const testTopic = v4 ( ) ;
147
- await schemaRegistryClient . register ( testTopic , schemaInfo ) ;
148
126
149
127
serializerConfig = { autoRegisterSchemas : false , useLatestVersion : true } ;
150
128
serializer = new AvroSerializer ( schemaRegistryClient , SerdeType . VALUE , serializerConfig ) ;
@@ -154,12 +132,11 @@ describe('Schema Registry Avro Integration Test', () => {
154
132
await expect ( serializer . serialize ( testTopic , messageValue ) ) . rejects . toThrowError ( ) ;
155
133
} ) ;
156
134
157
- it ( 'Should serialize with schemas registered, UseLatestVersion enabled and autoRegisterSchemas disabled' , async ( ) => {
135
+ it ( 'Should serialize with autoRegisterSchemas enabled and useLatestVersion disabled' , async ( ) => {
158
136
const testTopic = v4 ( ) ;
159
- await schemaRegistryClient . register ( testTopic , schemaInfo ) ;
160
- await schemaRegistryClient . register ( testTopic + '-value' , schemaInfo ) ;
137
+ await schemaRegistryClient . register ( testTopic + ' -value' , schemaInfo ) ;
161
138
162
- serializerConfig = { autoRegisterSchemas : false , useLatestVersion : true } ;
139
+ serializerConfig = { autoRegisterSchemas : true , useLatestVersion : false } ;
163
140
serializer = new AvroSerializer ( schemaRegistryClient , SerdeType . VALUE , serializerConfig ) ;
164
141
165
142
const messageValue = { "name" : "Bob Jones" , "age" : 25 } ;
@@ -257,7 +234,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
257
234
}
258
235
} ) ;
259
236
await producer . connect ( ) ;
260
- serializerConfig = { autoRegisterSchemas : true } ;
237
+ serializerConfig = { useLatestVersion : true } ;
261
238
262
239
serializer = new AvroSerializer ( schemaRegistryClient , SerdeType . VALUE , serializerConfig ) ;
263
240
deserializer = new AvroDeserializer ( schemaRegistryClient , SerdeType . VALUE , { } ) ;
@@ -272,7 +249,6 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
272
249
273
250
afterEach ( async ( ) => {
274
251
await producer . disconnect ( ) ;
275
- producer = null ;
276
252
} ) ;
277
253
278
254
it ( 'Should serialize and deserialize string' , async ( ) => {
@@ -287,7 +263,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
287
263
metadata : metadata
288
264
} ;
289
265
290
- await schemaRegistryClient . register ( stringTopic , stringSchemaInfo ) ;
266
+ await schemaRegistryClient . register ( stringTopic + "-value" , stringSchemaInfo ) ;
291
267
292
268
const stringMessageValue = "Hello, World!" ;
293
269
const outgoingStringMessage = {
@@ -335,7 +311,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
335
311
metadata : metadata
336
312
} ;
337
313
338
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
314
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
339
315
340
316
const messageValue = Buffer . from ( "Hello, World!" ) ;
341
317
const outgoingMessage = {
@@ -383,7 +359,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
383
359
metadata : metadata
384
360
} ;
385
361
386
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
362
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
387
363
388
364
const messageValue = 25 ;
389
365
const outgoingMessage = {
@@ -431,7 +407,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
431
407
metadata : metadata
432
408
} ;
433
409
434
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
410
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
435
411
436
412
const messageValue = 25 ;
437
413
const outgoingMessage = {
@@ -479,7 +455,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
479
455
metadata : metadata
480
456
} ;
481
457
482
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
458
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
483
459
484
460
const messageValue = true ;
485
461
const outgoingMessage = {
@@ -527,7 +503,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
527
503
metadata : metadata
528
504
} ;
529
505
530
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
506
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
531
507
532
508
const messageValue = 1.354 ;
533
509
const outgoingMessage = {
@@ -575,7 +551,7 @@ describe('Schema Registry Avro Integration Test - Primitives', () => {
575
551
metadata : metadata
576
552
} ;
577
553
578
- await schemaRegistryClient . register ( topic , stringSchemaInfo ) ;
554
+ await schemaRegistryClient . register ( topic + "-value" , stringSchemaInfo ) ;
579
555
580
556
const messageValue = 1.354 ;
581
557
const outgoingMessage = {
0 commit comments