aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShivaram Venkataraman <shivaram@eecs.berkeley.edu>2012-08-12 17:18:01 -0700
committerShivaram Venkataraman <shivaram@eecs.berkeley.edu>2012-08-13 13:32:10 -0700
commit22ba3a3f7795ad7bdf2083b05643c1655f627ca5 (patch)
tree08fa24b31a5a1bf511829963f969643fbad83bec
parent1f68c4b03b7113e5083d47d7d200543858e6f98a (diff)
downloadspark-22ba3a3f7795ad7bdf2083b05643c1655f627ca5.tar.gz
spark-22ba3a3f7795ad7bdf2083b05643c1655f627ca5.tar.bz2
spark-22ba3a3f7795ad7bdf2083b05643c1655f627ca5.zip
Add test-cases for 32-bit and no-compressed oops scenarios.
-rw-r--r--core/src/test/scala/spark/BoundedMemoryCacheSuite.scala5
-rw-r--r--core/src/test/scala/spark/SizeEstimatorSuite.scala55
2 files changed, 46 insertions, 14 deletions
diff --git a/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala b/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
index 745c86a0d0..dff2970566 100644
--- a/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
+++ b/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
@@ -1,8 +1,9 @@
package spark
import org.scalatest.FunSuite
+import org.scalatest.PrivateMethodTester
-class BoundedMemoryCacheSuite extends FunSuite {
+class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester {
test("constructor test") {
val cache = new BoundedMemoryCache(60)
expect(60)(cache.getCapacity)
@@ -12,6 +13,8 @@ class BoundedMemoryCacheSuite extends FunSuite {
// Set the arch to 64-bit and compressedOops to true to get a deterministic test-case
val oldArch = System.setProperty("os.arch", "amd64")
val oldOops = System.setProperty("spark.test.useCompressedOops", "true")
+ val initialize = PrivateMethod[Unit]('initialize)
+ SizeEstimator invokePrivate initialize()
val cache = new BoundedMemoryCache(60) {
//TODO sorry about this, but there is not better way how to skip 'cacheTracker.dropEntry'
diff --git a/core/src/test/scala/spark/SizeEstimatorSuite.scala b/core/src/test/scala/spark/SizeEstimatorSuite.scala
index 9c45b3c287..a2015644ee 100644
--- a/core/src/test/scala/spark/SizeEstimatorSuite.scala
+++ b/core/src/test/scala/spark/SizeEstimatorSuite.scala
@@ -2,6 +2,7 @@ package spark
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfterAll
+import org.scalatest.PrivateMethodTester
class DummyClass1 {}
@@ -18,7 +19,7 @@ class DummyClass4(val d: DummyClass3) {
val x: Int = 0
}
-class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
+class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
var oldArch: String = _
var oldOops: String = _
@@ -29,17 +30,8 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
}
override def afterAll() {
- if (oldArch != null) {
- System.setProperty("os.arch", oldArch)
- } else {
- System.clearProperty("os.arch")
- }
-
- if (oldOops != null) {
- System.setProperty("spark.test.useCompressedOops", oldOops)
- } else {
- System.clearProperty("spark.test.useCompressedOops")
- }
+ resetOrClear("os.arch", oldArch)
+ resetOrClear("spark.test.useCompressedOops", oldOops)
}
test("simple classes") {
@@ -99,5 +91,42 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
assert(estimatedSize >= 4000, "Estimated size " + estimatedSize + " should be more than 4000")
assert(estimatedSize <= 4200, "Estimated size " + estimatedSize + " should be less than 4100")
}
-}
+ test("32-bit arch") {
+ val arch = System.setProperty("os.arch", "x86")
+
+ val initialize = PrivateMethod[Unit]('initialize)
+ SizeEstimator invokePrivate initialize()
+
+ expect(40)(SizeEstimator.estimate(""))
+ expect(48)(SizeEstimator.estimate("a"))
+ expect(48)(SizeEstimator.estimate("ab"))
+ expect(56)(SizeEstimator.estimate("abcdefgh"))
+
+ resetOrClear("os.arch", arch)
+ }
+
+ test("64-bit arch with no compressed oops") {
+ val arch = System.setProperty("os.arch", "amd64")
+ val oops = System.setProperty("spark.test.useCompressedOops", "false")
+
+ val initialize = PrivateMethod[Unit]('initialize)
+ SizeEstimator invokePrivate initialize()
+
+ expect(64)(SizeEstimator.estimate(""))
+ expect(72)(SizeEstimator.estimate("a"))
+ expect(72)(SizeEstimator.estimate("ab"))
+ expect(80)(SizeEstimator.estimate("abcdefgh"))
+
+ resetOrClear("os.arch", arch)
+ resetOrClear("spark.test.useCompressedOops", oops)
+ }
+
+ def resetOrClear(prop: String, oldValue: String) {
+ if (oldValue != null) {
+ System.setProperty(prop, oldValue)
+ } else {
+ System.clearProperty(prop)
+ }
+ }
+}