@@ -2,6 +2,7 @@ package spark
2
2
3
3
import org .scalatest .FunSuite
4
4
import org .scalatest .BeforeAndAfterAll
5
+ import org .scalatest .PrivateMethodTester
5
6
6
7
class DummyClass1 {}
7
8
@@ -18,7 +19,7 @@ class DummyClass4(val d: DummyClass3) {
18
19
val x : Int = 0
19
20
}
20
21
21
- class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
22
+ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
22
23
var oldArch : String = _
23
24
var oldOops : String = _
24
25
@@ -29,17 +30,8 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
29
30
}
30
31
31
32
override def afterAll () {
32
- if (oldArch != null ) {
33
- System .setProperty(" os.arch" , oldArch)
34
- } else {
35
- System .clearProperty(" os.arch" )
36
- }
37
-
38
- if (oldOops != null ) {
39
- System .setProperty(" spark.test.useCompressedOops" , oldOops)
40
- } else {
41
- System .clearProperty(" spark.test.useCompressedOops" )
42
- }
33
+ resetOrClear(" os.arch" , oldArch)
34
+ resetOrClear(" spark.test.useCompressedOops" , oldOops)
43
35
}
44
36
45
37
test(" simple classes" ) {
@@ -99,5 +91,42 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
99
91
assert(estimatedSize >= 4000 , " Estimated size " + estimatedSize + " should be more than 4000" )
100
92
assert(estimatedSize <= 4200 , " Estimated size " + estimatedSize + " should be less than 4100" )
101
93
}
102
- }
103
94
95
+ test(" 32-bit arch" ) {
96
+ val arch = System .setProperty(" os.arch" , " x86" )
97
+
98
+ val initialize = PrivateMethod [Unit ](' initialize )
99
+ SizeEstimator invokePrivate initialize()
100
+
101
+ expect(40 )(SizeEstimator .estimate(" " ))
102
+ expect(48 )(SizeEstimator .estimate(" a" ))
103
+ expect(48 )(SizeEstimator .estimate(" ab" ))
104
+ expect(56 )(SizeEstimator .estimate(" abcdefgh" ))
105
+
106
+ resetOrClear(" os.arch" , arch)
107
+ }
108
+
109
+ test(" 64-bit arch with no compressed oops" ) {
110
+ val arch = System .setProperty(" os.arch" , " amd64" )
111
+ val oops = System .setProperty(" spark.test.useCompressedOops" , " false" )
112
+
113
+ val initialize = PrivateMethod [Unit ](' initialize )
114
+ SizeEstimator invokePrivate initialize()
115
+
116
+ expect(64 )(SizeEstimator .estimate(" " ))
117
+ expect(72 )(SizeEstimator .estimate(" a" ))
118
+ expect(72 )(SizeEstimator .estimate(" ab" ))
119
+ expect(80 )(SizeEstimator .estimate(" abcdefgh" ))
120
+
121
+ resetOrClear(" os.arch" , arch)
122
+ resetOrClear(" spark.test.useCompressedOops" , oops)
123
+ }
124
+
125
+ def resetOrClear (prop : String , oldValue : String ) {
126
+ if (oldValue != null ) {
127
+ System .setProperty(prop, oldValue)
128
+ } else {
129
+ System .clearProperty(prop)
130
+ }
131
+ }
132
+ }
0 commit comments