@@ -3,6 +3,7 @@ package spark
3
3
import org .scalatest .FunSuite
4
4
import org .scalatest .BeforeAndAfterAll
5
5
import org .scalatest .PrivateMethodTester
6
+ import org .scalatest .matchers .ShouldMatchers
6
7
7
8
class DummyClass1 {}
8
9
@@ -19,7 +20,8 @@ class DummyClass4(val d: DummyClass3) {
19
20
val x : Int = 0
20
21
}
21
22
22
- class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
23
+ class SizeEstimatorSuite extends FunSuite
24
+ with BeforeAndAfterAll with PrivateMethodTester with ShouldMatchers {
23
25
var oldArch : String = _
24
26
var oldOops : String = _
25
27
@@ -42,11 +44,15 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMet
42
44
expect(48 )(SizeEstimator .estimate(new DummyClass4 (new DummyClass3 )))
43
45
}
44
46
47
+ // NOTE: The String class definition changed in JDK 7 to exclude the int fields count and length.
48
+ // This means that the size of strings will be lesser by 8 bytes in JDK 7 compared to JDK 6.
49
+ // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
50
+ // Work around to check for either.
45
51
test(" strings" ) {
46
- expect( 48 )( SizeEstimator .estimate(" " ))
47
- expect( 56 )( SizeEstimator .estimate(" a" ))
48
- expect( 56 )( SizeEstimator .estimate(" ab" ))
49
- expect( 64 )( SizeEstimator .estimate(" abcdefgh" ))
52
+ SizeEstimator .estimate(" " ) should (equal ( 48 ) or equal ( 40 ))
53
+ SizeEstimator .estimate(" a" ) should (equal ( 56 ) or equal ( 48 ))
54
+ SizeEstimator .estimate(" ab" ) should (equal ( 56 ) or equal ( 48 ))
55
+ SizeEstimator .estimate(" abcdefgh" ) should (equal( 64 ) or equal( 56 ))
50
56
}
51
57
52
58
test(" primitive arrays" ) {
@@ -106,17 +112,21 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMet
106
112
resetOrClear(" os.arch" , arch)
107
113
}
108
114
115
+ // NOTE: The String class definition changed in JDK 7 to exclude the int fields count and length.
116
+ // This means that the size of strings will be lesser by 8 bytes in JDK 7 compared to JDK 6.
117
+ // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
118
+ // Work around to check for either.
109
119
test(" 64-bit arch with no compressed oops" ) {
110
120
val arch = System .setProperty(" os.arch" , " amd64" )
111
121
val oops = System .setProperty(" spark.test.useCompressedOops" , " false" )
112
122
113
123
val initialize = PrivateMethod [Unit ](' initialize )
114
124
SizeEstimator invokePrivate initialize()
115
125
116
- expect( 64 )( SizeEstimator .estimate(" " ))
117
- expect( 72 )( SizeEstimator .estimate(" a" ))
118
- expect( 72 )( SizeEstimator .estimate(" ab" ))
119
- expect( 80 )( SizeEstimator .estimate(" abcdefgh" ))
126
+ SizeEstimator .estimate(" " ) should (equal ( 64 ) or equal ( 56 ))
127
+ SizeEstimator .estimate(" a" ) should (equal ( 72 ) or equal ( 64 ))
128
+ SizeEstimator .estimate(" ab" ) should (equal ( 72 ) or equal ( 64 ))
129
+ SizeEstimator .estimate(" abcdefgh" ) should (equal ( 80 ) or equal ( 72 ))
120
130
121
131
resetOrClear(" os.arch" , arch)
122
132
resetOrClear(" spark.test.useCompressedOops" , oops)
0 commit comments