Skip to content

Commit 2ee7312

Browse files
committed
Add test-cases for 32-bit and no-compressed oops scenarios.
1 parent 5450223 commit 2ee7312

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

core/src/test/scala/spark/BoundedMemoryCacheSuite.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package spark
22

33
import org.scalatest.FunSuite
4+
import org.scalatest.PrivateMethodTester
45

5-
class BoundedMemoryCacheSuite extends FunSuite {
6+
class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester {
67
test("constructor test") {
78
val cache = new BoundedMemoryCache(60)
89
expect(60)(cache.getCapacity)
@@ -12,6 +13,8 @@ class BoundedMemoryCacheSuite extends FunSuite {
1213
// Set the arch to 64-bit and compressedOops to true to get a deterministic test-case
1314
val oldArch = System.setProperty("os.arch", "amd64")
1415
val oldOops = System.setProperty("spark.test.useCompressedOops", "true")
16+
val initialize = PrivateMethod[Unit]('initialize)
17+
SizeEstimator invokePrivate initialize()
1518

1619
val cache = new BoundedMemoryCache(60) {
1720
//TODO sorry about this, but there is not better way how to skip 'cacheTracker.dropEntry'

core/src/test/scala/spark/SizeEstimatorSuite.scala

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package spark
22

33
import org.scalatest.FunSuite
44
import org.scalatest.BeforeAndAfterAll
5+
import org.scalatest.PrivateMethodTester
56

67
class DummyClass1 {}
78

@@ -18,7 +19,7 @@ class DummyClass4(val d: DummyClass3) {
1819
val x: Int = 0
1920
}
2021

21-
class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
22+
class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
2223
var oldArch: String = _
2324
var oldOops: String = _
2425

@@ -29,17 +30,8 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
2930
}
3031

3132
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)
4335
}
4436

4537
test("simple classes") {
@@ -99,5 +91,42 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
9991
assert(estimatedSize >= 4000, "Estimated size " + estimatedSize + " should be more than 4000")
10092
assert(estimatedSize <= 4200, "Estimated size " + estimatedSize + " should be less than 4100")
10193
}
102-
}
10394

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

Comments
 (0)