-
Notifications
You must be signed in to change notification settings - Fork 4
/
SerializationSizeTest.scala
66 lines (52 loc) · 1.59 KB
/
SerializationSizeTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.hammerlab.spark.test.serde
import org.hammerlab.test.version.Util
import org.hammerlab.test.serde.JavaSerialization._
import org.hammerlab.spark.test.serde.util.{Foo, FooRegistrarTest, HasKryoSuite}
class SerializationSizeTest
extends FooRegistrarTest
with HasKryoSuite {
val l = List("a" * 8, "b" * 8, "c" * 8)
def checkJavaRoundTrip(o: Object, size: Int): Unit = {
val bytes = javaBytes(o)
bytes.length should be(size)
javaRead[List[String]](bytes) should be(o)
}
test("java list") {
checkJavaRoundTrip(
l,
// This List[String] gets compressed differently in Scala 2.10 vs. 2.11!
if (Util.is2_10)
263
else
166
)
}
test("kryo list") {
checkKryoRoundTrip(l, 32)
}
test("java foo") {
checkJavaRoundTrip(Foo(187, "d" * 8), 104)
}
test("kryo foo") {
checkKryoRoundTrip(Foo(187, "d" * 8), 12)
}
test("kryo foo class") {
checkKryoRoundTrip(Foo(127, "d" * 8), 13, includeClass = true)
checkKryoRoundTrip(Foo(128, "d" * 8), 13, includeClass = true)
checkKryoRoundTrip(Foo(129, "d" * 16), 21, includeClass = true)
checkKryoRoundTrip(Foo(130, "d" * 16), 21, includeClass = true)
checkKryoRoundTrip(Foo(187, "d" * 8), 13, includeClass = true)
}
test("kryo 1 string") {
checkKryoRoundTrip("a" * 8, 9)
}
test("kryo class and 1 string") {
checkKryoRoundTrip("a" * 8, 10, includeClass = true)
}
test("kryo strings") {
checkKryoRoundTrip(18, "a" * 8, "b" * 8)
}
test("kryo class and strings") {
checkKryoRoundTrip(20, includeClass = true, "a" * 8, "b" * 8)
}
}