Skip to content

Commit b84223c

Browse files
committed
More serialization tests
1 parent 63ee6d7 commit b84223c

9 files changed

Lines changed: 175 additions & 19 deletions

File tree

util/src/main/kotlin/com/caplin/integration/datasourcex/util/serialization/jackson/DataSourceModule.kt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.caplin.integration.datasourcex.util.flow.MapEvent
55
import com.caplin.integration.datasourcex.util.flow.SetEvent
66
import com.caplin.integration.datasourcex.util.flow.SimpleMapEvent
77
import com.caplin.integration.datasourcex.util.flow.ValueOrCompletion
8+
import com.fasterxml.jackson.databind.JsonDeserializer
9+
import com.fasterxml.jackson.databind.JsonSerializer
810
import com.fasterxml.jackson.databind.Module
911
import com.fasterxml.jackson.databind.ObjectMapper
1012
import com.fasterxml.jackson.databind.module.SimpleModule
@@ -31,14 +33,12 @@ object DataSourceModule : SimpleModule() {
3133
@Suppress("UNCHECKED_CAST")
3234
addSerializer(
3335
MapEvent.EntryEvent::class.java,
34-
mapEventSerializer
35-
as com.fasterxml.jackson.databind.JsonSerializer<MapEvent.EntryEvent<*, *>>,
36+
mapEventSerializer as JsonSerializer<MapEvent.EntryEvent<*, *>>,
3637
)
3738
@Suppress("UNCHECKED_CAST")
3839
addDeserializer(
3940
MapEvent.EntryEvent::class.java,
40-
mapEventDeserializer
41-
as com.fasterxml.jackson.databind.JsonDeserializer<MapEvent.EntryEvent<*, *>>,
41+
mapEventDeserializer as JsonDeserializer<MapEvent.EntryEvent<*, *>>,
4242
)
4343

4444
val simpleMapEventSerializer = SimpleMapEventSerializer()
@@ -50,14 +50,12 @@ object DataSourceModule : SimpleModule() {
5050
@Suppress("UNCHECKED_CAST")
5151
addSerializer(
5252
SimpleMapEvent.EntryEvent::class.java,
53-
simpleMapEventSerializer
54-
as com.fasterxml.jackson.databind.JsonSerializer<SimpleMapEvent.EntryEvent<*, *>>,
53+
simpleMapEventSerializer as JsonSerializer<SimpleMapEvent.EntryEvent<*, *>>,
5554
)
5655
@Suppress("UNCHECKED_CAST")
5756
addDeserializer(
5857
SimpleMapEvent.EntryEvent::class.java,
59-
simpleMapEventDeserializer
60-
as com.fasterxml.jackson.databind.JsonDeserializer<SimpleMapEvent.EntryEvent<*, *>>,
58+
simpleMapEventDeserializer as JsonDeserializer<SimpleMapEvent.EntryEvent<*, *>>,
6159
)
6260

6361
val setEventSerializer = SetEventSerializer()
@@ -69,13 +67,12 @@ object DataSourceModule : SimpleModule() {
6967
@Suppress("UNCHECKED_CAST")
7068
addSerializer(
7169
SetEvent.EntryEvent::class.java,
72-
setEventSerializer as com.fasterxml.jackson.databind.JsonSerializer<SetEvent.EntryEvent<*>>,
70+
setEventSerializer as JsonSerializer<SetEvent.EntryEvent<*>>,
7371
)
7472
@Suppress("UNCHECKED_CAST")
7573
addDeserializer(
7674
SetEvent.EntryEvent::class.java,
77-
setEventDeserializer
78-
as com.fasterxml.jackson.databind.JsonDeserializer<SetEvent.EntryEvent<*>>,
75+
setEventDeserializer as JsonDeserializer<SetEvent.EntryEvent<*>>,
7976
)
8077

8178
val valueOrCompletionSerializer = ValueOrCompletionSerializer()
@@ -87,27 +84,23 @@ object DataSourceModule : SimpleModule() {
8784
@Suppress("UNCHECKED_CAST")
8885
addSerializer(
8986
ValueOrCompletion.Value::class.java,
90-
valueOrCompletionSerializer
91-
as com.fasterxml.jackson.databind.JsonSerializer<ValueOrCompletion.Value<*>>,
87+
valueOrCompletionSerializer as JsonSerializer<ValueOrCompletion.Value<*>>,
9288
)
9389
@Suppress("UNCHECKED_CAST")
9490
addDeserializer(
9591
ValueOrCompletion.Value::class.java,
96-
valueOrCompletionDeserializer
97-
as com.fasterxml.jackson.databind.JsonDeserializer<ValueOrCompletion.Value<*>>,
92+
valueOrCompletionDeserializer as JsonDeserializer<ValueOrCompletion.Value<*>>,
9893
)
9994

10095
@Suppress("UNCHECKED_CAST")
10196
addSerializer(
10297
ValueOrCompletion.Completion::class.java,
103-
valueOrCompletionSerializer
104-
as com.fasterxml.jackson.databind.JsonSerializer<ValueOrCompletion.Completion>,
98+
valueOrCompletionSerializer as JsonSerializer<ValueOrCompletion.Completion>,
10599
)
106100
@Suppress("UNCHECKED_CAST")
107101
addDeserializer(
108102
ValueOrCompletion.Completion::class.java,
109-
valueOrCompletionDeserializer
110-
as com.fasterxml.jackson.databind.JsonDeserializer<ValueOrCompletion.Completion>,
103+
valueOrCompletionDeserializer as JsonDeserializer<ValueOrCompletion.Completion>,
111104
)
112105
}
113106
}

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/fory/MapEventSerializationTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,20 @@ class MapEventSerializationTest :
3737
val deserialized = fory.deserialize(bytes)
3838
deserialized shouldBe event
3939
}
40+
41+
context("EntryEvent specifically") {
42+
test("Upsert") {
43+
val event: MapEvent.EntryEvent<String, String> = Upsert("key", "old", "new")
44+
val bytes = fory.serialize(event)
45+
val deserialized = fory.deserialize(bytes)
46+
deserialized shouldBe event
47+
}
48+
49+
test("Removed") {
50+
val event: MapEvent.EntryEvent<String, String> = Removed("key", "old")
51+
val bytes = fory.serialize(event)
52+
val deserialized = fory.deserialize(bytes)
53+
deserialized shouldBe event
54+
}
55+
}
4056
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/fory/SetEventSerializationTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ class SetEventSerializationTest :
3535
val deserialized = fory.deserialize(bytes)
3636
deserialized shouldBe event
3737
}
38+
39+
context("EntryEvent specifically") {
40+
test("Insert") {
41+
val event: SetEvent.EntryEvent<String> = SetEvent.EntryEvent.Insert("value")
42+
val bytes = fory.serialize(event)
43+
val deserialized = fory.deserialize(bytes)
44+
deserialized shouldBe event
45+
}
46+
47+
test("Removed") {
48+
val event: SetEvent.EntryEvent<String> = SetEvent.EntryEvent.Removed("value")
49+
val bytes = fory.serialize(event)
50+
val deserialized = fory.deserialize(bytes)
51+
deserialized shouldBe event
52+
}
53+
}
3854
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/fory/SimpleMapEventSerializationTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ class SimpleMapEventSerializationTest :
3535
val deserialized = fory.deserialize(bytes)
3636
deserialized shouldBe event
3737
}
38+
39+
context("EntryEvent specifically") {
40+
test("Upsert") {
41+
val event: SimpleMapEvent.EntryEvent<String, String> =
42+
SimpleMapEvent.EntryEvent.Upsert("key", "value")
43+
val bytes = fory.serialize(event)
44+
val deserialized = fory.deserialize(bytes)
45+
deserialized shouldBe event
46+
}
47+
48+
test("Removed") {
49+
val event: SimpleMapEvent.EntryEvent<String, String> =
50+
SimpleMapEvent.EntryEvent.Removed("key")
51+
val bytes = fory.serialize(event)
52+
val deserialized = fory.deserialize(bytes)
53+
deserialized shouldBe event
54+
}
55+
}
3856
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/fory/ValueOrCompletionSerializationTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,20 @@ class ValueOrCompletionSerializationTest :
2828
val deserialized = fory.deserialize(bytes)
2929
deserialized shouldBe event
3030
}
31+
32+
context("Value and Completion specifically") {
33+
test("Value") {
34+
val event: ValueOrCompletion.Value<String> = ValueOrCompletion.Value("value")
35+
val bytes = fory.serialize(event)
36+
val deserialized = fory.deserialize(bytes)
37+
deserialized shouldBe event
38+
}
39+
40+
test("Completion") {
41+
val event: ValueOrCompletion.Completion = ValueOrCompletion.Completion(null)
42+
val bytes = fory.serialize(event)
43+
val deserialized = fory.deserialize(bytes)
44+
deserialized shouldBe event
45+
}
46+
}
3147
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/jackson/MapEventSerializationTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,28 @@ class MapEventSerializationTest :
3636
mapper.readValue(json, object : TypeReference<MapEvent<String, String>>() {})
3737
deserialized shouldBe event
3838
}
39+
40+
context("EntryEvent specifically") {
41+
test("Upsert") {
42+
val event: MapEvent.EntryEvent<String, String> = Upsert("key", "old", "new")
43+
val json = mapper.writeValueAsString(event)
44+
val deserialized: MapEvent.EntryEvent<String, String> =
45+
mapper.readValue(
46+
json,
47+
object : TypeReference<MapEvent.EntryEvent<String, String>>() {},
48+
)
49+
deserialized shouldBe event
50+
}
51+
52+
test("Removed") {
53+
val event: MapEvent.EntryEvent<String, String> = Removed("key", "old")
54+
val json = mapper.writeValueAsString(event)
55+
val deserialized: MapEvent.EntryEvent<String, String> =
56+
mapper.readValue(
57+
json,
58+
object : TypeReference<MapEvent.EntryEvent<String, String>>() {},
59+
)
60+
deserialized shouldBe event
61+
}
62+
}
3963
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/jackson/SetEventSerializationTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,22 @@ class SetEventSerializationTest :
3131
val deserialized = mapper.readValue(json, object : TypeReference<SetEvent<String>>() {})
3232
deserialized shouldBe event
3333
}
34+
35+
context("EntryEvent specifically") {
36+
test("Insert") {
37+
val event: SetEvent.EntryEvent<String> = SetEvent.EntryEvent.Insert("value")
38+
val json = mapper.writeValueAsString(event)
39+
val deserialized =
40+
mapper.readValue(json, object : TypeReference<SetEvent.EntryEvent<String>>() {})
41+
deserialized shouldBe event
42+
}
43+
44+
test("Removed") {
45+
val event: SetEvent.EntryEvent<String> = SetEvent.EntryEvent.Removed("value")
46+
val json = mapper.writeValueAsString(event)
47+
val deserialized =
48+
mapper.readValue(json, object : TypeReference<SetEvent.EntryEvent<String>>() {})
49+
deserialized shouldBe event
50+
}
51+
}
3452
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/jackson/SimpleMapEventSerializationTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,30 @@ class SimpleMapEventSerializationTest :
3434
mapper.readValue(json, object : TypeReference<SimpleMapEvent<String, String>>() {})
3535
deserialized shouldBe event
3636
}
37+
38+
context("EntryEvent specifically") {
39+
test("Upsert") {
40+
val event: SimpleMapEvent.EntryEvent<String, String> =
41+
SimpleMapEvent.EntryEvent.Upsert("key", "value")
42+
val json = mapper.writeValueAsString(event)
43+
val deserialized =
44+
mapper.readValue(
45+
json,
46+
object : TypeReference<SimpleMapEvent.EntryEvent<String, String>>() {},
47+
)
48+
deserialized shouldBe event
49+
}
50+
51+
test("Removed") {
52+
val event: SimpleMapEvent.EntryEvent<String, String> =
53+
SimpleMapEvent.EntryEvent.Removed("key")
54+
val json = mapper.writeValueAsString(event)
55+
val deserialized =
56+
mapper.readValue(
57+
json,
58+
object : TypeReference<SimpleMapEvent.EntryEvent<String, String>>() {},
59+
)
60+
deserialized shouldBe event
61+
}
62+
}
3763
})

