@@ -18,14 +18,13 @@ package com.twitter.chill
18
18
19
19
import org .specs ._
20
20
21
- import scala .collection .immutable .BitSet
22
- import scala .collection .immutable .ListMap
23
- import scala .collection .immutable .HashMap
24
-
21
+ import scala .collection .immutable .{SortedSet , BitSet , ListSet , ListMap , HashMap }
25
22
import scala .collection .mutable .{ArrayBuffer => MArrayBuffer , HashMap => MHashMap }
26
23
import _root_ .java .util .PriorityQueue
27
24
import _root_ .java .util .Locale
28
25
import scala .collection .mutable
26
+ import scala .collection .JavaConverters ._
27
+
29
28
/*
30
29
* This is just a test case for Kryo to deal with. It should
31
30
* be outside KryoSpec, otherwise the enclosing class, KryoSpec
@@ -49,6 +48,8 @@ trait ExampleUsingSelf { self =>
49
48
def addOne = new ExampleUsingSelf {override def count = self.count+ 1 }
50
49
}
51
50
51
+ case class Foo (m1 : Map [String , Int ], m2 : Map [String , Seq [String ]])
52
+
52
53
class KryoSpec extends Specification with BaseProperties {
53
54
54
55
noDetailedDiffs() // Fixes issue for scala 2.9
@@ -60,6 +61,7 @@ class KryoSpec extends Specification with BaseProperties {
60
61
val test = List (1 ,2 ," hey" ,(1 ,2 ),
61
62
(" hey" ," you" ),
62
63
(" slightly" , 1L , " longer" , 42 , " tuple" ),
64
+ Foo (Map (" 1" -> 1 ), Map (" 1" -> Seq (" foo.com" ))),
63
65
Map (1 -> 2 ,4 -> 5 ),
64
66
0 to 100 ,
65
67
(0 to 42 ).toList, Seq (1 ,100 ,1000 ),
@@ -70,6 +72,8 @@ class KryoSpec extends Specification with BaseProperties {
70
72
MArrayBuffer (1 ,2 ,3 ,4 ,5 ),
71
73
List (Some (MHashMap (1 -> 1 , 2 -> 2 )), None , Some (MHashMap (3 -> 4 ))),
72
74
Set (1 ,2 ,3 ,4 ,10 ),
75
+ SortedSet [Long ](),
76
+ SortedSet (1L , 2L , 3L , 4L ),
73
77
BitSet (),
74
78
BitSet ((0 until 1000 ).map{ x : Int => x* x } : _* ),
75
79
ListMap (" good" -> 0.5 , " bad" -> - 1.0 ),
@@ -83,6 +87,10 @@ class KryoSpec extends Specification with BaseProperties {
83
87
Vector (1 ,2 ,3 ,4 ,5 ),
84
88
TestValMap (null ),
85
89
Some (" junk" ),
90
+ List (1 , 2 , 3 ).asJava,
91
+ Map (" hey" -> 1 , " you" -> 2 ).asJava,
92
+ new _root_.java.util.ArrayList (Seq (1 , 2 , 3 ).asJava).asScala,
93
+ new _root_.java.util.HashMap [Int ,Int ](Map (1 -> 2 , 3 -> 4 ).asJava).asScala,
86
94
(),
87
95
' hai )
88
96
.asInstanceOf [List [AnyRef ]]
@@ -92,6 +100,22 @@ class KryoSpec extends Specification with BaseProperties {
92
100
serdeser must be_== (orig)
93
101
}
94
102
}
103
+ " round trip a SortedSet" in {
104
+ val a = SortedSet [Long ]() // Test empty SortedSet
105
+ val b = SortedSet [Int ](1 ,2 ) // Test small SortedSet
106
+ val c = SortedSet [Int ](1 ,2 ,3 ,4 ,6 ,7 ,8 ,9 ,10 )(Ordering .fromLessThan((x, y) => x > y)) // Test with different ordering
107
+ rt(a) must be_== (a)
108
+ rt(b) must be_== (b)
109
+ (rt(c) + 5 ) must be_== (c + 5 )
110
+ }
111
+ " round trip a ListSet" in {
112
+ val a = ListSet [Long ]() // Test empty SortedSet
113
+ val b = ListSet [Int ](1 ,2 ) // Test small ListSet
114
+ val c = ListSet [Int ](1 ,2 ,3 ,4 ,6 ,7 ,8 ,9 ,10 )
115
+ rt(a) must be_== (a)
116
+ rt(b) must be_== (b)
117
+ (rt(c)) must be_== (c)
118
+ }
95
119
" handle trait with reference of self" in {
96
120
var a = new ExampleUsingSelf {}
97
121
var b = rt(a.addOne)
@@ -270,5 +294,20 @@ class KryoSpec extends Specification with BaseProperties {
270
294
val qrlist = toList(qr)
271
295
toList(rt(qr)) must be_== (qrlist)
272
296
}
297
+ " Ranges should be fixed size" in {
298
+ val MAX_RANGE_SIZE = 188 // what seems to be needed.
299
+ serialize((1 to 10000 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
300
+ serialize((1 to 10000 by 2 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
301
+ serialize((1 until 10000 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
302
+ serialize((1 until 10000 by 2 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
303
+ serialize((1L to 10000L )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
304
+ serialize((1L to 10000L by 2L )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
305
+ serialize((1L until 10000L )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
306
+ serialize((1L until 10000L by 2L )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
307
+ serialize((1.0 to 10000.0 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
308
+ serialize((1.0 to 10000.0 by 2.0 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
309
+ serialize((1.0 until 10000.0 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
310
+ serialize((1.0 until 10000.0 by 2.0 )).size must be_<(MAX_RANGE_SIZE ) // some fixed size
311
+ }
273
312
}
274
313
}
0 commit comments