aboutsummaryrefslogtreecommitdiff
path: root/core/src/test
diff options
context:
space:
mode:
authorShivaram Venkataraman <shivaram@eecs.berkeley.edu>2012-10-04 19:42:57 -0700
committerMatei Zaharia <matei@eecs.berkeley.edu>2012-10-05 16:58:57 -0700
commitb6e4f46a968b167eae9b7dd4fac82a98934eebe9 (patch)
treeea9dedf110f690923a560b62567e4984dedc3ee9 /core/src/test
parente3ae98b54e4cd9553afcb92b1c2eb555782d5720 (diff)
downloadspark-b6e4f46a968b167eae9b7dd4fac82a98934eebe9.tar.gz
spark-b6e4f46a968b167eae9b7dd4fac82a98934eebe9.tar.bz2
spark-b6e4f46a968b167eae9b7dd4fac82a98934eebe9.zip
Fix SizeEstimator tests to work with String classes in JDK 6 and 7
Conflicts: core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
Diffstat (limited to 'core/src/test')
-rw-r--r--core/src/test/scala/spark/BoundedMemoryCacheSuite.scala13
-rw-r--r--core/src/test/scala/spark/SizeEstimatorSuite.scala28
2 files changed, 29 insertions, 12 deletions
diff --git a/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala b/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
index e00e8c4123..37cafd1e8e 100644
--- a/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
+++ b/core/src/test/scala/spark/BoundedMemoryCacheSuite.scala
@@ -2,9 +2,10 @@ package spark
import org.scalatest.FunSuite
import org.scalatest.PrivateMethodTester
+import org.scalatest.matchers.ShouldMatchers
// TODO: Replace this with a test of MemoryStore
-class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester {
+class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester with ShouldMatchers {
test("constructor test") {
val cache = new BoundedMemoryCache(60)
expect(60)(cache.getCapacity)
@@ -23,15 +24,21 @@ class BoundedMemoryCacheSuite extends FunSuite with PrivateMethodTester {
logInfo("Dropping key (%s, %d) of size %d to make space".format(datasetId, partition, entry.size))
}
}
+
+ // NOTE: The String class definition changed in JDK 7 to exclude the int fields count and length
+ // This means that the size of strings will be lesser by 8 bytes in JDK 7 compared to JDK 6.
+ // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
+ // Work around to check for either.
+
//should be OK
- expect(CachePutSuccess(56))(cache.put("1", 0, "Meh"))
+ cache.put("1", 0, "Meh") should (equal (CachePutSuccess(56)) or equal (CachePutSuccess(48)))
//we cannot add this to cache (there is not enough space in cache) & we cannot evict the only value from
//cache because it's from the same dataset
expect(CachePutFailure())(cache.put("1", 1, "Meh"))
//should be OK, dataset '1' can be evicted from cache
- expect(CachePutSuccess(56))(cache.put("2", 0, "Meh"))
+ cache.put("2", 0, "Meh") should (equal (CachePutSuccess(56)) or equal (CachePutSuccess(48)))
//should fail, cache should obey it's capacity
expect(CachePutFailure())(cache.put("3", 0, "Very_long_and_useless_string"))
diff --git a/core/src/test/scala/spark/SizeEstimatorSuite.scala b/core/src/test/scala/spark/SizeEstimatorSuite.scala
index a2015644ee..7677ac6db5 100644
--- a/core/src/test/scala/spark/SizeEstimatorSuite.scala
+++ b/core/src/test/scala/spark/SizeEstimatorSuite.scala
@@ -3,6 +3,7 @@ package spark
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfterAll
import org.scalatest.PrivateMethodTester
+import org.scalatest.matchers.ShouldMatchers
class DummyClass1 {}
@@ -19,7 +20,8 @@ class DummyClass4(val d: DummyClass3) {
val x: Int = 0
}
-class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMethodTester {
+class SizeEstimatorSuite extends FunSuite
+ with BeforeAndAfterAll with PrivateMethodTester with ShouldMatchers {
var oldArch: String = _
var oldOops: String = _
@@ -42,11 +44,15 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMet
expect(48)(SizeEstimator.estimate(new DummyClass4(new DummyClass3)))
}
+ // NOTE: The String class definition changed in JDK 7 to exclude the int fields count and length.
+ // This means that the size of strings will be lesser by 8 bytes in JDK 7 compared to JDK 6.
+ // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
+ // Work around to check for either.
test("strings") {
- expect(48)(SizeEstimator.estimate(""))
- expect(56)(SizeEstimator.estimate("a"))
- expect(56)(SizeEstimator.estimate("ab"))
- expect(64)(SizeEstimator.estimate("abcdefgh"))
+ SizeEstimator.estimate("") should (equal (48) or equal (40))
+ SizeEstimator.estimate("a") should (equal (56) or equal (48))
+ SizeEstimator.estimate("ab") should (equal (56) or equal (48))
+ SizeEstimator.estimate("abcdefgh") should (equal(64) or equal(56))
}
test("primitive arrays") {
@@ -106,6 +112,10 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMet
resetOrClear("os.arch", arch)
}
+ // NOTE: The String class definition changed in JDK 7 to exclude the int fields count and length.
+ // This means that the size of strings will be lesser by 8 bytes in JDK 7 compared to JDK 6.
+ // http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
+ // Work around to check for either.
test("64-bit arch with no compressed oops") {
val arch = System.setProperty("os.arch", "amd64")
val oops = System.setProperty("spark.test.useCompressedOops", "false")
@@ -113,10 +123,10 @@ class SizeEstimatorSuite extends FunSuite with BeforeAndAfterAll with PrivateMet
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"))
+ SizeEstimator.estimate("") should (equal (64) or equal (56))
+ SizeEstimator.estimate("a") should (equal (72) or equal (64))
+ SizeEstimator.estimate("ab") should (equal (72) or equal (64))
+ SizeEstimator.estimate("abcdefgh") should (equal (80) or equal (72))
resetOrClear("os.arch", arch)
resetOrClear("spark.test.useCompressedOops", oops)