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

Use a dummy string class in Size Estimator tests to make it resistant to jdk

versions
parent 77d75173
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,15 @@ class DummyClass4(val d: DummyClass3) { ...@@ -20,6 +20,15 @@ class DummyClass4(val d: DummyClass3) {
val x: Int = 0 val x: Int = 0
} }
object DummyString {
def apply(str: String) : DummyString = new DummyString(str.toArray)
}
class DummyString(val arr: Array[Char]) {
override val hashCode: Int = 0
// JDK-7 has an extra hash32 field http://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/rev/11987e85555f
@transient val hash32: Int = 0
}
class SizeEstimatorSuite class SizeEstimatorSuite
extends FunSuite with BeforeAndAfterAll with PrivateMethodTester with ShouldMatchers { extends FunSuite with BeforeAndAfterAll with PrivateMethodTester with ShouldMatchers {
...@@ -50,10 +59,10 @@ class SizeEstimatorSuite ...@@ -50,10 +59,10 @@ class SizeEstimatorSuite
// http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
// Work around to check for either. // Work around to check for either.
test("strings") { test("strings") {
SizeEstimator.estimate("") should (equal (48) or equal (40)) SizeEstimator.estimate(DummyString("")) should (equal (48) or equal (40))
SizeEstimator.estimate("a") should (equal (56) or equal (48)) SizeEstimator.estimate(DummyString("a")) should (equal (56) or equal (48))
SizeEstimator.estimate("ab") should (equal (56) or equal (48)) SizeEstimator.estimate(DummyString("ab")) should (equal (56) or equal (48))
SizeEstimator.estimate("abcdefgh") should (equal(64) or equal(56)) SizeEstimator.estimate(DummyString("abcdefgh")) should (equal(64) or equal(56))
} }
test("primitive arrays") { test("primitive arrays") {
...@@ -105,10 +114,10 @@ class SizeEstimatorSuite ...@@ -105,10 +114,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize) val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize() SizeEstimator invokePrivate initialize()
expect(40)(SizeEstimator.estimate("")) expect(40)(SizeEstimator.estimate(DummyString("")))
expect(48)(SizeEstimator.estimate("a")) expect(48)(SizeEstimator.estimate(DummyString("a")))
expect(48)(SizeEstimator.estimate("ab")) expect(48)(SizeEstimator.estimate(DummyString("ab")))
expect(56)(SizeEstimator.estimate("abcdefgh")) expect(56)(SizeEstimator.estimate(DummyString("abcdefgh")))
resetOrClear("os.arch", arch) resetOrClear("os.arch", arch)
} }
...@@ -124,10 +133,10 @@ class SizeEstimatorSuite ...@@ -124,10 +133,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize) val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize() SizeEstimator invokePrivate initialize()
SizeEstimator.estimate("") should (equal (64) or equal (56)) SizeEstimator.estimate(DummyString("")) should (equal (64) or equal (56))
SizeEstimator.estimate("a") should (equal (72) or equal (64)) SizeEstimator.estimate(DummyString("a")) should (equal (72) or equal (64))
SizeEstimator.estimate("ab") should (equal (72) or equal (64)) SizeEstimator.estimate(DummyString("ab")) should (equal (72) or equal (64))
SizeEstimator.estimate("abcdefgh") should (equal (80) or equal (72)) SizeEstimator.estimate(DummyString("abcdefgh")) should (equal (80) or equal (72))
resetOrClear("os.arch", arch) resetOrClear("os.arch", arch)
resetOrClear("spark.test.useCompressedOops", oops) resetOrClear("spark.test.useCompressedOops", oops)
......
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