@@ -5,7 +5,7 @@ import org.apache.flink.api.common.serialization.SerializerConfigImpl
5
5
import org .apache .flink .api .common .typeinfo .TypeInformation
6
6
import org .apache .flink .api .common .typeutils .base .StringSerializer
7
7
import org .apache .flink .api .java .typeutils .runtime .NullableSerializer
8
- import org .apache .flinkx .api .SerializerTest .DeeplyNested .ModeNested .SuperNested .{Egg , Food }
8
+ import org .apache .flinkx .api .SerializerTest .DeeplyNested .ModeNested .SuperNested .{Egg , Food , Ham }
9
9
import org .apache .flinkx .api .SerializerTest .NestedRoot .NestedMiddle .NestedBottom
10
10
import org .apache .flinkx .api .SerializerTest ._
11
11
import org .apache .flinkx .api .serializer .{CaseClassSerializer , nullable }
@@ -21,69 +21,56 @@ class SerializerTest extends AnyFlatSpec with Matchers with Inspectors with Test
21
21
val ec = new SerializerConfigImpl ()
22
22
23
23
it should " derive serializer for simple class" in {
24
- val ser = implicitly[TypeInformation [Simple ]].createSerializer(ec)
25
- all(ser, Simple (1 , " foo" ))
24
+ Simple (1 , " foo" ) should haveTypeInfoAndBeSerializable[Simple ]
26
25
}
27
26
28
27
it should " derive serializer for java classes" in {
29
- val ser = implicitly[TypeInformation [SimpleJava ]].createSerializer(ec)
30
- all(ser, SimpleJava (1 , " foo" ))
28
+ SimpleJava (1 , " foo" ) should beSerializable[SimpleJava ]
31
29
}
32
30
33
31
it should " derive serializer for java.time classes" in {
34
- val ser = implicitly[TypeInformation [JavaTime ]].createSerializer(ec)
35
- all(ser, JavaTime (Instant .now(), LocalDate .now(), LocalDateTime .now()))
32
+ JavaTime (Instant .now(), LocalDate .now(), LocalDateTime .now()) should haveTypeInfoAndBeSerializable[JavaTime ]
36
33
}
37
34
38
35
it should " derive nested classes" in {
39
- val ser = implicitly[TypeInformation [Nested ]].createSerializer(ec)
40
- all(ser, Nested (Simple (1 , " foo" )))
36
+ Nested (Simple (1 , " foo" )) should haveTypeInfoAndBeSerializable[Nested ]
41
37
}
42
38
43
39
it should " derive for ADTs" in {
44
- val ser = implicitly[TypeInformation [ADT ]].createSerializer(ec)
45
- all(ser, Foo (" a" ))
46
- all(ser, Bar (1 ))
40
+ Foo (" a" ) should haveTypeInfoAndBeSerializable[ADT ](nullable = false )
41
+ Bar (1 ) should haveTypeInfoAndBeSerializable[ADT ](nullable = false )
47
42
}
48
43
49
44
it should " derive for ADTs with case objects" in {
50
- val ser = implicitly[TypeInformation [ADT2 ]].createSerializer(ec)
51
- all(ser, Foo2 )
52
- all(ser, Bar2 )
45
+ Foo2 should haveTypeInfoAndBeSerializable[ADT2 ](nullable = false )
46
+ Bar2 should haveTypeInfoAndBeSerializable[ADT2 ](nullable = false )
53
47
}
54
48
55
49
it should " derive for deeply nested classes" in {
56
- val ser = implicitly[TypeInformation [Egg ]].createSerializer(ec)
57
- all(ser, Egg (1 ))
50
+ Egg (1 ) should haveTypeInfoAndBeSerializable[Egg ]
58
51
}
59
52
60
53
it should " derive for deeply nested adts" in {
61
- val ser = implicitly[TypeInformation [Food ]].createSerializer(ec)
62
- all(ser, Egg (1 ))
54
+ Egg (1 ) should haveTypeInfoAndBeSerializable[Food ](nullable = false )
63
55
}
64
56
65
57
it should " derive for nested ADTs" in {
66
- val ser = implicitly[TypeInformation [WrappedADT ]].createSerializer(ec)
67
- all(ser, WrappedADT (Foo (" a" )))
68
- all(ser, WrappedADT (Bar (1 )))
58
+ WrappedADT (Foo (" a" )) should haveTypeInfoAndBeSerializable[WrappedADT ]
59
+ WrappedADT (Bar (1 )) should haveTypeInfoAndBeSerializable[WrappedADT ]
69
60
}
70
61
71
62
it should " derive for generic ADTs" in {
72
- val ser = implicitly[TypeInformation [Param [Int ]]].createSerializer(ec)
73
- all(ser, P2 (1 ))
63
+ P2 (1 ) should haveTypeInfoAndBeSerializable[Param [Int ]](nullable = false )
74
64
}
75
65
76
66
it should " derive seq" in {
77
- val ser = implicitly[TypeInformation [SimpleSeq ]].createSerializer(ec)
78
- noKryo(ser)
79
- serializable(ser)
67
+ SimpleSeq (Seq (Simple (1 , " a" ))) should haveTypeInfoAndBeSerializable[SimpleSeq ]
80
68
}
81
69
82
70
it should " derive list of ADT" in {
83
- val ser = implicitly[TypeInformation [List [ADT ]]].createSerializer(ec)
84
- all(ser, List (Foo (" a" )))
85
- roundtrip(ser, :: (Foo (" a" ), Nil ))
86
- roundtrip(ser, Nil )
71
+ List (Foo (" a" )) should haveTypeInfoAndBeSerializable[List [ADT ]](nullable = false )
72
+ :: (Foo (" a" ), Nil ) should beSerializable[List [ADT ]](nullable = false )
73
+ Nil should beSerializable[List [ADT ]](nullable = false )
87
74
}
88
75
89
76
it should " derive recursively" in {
@@ -92,24 +79,19 @@ class SerializerTest extends AnyFlatSpec with Matchers with Inspectors with Test
92
79
}
93
80
94
81
it should " derive list" in {
95
- val ser = implicitly[TypeInformation [List [Simple ]]].createSerializer(ec)
96
- all(ser, List (Simple (1 , " a" )))
82
+ List (Simple (1 , " a" )) should haveTypeInfoAndBeSerializable[List [Simple ]](nullable = false )
97
83
}
98
84
99
85
it should " derive nested list" in {
100
- val ser = implicitly[TypeInformation [List [SimpleList ]]].createSerializer(ec)
101
- all(ser, List (SimpleList (List (1 ))))
86
+ List (SimpleList (List (1 ))) should haveTypeInfoAndBeSerializable[List [SimpleList ]](nullable = false )
102
87
}
103
88
104
89
it should " derive seq of seq" in {
105
- val ser = implicitly[TypeInformation [SimpleSeqSeq ]].createSerializer(ec)
106
- noKryo(ser)
107
- serializable(ser)
90
+ SimpleSeqSeq (Seq (Seq (Simple (1 , " a" )))) should haveTypeInfoAndBeSerializable[SimpleSeqSeq ]
108
91
}
109
92
110
93
it should " derive generic type bounded classes" in {
111
- val ser = implicitly[TypeInformation [BoundADT [Foo ]]].createSerializer(ec)
112
- noKryo(ser)
94
+ BoundADT (Foo (" a" )) should haveTypeInfoAndBeSerializable[BoundADT [Foo ]]
113
95
}
114
96
115
97
// it should "derive nested generic type bounded classes" in {
@@ -126,114 +108,97 @@ class SerializerTest extends AnyFlatSpec with Matchers with Inspectors with Test
126
108
127
109
it should " be serializable in case of annotations on classes" in {
128
110
val ser = implicitly[TypeInformation [Annotated ]].createSerializer(ec)
129
- serializable (ser)
111
+ javaSerializable (ser)
130
112
}
131
113
132
114
it should " be serializable in case of annotations on subtypes" in {
133
115
val ser = implicitly[TypeInformation [Ann ]].createSerializer(ec)
134
- serializable (ser)
116
+ javaSerializable (ser)
135
117
}
136
118
137
119
it should " serialize Option" in {
138
- val ser = implicitly[TypeInformation [SimpleOption ]].createSerializer(ec)
139
- all(ser, SimpleOption (None ))
140
- roundtrip(ser, SimpleOption (Some (" foo" )))
120
+ SimpleOption (None ) should haveTypeInfoAndBeSerializable[SimpleOption ]
121
+ SimpleOption (Some (" foo" )) should beSerializable[SimpleOption ]
141
122
}
142
123
143
124
it should " serialize Either" in {
144
- val ser = implicitly[TypeInformation [SimpleEither ]].createSerializer(ec)
145
- all(ser, SimpleEither (Left (" foo" )))
146
- roundtrip(ser, SimpleEither (Right (42 )))
125
+ SimpleEither (Left (" foo" )) should haveTypeInfoAndBeSerializable[SimpleEither ]
126
+ SimpleEither (Right (42 )) should beSerializable[SimpleEither ]
147
127
}
148
128
149
129
it should " serialize nested list of ADT" in {
150
- val ser = implicitly[TypeInformation [ListADT ]].createSerializer(ec)
151
- all(ser, ListADT (Nil ))
152
- roundtrip(ser, ListADT (List (Foo (" a" ))))
130
+ ListADT (Nil ) should haveTypeInfoAndBeSerializable[ListADT ]
131
+ ListADT (List (Foo (" a" ))) should beSerializable[ListADT ]
153
132
}
154
133
155
134
it should " derive multiple instances of generic class" in {
156
- val ser = implicitly[TypeInformation [Generic [SimpleOption ]]].createSerializer(ec)
157
- val ser2 = implicitly[TypeInformation [Generic [Simple ]]].createSerializer(ec)
158
- all(ser, Generic (SimpleOption (None ), Bar (0 )))
159
- all(ser2, Generic (Simple (0 , " asd" ), Bar (0 )))
135
+ Generic (SimpleOption (None ), Bar (0 )) should haveTypeInfoAndBeSerializable[Generic [SimpleOption ]]
136
+ Generic (Simple (0 , " asd" ), Bar (0 )) should haveTypeInfoAndBeSerializable[Generic [Simple ]]
160
137
}
161
138
162
139
it should " serialize nil" in {
163
- val ser = implicitly[TypeInformation [NonEmptyList [String ]]].createSerializer(ec)
164
- roundtrip(ser, NonEmptyList .one(" a" ))
140
+ NonEmptyList .one(" a" ) should haveTypeInfoAndBeSerializable[NonEmptyList [String ]]
165
141
}
166
142
167
143
it should " serialize unit" in {
168
- val ser = implicitly[TypeInformation [Unit ]].createSerializer(ec)
169
- roundtrip(ser, ())
144
+ () should haveTypeInfoAndBeSerializable[Unit ](nullable = false )
170
145
}
171
146
172
147
it should " serialize triple-nested case clases" in {
173
- val ser = implicitly[TypeInformation [Seq [NestedBottom ]]].createSerializer(ec)
174
- roundtrip(ser, List (NestedBottom (Some (" a" ), None )))
148
+ List (NestedBottom (Some (" a" ), None )) should haveTypeInfoAndBeSerializable[Seq [NestedBottom ]](nullable = false )
175
149
}
176
150
177
151
it should " serialize classes with type mapper" in {
178
152
import MappedTypeInfoTest ._
179
- val ser = implicitly[TypeInformation [WrappedString ]].createSerializer(ec)
180
153
val str = new WrappedString ()
181
154
str.put(" foo" )
182
- roundtrip(ser, str )
155
+ str should haveTypeInfoAndBeSerializable[ WrappedString ](nullable = false )
183
156
}
184
157
185
158
it should " serialize bigint" in {
186
- val ser = implicitly[TypeInformation [BigInt ]].createSerializer(ec)
187
- roundtrip(ser, BigInt (123 ))
159
+ BigInt (123 ) should haveTypeInfoAndBeSerializable[BigInt ](nullable = false )
188
160
}
189
161
190
162
it should " serialize bigdec" in {
191
- val ser = implicitly[TypeInformation [BigDecimal ]].createSerializer(ec)
192
- roundtrip(ser, BigDecimal (123 ))
163
+ BigDecimal (123 ) should haveTypeInfoAndBeSerializable[BigDecimal ](nullable = false )
193
164
}
194
165
195
166
it should " serialize uuid" in {
196
- val ser = implicitly[TypeInformation [UUID ]].createSerializer(ec)
197
- roundtrip(ser, UUID .randomUUID())
167
+ UUID .randomUUID() should haveTypeInfoAndBeSerializable[UUID ](nullable = false )
198
168
}
199
169
200
170
it should " serialize case class with private field" in {
201
- val ser = implicitly[TypeInformation [PrivateField ]].createSerializer(ec)
202
- roundtrip(ser, PrivateField (" abc" ))
171
+ PrivateField (" abc" ) should haveTypeInfoAndBeSerializable[PrivateField ]
203
172
}
204
173
205
174
it should " serialize a case class overriding a field" in {
206
- val ser = implicitly[TypeInformation [ExtendingCaseClass ]].createSerializer(ec)
207
- roundtrip(ser, ExtendingCaseClass (" abc" , " def" ))
175
+ ExtendingCaseClass (" abc" , " def" ) should haveTypeInfoAndBeSerializable[ExtendingCaseClass ]
208
176
}
209
177
210
178
it should " serialize a null case class" in {
211
- val ser = implicitly[ TypeInformation [ Simple ]].createSerializer(ec)
212
- roundtrip(ser, null )
179
+ val data : Simple = null
180
+ data should haveTypeInfoAndBeSerializable[ Simple ]
213
181
}
214
182
215
183
it should " serialize a case class with nullable field" in {
216
- val ser = implicitly[TypeInformation [NullableField ]].createSerializer(ec)
217
- roundtrip(ser, NullableField (null , Bar (1 )))
184
+ Bar (1 ) should haveTypeInfoAndBeSerializable[Bar ]
218
185
}
219
186
220
187
it should " serialize a case class with a nullable field of a case class with no arity" in {
221
- val ser = implicitly[TypeInformation [NullableFieldWithNoArity ]].createSerializer(ec)
222
- roundtrip(ser, NullableFieldWithNoArity (null ))
188
+ NullableFieldWithNoArity (null ) should haveTypeInfoAndBeSerializable[NullableFieldWithNoArity ]
223
189
}
224
190
225
191
it should " serialize nullable fields" in {
226
192
val ser = implicitly[TypeInformation [SimpleJava ]].createSerializer(ec)
227
- roundtrip(ser, SimpleJava (null , null ))
193
+ SimpleJava (null , null ) should haveTypeInfoAndBeSerializable[ SimpleJava ]
228
194
val ccser = ser.asInstanceOf [CaseClassSerializer [SimpleJava ]]
229
195
// IntSerializer doesn't handle null so it's wrapped in a NullableSerializer
230
196
ccser.getFieldSerializers()(0 ) shouldBe a[NullableSerializer [Integer ]]
231
197
ccser.getFieldSerializers()(1 ) shouldBe a[StringSerializer ] // StringSerializer natively handles null
232
198
}
233
199
234
200
it should " serialize a case class with a nullable field of a fixed size case class" in {
235
- val ser = implicitly[TypeInformation [NullableFixedSizeCaseClass ]].createSerializer(ec)
236
- roundtrip(ser, NullableFixedSizeCaseClass (null ))
201
+ NullableFixedSizeCaseClass (null ) should haveTypeInfoAndBeSerializable[NullableFixedSizeCaseClass ]
237
202
}
238
203
239
204
}
0 commit comments