Skip to content

Commit c90874b

Browse files
authored
add schema registry implementation for tests (#28)
1 parent 252c8f3 commit c90874b

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.davideicardi.kaa.test
2+
3+
import org.apache.avro.Schema
4+
import org.apache.avro.SchemaNormalization
5+
import com.davideicardi.kaa.SchemaId
6+
import com.davideicardi.kaa.SchemaRegistry
7+
8+
class TestSchemaRegistry() extends SchemaRegistry {
9+
val schemas = collection.mutable.Map[SchemaId, Schema]()
10+
11+
override def put(schema: Schema): SchemaId = {
12+
val fingerprint = SchemaNormalization.parsingFingerprint64(schema)
13+
val key = SchemaId(fingerprint)
14+
15+
schemas.put(key, schema)
16+
17+
key
18+
}
19+
20+
override def get(id: SchemaId): Option[Schema] = {
21+
schemas.get(id)
22+
}
23+
}

kaa/src/test/scala/kaa/darwin/AvroSingleObjectSerializerSpec.scala

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import org.apache.avro.{Schema, SchemaNormalization}
55
import org.scalatest._
66
import flatspec._
77
import com.davideicardi.kaa.avro.{AvroBinarySerializer, AvroSingleObjectEncoding, AvroSingleObjectSerializer}
8-
import com.davideicardi.kaa.{SchemaId, SchemaRegistry}
8+
import com.davideicardi.kaa.SchemaId
9+
import com.davideicardi.kaa.test.TestSchemaRegistry
910
import matchers._
1011

11-
import scala.collection.mutable
12-
1312
case class Pokemon(name: String, mainType: String, offType: Option[String], level: Int)
1413

1514
class AvroSingleObjectSerializerSpec extends AnyFlatSpec with should.Matchers {
1615

17-
val registry = new SchemaRegistryFake
16+
val registry = new TestSchemaRegistry
1817
val dragonite = Pokemon("Dragonite", "Dragon", None, 100)
1918

2019
val singleObjectSerializer = new AvroSingleObjectSerializer[Pokemon](registry)
@@ -42,20 +41,3 @@ class AvroSingleObjectSerializerSpec extends AnyFlatSpec with should.Matchers {
4241
}
4342
}
4443
}
45-
46-
class SchemaRegistryFake extends SchemaRegistry {
47-
val _schemas = new mutable.HashMap[SchemaId, Schema]
48-
49-
override def put(schema: Schema): SchemaId = {
50-
val id = SchemaId(
51-
SchemaNormalization.parsingFingerprint64(schema)
52-
)
53-
_schemas.put(id, schema)
54-
55-
id
56-
}
57-
58-
override def get(id: SchemaId): Option[Schema] = {
59-
_schemas.get(id)
60-
}
61-
}

0 commit comments

Comments
 (0)