@@ -3,45 +3,70 @@ package com.caplin.integration.datasourcex.util.serialization.fory
33import com.caplin.integration.datasourcex.util.flow.ValueOrCompletion
44import io.kotest.core.spec.style.FunSpec
55import io.kotest.matchers.shouldBe
6+ import io.kotest.matchers.types.shouldBeInstanceOf
67import org.apache.fory.Fory
78import org.apache.fory.config.Language
89
10+ class CustomException (val customMessage : String ) : Exception(customMessage)
11+
912class ValueOrCompletionSerializationTest :
10- FunSpec ({
11- val fory =
12- Fory .builder()
13- .withLanguage(Language .JAVA )
14- .requireClassRegistration(false )
15- .build()
16- .registerDataSourceSerializers()
17-
18- test(" Value" ) {
19- val event = ValueOrCompletion .Value (" value" )
20- val bytes = fory.serialize(event)
21- val deserialized = fory.deserialize(bytes)
22- deserialized shouldBe event
23- }
24-
25- test(" Completion" ) {
26- val event = ValueOrCompletion .Completion (null )
27- val bytes = fory.serialize(event)
28- val deserialized = fory.deserialize(bytes)
29- deserialized shouldBe event
30- }
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- }
47- })
13+ FunSpec (
14+ {
15+ val fory =
16+ Fory .builder()
17+ .withLanguage(Language .JAVA )
18+ .requireClassRegistration(false )
19+ .withRefTracking(true )
20+ .build()
21+ .registerDataSourceSerializers(preserveExceptionTypes = true )
22+
23+ val foryNoType =
24+ Fory .builder()
25+ .withLanguage(Language .JAVA )
26+ .requireClassRegistration(false )
27+ .withRefTracking(false )
28+ .build()
29+ .registerDataSourceSerializers()
30+
31+ test(" Value" ) {
32+ val event = ValueOrCompletion .Value (" value" )
33+ val bytes = fory.serialize(event)
34+ val deserialized = fory.deserialize(bytes)
35+ deserialized shouldBe event
36+ }
37+
38+ test(" Completion" ) {
39+ val event = ValueOrCompletion .Completion (null )
40+ val bytes = fory.serialize(event)
41+ val deserialized = fory.deserialize(bytes)
42+ deserialized shouldBe event
43+ }
44+
45+ context(" Value and Completion specifically" ) {
46+ test(" Value" ) {
47+ val event: ValueOrCompletion .Value <String > = ValueOrCompletion .Value (" value" )
48+ val bytes = fory.serialize(event)
49+ val deserialized = fory.deserialize(bytes)
50+ deserialized shouldBe event
51+ }
52+
53+ test(" Completion with custom exception (preserved type)" ) {
54+ val event: ValueOrCompletion .Completion =
55+ ValueOrCompletion .Completion (CustomException (" aah" ))
56+ val bytes = fory.serialize(event)
57+ val deserialized = fory.deserialize(bytes) as ValueOrCompletion .Completion
58+ val throwable = deserialized.throwable.shouldBeInstanceOf<CustomException >()
59+ throwable.customMessage shouldBe " aah"
60+ }
61+
62+ test(" Completion with exception (no type)" ) {
63+ val event: ValueOrCompletion .Completion =
64+ ValueOrCompletion .Completion (IllegalStateException (" aah" ))
65+ val bytes = foryNoType.serialize(event)
66+ val deserialized = foryNoType.deserialize(bytes) as ValueOrCompletion .Completion
67+ deserialized.throwable.shouldBeInstanceOf<RuntimeException >()
68+ deserialized.throwable.message shouldBe " aah"
69+ }
70+ }
71+ },
72+ )
0 commit comments