Fixed deprecated use of expect in SizeEstimatorSuite

This commit is contained in:
Matei Zaharia 2013-06-25 16:11:44 -04:00
parent 7e0191c6ea
commit 7680ce0bd6

View file

@ -46,54 +46,54 @@ class SizeEstimatorSuite
} }
test("simple classes") { test("simple classes") {
expect(16)(SizeEstimator.estimate(new DummyClass1)) assert(SizeEstimator.estimate(new DummyClass1) === 16)
expect(16)(SizeEstimator.estimate(new DummyClass2)) assert(SizeEstimator.estimate(new DummyClass2) === 16)
expect(24)(SizeEstimator.estimate(new DummyClass3)) assert(SizeEstimator.estimate(new DummyClass3) === 24)
expect(24)(SizeEstimator.estimate(new DummyClass4(null))) assert(SizeEstimator.estimate(new DummyClass4(null)) === 24)
expect(48)(SizeEstimator.estimate(new DummyClass4(new DummyClass3))) assert(SizeEstimator.estimate(new DummyClass4(new DummyClass3)) === 48)
} }
// NOTE: The String class definition varies across JDK versions (1.6 vs. 1.7) and vendors // NOTE: The String class definition varies across JDK versions (1.6 vs. 1.7) and vendors
// (Sun vs IBM). Use a DummyString class to make tests deterministic. // (Sun vs IBM). Use a DummyString class to make tests deterministic.
test("strings") { test("strings") {
expect(40)(SizeEstimator.estimate(DummyString(""))) assert(SizeEstimator.estimate(DummyString("")) === 40)
expect(48)(SizeEstimator.estimate(DummyString("a"))) assert(SizeEstimator.estimate(DummyString("a")) === 48)
expect(48)(SizeEstimator.estimate(DummyString("ab"))) assert(SizeEstimator.estimate(DummyString("ab")) === 48)
expect(56)(SizeEstimator.estimate(DummyString("abcdefgh"))) assert(SizeEstimator.estimate(DummyString("abcdefgh")) === 56)
} }
test("primitive arrays") { test("primitive arrays") {
expect(32)(SizeEstimator.estimate(new Array[Byte](10))) assert(SizeEstimator.estimate(new Array[Byte](10)) === 32)
expect(40)(SizeEstimator.estimate(new Array[Char](10))) assert(SizeEstimator.estimate(new Array[Char](10)) === 40)
expect(40)(SizeEstimator.estimate(new Array[Short](10))) assert(SizeEstimator.estimate(new Array[Short](10)) === 40)
expect(56)(SizeEstimator.estimate(new Array[Int](10))) assert(SizeEstimator.estimate(new Array[Int](10)) === 56)
expect(96)(SizeEstimator.estimate(new Array[Long](10))) assert(SizeEstimator.estimate(new Array[Long](10)) === 96)
expect(56)(SizeEstimator.estimate(new Array[Float](10))) assert(SizeEstimator.estimate(new Array[Float](10)) === 56)
expect(96)(SizeEstimator.estimate(new Array[Double](10))) assert(SizeEstimator.estimate(new Array[Double](10)) === 96)
expect(4016)(SizeEstimator.estimate(new Array[Int](1000))) assert(SizeEstimator.estimate(new Array[Int](1000)) === 4016)
expect(8016)(SizeEstimator.estimate(new Array[Long](1000))) assert(SizeEstimator.estimate(new Array[Long](1000)) === 8016)
} }
test("object arrays") { test("object arrays") {
// Arrays containing nulls should just have one pointer per element // Arrays containing nulls should just have one pointer per element
expect(56)(SizeEstimator.estimate(new Array[String](10))) assert(SizeEstimator.estimate(new Array[String](10)) === 56)
expect(56)(SizeEstimator.estimate(new Array[AnyRef](10))) assert(SizeEstimator.estimate(new Array[AnyRef](10)) === 56)
// For object arrays with non-null elements, each object should take one pointer plus // For object arrays with non-null elements, each object should take one pointer plus
// however many bytes that class takes. (Note that Array.fill calls the code in its // however many bytes that class takes. (Note that Array.fill calls the code in its
// second parameter separately for each object, so we get distinct objects.) // second parameter separately for each object, so we get distinct objects.)
expect(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass1))) assert(SizeEstimator.estimate(Array.fill(10)(new DummyClass1)) === 216)
expect(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass2))) assert(SizeEstimator.estimate(Array.fill(10)(new DummyClass2)) === 216)
expect(296)(SizeEstimator.estimate(Array.fill(10)(new DummyClass3))) assert(SizeEstimator.estimate(Array.fill(10)(new DummyClass3)) === 296)
expect(56)(SizeEstimator.estimate(Array(new DummyClass1, new DummyClass2))) assert(SizeEstimator.estimate(Array(new DummyClass1, new DummyClass2)) === 56)
// Past size 100, our samples 100 elements, but we should still get the right size. // Past size 100, our samples 100 elements, but we should still get the right size.
expect(28016)(SizeEstimator.estimate(Array.fill(1000)(new DummyClass3))) assert(SizeEstimator.estimate(Array.fill(1000)(new DummyClass3)) === 28016)
// If an array contains the *same* element many times, we should only count it once. // If an array contains the *same* element many times, we should only count it once.
val d1 = new DummyClass1 val d1 = new DummyClass1
expect(72)(SizeEstimator.estimate(Array.fill(10)(d1))) // 10 pointers plus 8-byte object assert(SizeEstimator.estimate(Array.fill(10)(d1)) === 72) // 10 pointers plus 8-byte object
expect(432)(SizeEstimator.estimate(Array.fill(100)(d1))) // 100 pointers plus 8-byte object assert(SizeEstimator.estimate(Array.fill(100)(d1)) === 432) // 100 pointers plus 8-byte object
// Same thing with huge array containing the same element many times. Note that this won't // Same thing with huge array containing the same element many times. Note that this won't
// return exactly 4032 because it can't tell that *all* the elements will equal the first // return exactly 4032 because it can't tell that *all* the elements will equal the first
@ -111,10 +111,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize) val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize() SizeEstimator invokePrivate initialize()
expect(40)(SizeEstimator.estimate(DummyString(""))) assert(SizeEstimator.estimate(DummyString("")) === 40)
expect(48)(SizeEstimator.estimate(DummyString("a"))) assert(SizeEstimator.estimate(DummyString("a")) === 48)
expect(48)(SizeEstimator.estimate(DummyString("ab"))) assert(SizeEstimator.estimate(DummyString("ab")) === 48)
expect(56)(SizeEstimator.estimate(DummyString("abcdefgh"))) assert(SizeEstimator.estimate(DummyString("abcdefgh")) === 56)
resetOrClear("os.arch", arch) resetOrClear("os.arch", arch)
} }
@ -128,10 +128,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize) val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize() SizeEstimator invokePrivate initialize()
expect(56)(SizeEstimator.estimate(DummyString(""))) assert(SizeEstimator.estimate(DummyString("")) === 56)
expect(64)(SizeEstimator.estimate(DummyString("a"))) assert(SizeEstimator.estimate(DummyString("a")) === 64)
expect(64)(SizeEstimator.estimate(DummyString("ab"))) assert(SizeEstimator.estimate(DummyString("ab")) === 64)
expect(72)(SizeEstimator.estimate(DummyString("abcdefgh"))) assert(SizeEstimator.estimate(DummyString("abcdefgh")) === 72)
resetOrClear("os.arch", arch) resetOrClear("os.arch", arch)
resetOrClear("spark.test.useCompressedOops", oops) resetOrClear("spark.test.useCompressedOops", oops)