-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reader/writer schema on binary reader factory
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 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
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
42 changes: 42 additions & 0 deletions
42
centurion-avro/src/test/kotlin/com/sksamuel/centurion/avro/EvolutionTest.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,42 @@ | ||
package com.sksamuel.centurion.avro | ||
|
||
import com.sksamuel.centurion.avro.io.BinaryReaderFactory | ||
import com.sksamuel.centurion.avro.io.BinaryWriterFactory | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.apache.avro.SchemaBuilder | ||
import org.apache.avro.generic.GenericData | ||
import org.apache.avro.util.Utf8 | ||
|
||
class EvolutionTest : FunSpec() { | ||
|
||
init { | ||
test("evolve schema by adding a nullable field") { | ||
|
||
val schema1 = SchemaBuilder.record("foo").fields() | ||
.requiredString("a") | ||
.requiredBoolean("b") | ||
.endRecord() | ||
|
||
val schema2 = SchemaBuilder.record("foo").fields() | ||
.requiredString("a") | ||
.requiredBoolean("b") | ||
.optionalString("c") | ||
.endRecord() | ||
|
||
val record1 = GenericData.Record(schema1) | ||
record1.put("a", "hello") | ||
record1.put("b", true) | ||
|
||
val bytes = BinaryWriterFactory.write(record1) | ||
val record2 = BinaryReaderFactory(schema2, schema1).read(bytes) | ||
|
||
record2["a"] shouldBe Utf8("hello") | ||
record2["b"] shouldBe true | ||
record2["c"] shouldBe null | ||
|
||
} | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -12,7 +12,7 @@ class SerdeTest : FunSpec({ | |
|
||
test("round trip happy path") { | ||
val user = User(Random.nextLong(), "sammy mcsamface", "[email protected]", Random.nextLong(), UserType.Admin) | ||
val serde = Serde<User>() | ||
val serde = ReflectionSerdeFactory.create<User>() | ||
serde.deserialize(serde.serialize(user)) shouldBe user | ||
} | ||
|
||
|
@@ -24,8 +24,8 @@ class SerdeTest : FunSpec({ | |
Random.nextLong(), | ||
UserType.Admin | ||
) | ||
val serde1 = Serde<User>() | ||
val serde2 = Serde<User>(SerdeOptions(codec = BZip2Codec())) | ||
val serde1 = ReflectionSerdeFactory.create<User>() | ||
val serde2 = ReflectionSerdeFactory.create<User>(SerdeOptions(codec = BZip2Codec())) | ||
serde1.serialize(user).size shouldBeGreaterThan serde2.serialize(user).size | ||
serde2.deserialize(serde2.serialize(user)) shouldBe user | ||
} | ||
|