util/src/test/kotlin/com/caplin/integration/datasourcex/util/serialization/jackson/ValueOrCompletionSerializationTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,33 @@ class ValueOrCompletionSerializationTest :
3838
deserialized.shouldBeInstanceOf<ValueOrCompletion.Completion>()
3939
deserialized.throwable?.message shouldBe "error"
4040
}
41+
42+
context("Value and Completion specifically") {
43+
test("Value") {
44+
val event: ValueOrCompletion.Value<String> = ValueOrCompletion.Value("value")
45+
val json = mapper.writeValueAsString(event)
46+
val deserialized =
47+
mapper.readValue(json, object : TypeReference<ValueOrCompletion.Value<String>>() {})
48+
deserialized shouldBe event
49+
}
50+
51+
test("Completion (null)") {
52+
val event: ValueOrCompletion.Completion = ValueOrCompletion.Completion(null)
53+
val json = mapper.writeValueAsString(event)
54+
val deserialized =
55+
mapper.readValue(json, object : TypeReference<ValueOrCompletion.Completion>() {})
56+
deserialized.shouldBeInstanceOf<ValueOrCompletion.Completion>()
57+
deserialized.throwable shouldBe null
58+
}
59+
60+
test("Completion (error)") {
61+
val event: ValueOrCompletion.Completion =
62+
ValueOrCompletion.Completion(RuntimeException("error"))
63+
val json = mapper.writeValueAsString(event)
64+
val deserialized =
65+
mapper.readValue(json, object : TypeReference<ValueOrCompletion.Completion>() {})
66+
deserialized.shouldBeInstanceOf<ValueOrCompletion.Completion>()
67+
deserialized.throwable?.message shouldBe "error"
68+
}
69+
}
4170
})

0 commit comments

Comments
 (0)