-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FDP-2470: Add serializer and deserializer tests
Signed-off-by: Jasper Kamerling <[email protected]>
- Loading branch information
1 parent
3f05a57
commit 91aa15c
Showing
7 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"type": "record", | ||
"name": "AvroSchema1", | ||
"namespace": "com.alliander.gxf.utilities.kafka.avro", | ||
"fields": [ | ||
{ | ||
"name": "field1", | ||
"type": { | ||
"type": "string", | ||
"avro.java.string": "String" | ||
} | ||
}, | ||
{ | ||
"name": "field2", | ||
"type": { | ||
"type": "string", | ||
"avro.java.string": "String" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "record", | ||
"name": "AvroSchema2", | ||
"namespace": "com.alliander.gxf.utilities.kafka.avro", | ||
"fields": [ | ||
{ | ||
"name": "message2", | ||
"type": { | ||
"type": "string", | ||
"avro.java.string": "String" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "record", | ||
"name": "AvroSchema3", | ||
"namespace": "com.alliander.gxf.utilities.kafka.avro", | ||
"fields": [ | ||
{ | ||
"name": "message3", | ||
"type": { | ||
"type": "string", | ||
"avro.java.string": "String" | ||
} | ||
} | ||
] | ||
} |
30 changes: 30 additions & 0 deletions
30
kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gxf.utilities.kafka.avro | ||
|
||
import com.alliander.gxf.utilities.kafka.avro.AvroSchema1 | ||
import com.alliander.gxf.utilities.kafka.avro.AvroSchema2 | ||
import com.alliander.gxf.utilities.kafka.avro.AvroSchema3 | ||
import org.apache.kafka.common.errors.SerializationException | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.jupiter.api.Test | ||
|
||
class AvroDeserializerTest { | ||
|
||
@Test | ||
fun avroDeserializerTest() { | ||
val message1 = AvroSchema1("field no 1", "field no 2") | ||
val message2 = AvroSchema2("message in a bottle") | ||
val message3 = AvroSchema3("message in a bottle") | ||
val deserializer = AvroDeserializer(listOf(AvroSchema1.getClassSchema(), AvroSchema2.getClassSchema())) | ||
|
||
assertThat(deserializer.deserialize("topic1", message1.toByteBuffer().array())) | ||
.isEqualTo(message1) | ||
assertThat(deserializer.deserialize("topic2", message2.toByteBuffer().array())) | ||
.isEqualTo(message2) | ||
|
||
assertThatThrownBy({deserializer.deserialize("topic3", message3.toByteBuffer().array())}) | ||
.isInstanceOf(SerializationException::class.java) | ||
.hasMessageContaining("Error deserializing Avro message for topic: topic3"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gxf.utilities.kafka.avro | ||
|
||
import com.alliander.gxf.utilities.kafka.avro.AvroSchema1 | ||
import com.alliander.gxf.utilities.kafka.avro.AvroSchema2 | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class AvroSerializerTest { | ||
@Test | ||
fun testEncodersCache() { | ||
val message1 = AvroSchema1("field no 1", "field no 2") | ||
val message2 = AvroSchema2("message in a bottle") | ||
val serializer = AvroSerializer() | ||
|
||
serializer.serialize("", message1) | ||
serializer.serialize("", message2) | ||
|
||
assertThat(AvroEncoder.encoders).containsKeys(AvroSchema1::class) | ||
assertThat(AvroEncoder.encoders).containsKeys(AvroSchema2::class) | ||
assertThat(AvroEncoder.encoders.size).isEqualTo(2) | ||
} | ||
} |