Skip to content
Snippets Groups Projects
Commit 22ba3a3f authored by Shivaram Venkataraman's avatar Shivaram Venkataraman
Browse files

Add test-cases for 32-bit and no-compressed oops scenarios.

parent 1f68c4b0
No related branches found
No related tags found
No related merge requests found
package spark package spark
import org.scalatest.FunSuite import org.scalatest.FunSuite
import org.scalatest.PrivateMethodTester
class BoundedMemoryCacheSuite extends FunSuite { class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester {
test("constructor test") { test("constructor test") {
val cache = new BoundedMemoryCache(60) val cache = new BoundedMemoryCache(60)
expect(60)(cache.getCapacity) expect(60)(cache.getCapacity)
...@@ -12,6 +13,8 @@ class BoundedMemoryCacheSuite extends FunSuite { ...@@ -12,6 +13,8 @@ class BoundedMemoryCacheSuite extends FunSuite {
// Set the arch to 64-bit and compressedOops to true to get a deterministic test-case // Set the arch to 64-bit and compressedOops to true to get a deterministic test-case
val oldArch = System.setProperty("os.arch", "amd64") val oldArch = System.setProperty("os.arch", "amd64")
val oldOops = System.setProperty("spark.test.useCompressedOops", "true") val oldOops = System.setProperty("spark.test.useCompressedOops", "true")
val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize()
val cache = new BoundedMemoryCache(60) { val cache = new BoundedMemoryCache(60) {
//TODO sorry about this, but there is not better way how to skip 'cacheTracker.dropEntry' //TODO sorry about this, but there is not better way how to skip 'cacheTracker.dropEntry'
......
...@@ -2,6 +2,7 @@ package spark ...@@ -2,6 +2,7 @@ package spark
import org.scalatest.FunSuite import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfterAll import org.scalatest.BeforeAndAfterAll
import org.scalatest.PrivateMethodTester
class DummyClass1 {} class DummyClass1 {}
...@@ -18,7 +19,7 @@ class DummyClass4(val d: DummyClass3) { ...@@ -18,7 +19,7 @@ class DummyClass4(val d: DummyClass3) {
val x: Int = 0 val x: Int = 0
} }
class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll { class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
var oldArch: String = _ var oldArch: String = _
var oldOops: String = _ var oldOops: String = _
...@@ -29,17 +30,8 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll { ...@@ -29,17 +30,8 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
} }
override def afterAll() { override def afterAll() {
if (oldArch != null) { resetOrClear("os.arch", oldArch)
System.setProperty("os.arch", oldArch) resetOrClear("spark.test.useCompressedOops", oldOops)
} else {
System.clearProperty("os.arch")
}
if (oldOops != null) {
System.setProperty("spark.test.useCompressedOops", oldOops)
} else {
System.clearProperty("spark.test.useCompressedOops")
}
} }
test("simple classes") { test("simple classes") {
...@@ -99,5 +91,42 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll { ...@@ -99,5 +91,42 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll {
assert(estimatedSize >= 4000, "Estimated size " + estimatedSize + " should be more than 4000") assert(estimatedSize >= 4000, "Estimated size " + estimatedSize + " should be more than 4000")
assert(estimatedSize <= 4200, "Estimated size " + estimatedSize + " should be less than 4100") 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)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment