Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AccumulatorSuite extends FunSuite with Matchers with LocalSparkContext {
val acc : Accumulator[Int] = sc.accumulator(0)

val d = sc.parallelize(1 to 20)
evaluating {d.foreach{x => acc.value = x}} should produce [Exception]
an [Exception] should be thrownBy {d.foreach{x => acc.value = x}}
}

test ("add value to collection accumulators") {
Expand All @@ -87,11 +87,11 @@ class AccumulatorSuite extends FunSuite with Matchers with LocalSparkContext {
sc = new SparkContext("local[" + nThreads + "]", "test")
val acc: Accumulable[mutable.Set[Any], Any] = sc.accumulable(new mutable.HashSet[Any]())
val d = sc.parallelize(1 to maxI)
evaluating {
an [SparkException] should be thrownBy {
d.foreach {
x => acc.value += x
}
} should produce [SparkException]
}
resetSparkContext()
}
}
Expand Down
38 changes: 19 additions & 19 deletions core/src/test/scala/org/apache/spark/util/NextIteratorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ import org.scalatest.Matchers
class NextIteratorSuite extends FunSuite with Matchers {
test("one iteration") {
val i = new StubIterator(Buffer(1))
i.hasNext should be === true
i.next should be === 1
i.hasNext should be === false
i.hasNext should be (true)
i.next should be (1)
i.hasNext should be (false)
intercept[NoSuchElementException] { i.next() }
}

test("two iterations") {
val i = new StubIterator(Buffer(1, 2))
i.hasNext should be === true
i.next should be === 1
i.hasNext should be === true
i.next should be === 2
i.hasNext should be === false
i.hasNext should be (true)
i.next should be (1)
i.hasNext should be (true)
i.next should be (2)
i.hasNext should be (false)
intercept[NoSuchElementException] { i.next() }
}

test("empty iteration") {
val i = new StubIterator(Buffer())
i.hasNext should be === false
i.hasNext should be (false)
intercept[NoSuchElementException] { i.next() }
}

test("close is called once for empty iterations") {
val i = new StubIterator(Buffer())
i.hasNext should be === false
i.hasNext should be === false
i.closeCalled should be === 1
i.hasNext should be (false)
i.hasNext should be (false)
i.closeCalled should be (1)
}

test("close is called once for non-empty iterations") {
val i = new StubIterator(Buffer(1, 2))
i.next should be === 1
i.next should be === 2
i.next should be (1)
i.next should be (2)
// close isn't called until we check for the next element
i.closeCalled should be === 0
i.hasNext should be === false
i.closeCalled should be === 1
i.hasNext should be === false
i.closeCalled should be === 1
i.closeCalled should be (0)
i.hasNext should be (false)
i.closeCalled should be (1)
i.hasNext should be (false)
i.closeCalled should be (1)
}

class StubIterator(ints: Buffer[Int]) extends NextIterator[Int] {
Expand Down
70 changes: 35 additions & 35 deletions core/src/test/scala/org/apache/spark/util/SizeEstimatorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,53 @@ class SizeEstimatorSuite
}

test("simple classes") {
expectResult(16)(SizeEstimator.estimate(new DummyClass1))
expectResult(16)(SizeEstimator.estimate(new DummyClass2))
expectResult(24)(SizeEstimator.estimate(new DummyClass3))
expectResult(24)(SizeEstimator.estimate(new DummyClass4(null)))
expectResult(48)(SizeEstimator.estimate(new DummyClass4(new DummyClass3)))
assertResult(16)(SizeEstimator.estimate(new DummyClass1))
assertResult(16)(SizeEstimator.estimate(new DummyClass2))
assertResult(24)(SizeEstimator.estimate(new DummyClass3))
assertResult(24)(SizeEstimator.estimate(new DummyClass4(null)))
assertResult(48)(SizeEstimator.estimate(new DummyClass4(new DummyClass3)))
}

// 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.
test("strings") {
expectResult(40)(SizeEstimator.estimate(DummyString("")))
expectResult(48)(SizeEstimator.estimate(DummyString("a")))
expectResult(48)(SizeEstimator.estimate(DummyString("ab")))
expectResult(56)(SizeEstimator.estimate(DummyString("abcdefgh")))
assertResult(40)(SizeEstimator.estimate(DummyString("")))
assertResult(48)(SizeEstimator.estimate(DummyString("a")))
assertResult(48)(SizeEstimator.estimate(DummyString("ab")))
assertResult(56)(SizeEstimator.estimate(DummyString("abcdefgh")))
}

test("primitive arrays") {
expectResult(32)(SizeEstimator.estimate(new Array[Byte](10)))
expectResult(40)(SizeEstimator.estimate(new Array[Char](10)))
expectResult(40)(SizeEstimator.estimate(new Array[Short](10)))
expectResult(56)(SizeEstimator.estimate(new Array[Int](10)))
expectResult(96)(SizeEstimator.estimate(new Array[Long](10)))
expectResult(56)(SizeEstimator.estimate(new Array[Float](10)))
expectResult(96)(SizeEstimator.estimate(new Array[Double](10)))
expectResult(4016)(SizeEstimator.estimate(new Array[Int](1000)))
expectResult(8016)(SizeEstimator.estimate(new Array[Long](1000)))
assertResult(32)(SizeEstimator.estimate(new Array[Byte](10)))
assertResult(40)(SizeEstimator.estimate(new Array[Char](10)))
assertResult(40)(SizeEstimator.estimate(new Array[Short](10)))
assertResult(56)(SizeEstimator.estimate(new Array[Int](10)))
assertResult(96)(SizeEstimator.estimate(new Array[Long](10)))
assertResult(56)(SizeEstimator.estimate(new Array[Float](10)))
assertResult(96)(SizeEstimator.estimate(new Array[Double](10)))
assertResult(4016)(SizeEstimator.estimate(new Array[Int](1000)))
assertResult(8016)(SizeEstimator.estimate(new Array[Long](1000)))
}

test("object arrays") {
// Arrays containing nulls should just have one pointer per element
expectResult(56)(SizeEstimator.estimate(new Array[String](10)))
expectResult(56)(SizeEstimator.estimate(new Array[AnyRef](10)))
assertResult(56)(SizeEstimator.estimate(new Array[String](10)))
assertResult(56)(SizeEstimator.estimate(new Array[AnyRef](10)))
// 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
// second parameter separately for each object, so we get distinct objects.)
expectResult(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass1)))
expectResult(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass2)))
expectResult(296)(SizeEstimator.estimate(Array.fill(10)(new DummyClass3)))
expectResult(56)(SizeEstimator.estimate(Array(new DummyClass1, new DummyClass2)))
assertResult(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass1)))
assertResult(216)(SizeEstimator.estimate(Array.fill(10)(new DummyClass2)))
assertResult(296)(SizeEstimator.estimate(Array.fill(10)(new DummyClass3)))
assertResult(56)(SizeEstimator.estimate(Array(new DummyClass1, new DummyClass2)))

// Past size 100, our samples 100 elements, but we should still get the right size.
expectResult(28016)(SizeEstimator.estimate(Array.fill(1000)(new DummyClass3)))
assertResult(28016)(SizeEstimator.estimate(Array.fill(1000)(new DummyClass3)))

// If an array contains the *same* element many times, we should only count it once.
val d1 = new DummyClass1
expectResult(72)(SizeEstimator.estimate(Array.fill(10)(d1))) // 10 pointers plus 8-byte object
expectResult(432)(SizeEstimator.estimate(Array.fill(100)(d1))) // 100 pointers plus 8-byte object
assertResult(72)(SizeEstimator.estimate(Array.fill(10)(d1))) // 10 pointers plus 8-byte object
assertResult(432)(SizeEstimator.estimate(Array.fill(100)(d1))) // 100 pointers plus 8-byte object

// 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
Expand All @@ -127,10 +127,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize()

expectResult(40)(SizeEstimator.estimate(DummyString("")))
expectResult(48)(SizeEstimator.estimate(DummyString("a")))
expectResult(48)(SizeEstimator.estimate(DummyString("ab")))
expectResult(56)(SizeEstimator.estimate(DummyString("abcdefgh")))
assertResult(40)(SizeEstimator.estimate(DummyString("")))
assertResult(48)(SizeEstimator.estimate(DummyString("a")))
assertResult(48)(SizeEstimator.estimate(DummyString("ab")))
assertResult(56)(SizeEstimator.estimate(DummyString("abcdefgh")))
resetOrClear("os.arch", arch)
}

Expand All @@ -142,10 +142,10 @@ class SizeEstimatorSuite
val initialize = PrivateMethod[Unit]('initialize)
SizeEstimator invokePrivate initialize()

expectResult(56)(SizeEstimator.estimate(DummyString("")))
expectResult(64)(SizeEstimator.estimate(DummyString("a")))
expectResult(64)(SizeEstimator.estimate(DummyString("ab")))
expectResult(72)(SizeEstimator.estimate(DummyString("abcdefgh")))
assertResult(56)(SizeEstimator.estimate(DummyString("")))
assertResult(64)(SizeEstimator.estimate(DummyString("a")))
assertResult(64)(SizeEstimator.estimate(DummyString("ab")))
assertResult(72)(SizeEstimator.estimate(DummyString("abcdefgh")))

resetOrClear("os.arch", arch)
resetOrClear("spark.test.useCompressedOops", oops)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ColumnStatsSuite extends FunSuite {

test(s"$columnStatsName: empty") {
val columnStats = columnStatsClass.newInstance()
expectResult(columnStats.initialBounds, "Wrong initial bounds") {
assertResult(columnStats.initialBounds, "Wrong initial bounds") {
(columnStats.lowerBound, columnStats.upperBound)
}
}
Expand All @@ -54,8 +54,8 @@ class ColumnStatsSuite extends FunSuite {
val values = rows.map(_.head.asInstanceOf[T#JvmType])
val ordering = columnType.dataType.ordering.asInstanceOf[Ordering[T#JvmType]]

expectResult(values.min(ordering), "Wrong lower bound")(columnStats.lowerBound)
expectResult(values.max(ordering), "Wrong upper bound")(columnStats.upperBound)
assertResult(values.min(ordering), "Wrong lower bound")(columnStats.lowerBound)
assertResult(values.max(ordering), "Wrong upper bound")(columnStats.upperBound)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ColumnTypeSuite extends FunSuite with Logging {
BOOLEAN -> 1, STRING -> 8, BINARY -> 16, GENERIC -> 16)

checks.foreach { case (columnType, expectedSize) =>
expectResult(expectedSize, s"Wrong defaultSize for $columnType") {
assertResult(expectedSize, s"Wrong defaultSize for $columnType") {
columnType.defaultSize
}
}
Expand All @@ -47,7 +47,7 @@ class ColumnTypeSuite extends FunSuite with Logging {
value: JvmType,
expected: Int) {

expectResult(expected, s"Wrong actualSize for $columnType") {
assertResult(expected, s"Wrong actualSize for $columnType") {
columnType.actualSize(value)
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ class ColumnTypeSuite extends FunSuite with Logging {
val length = buffer.getInt()
assert(length === serializedObj.length)

expectResult(obj, "Deserialized object didn't equal to the original object") {
assertResult(obj, "Deserialized object didn't equal to the original object") {
val bytes = new Array[Byte](length)
buffer.get(bytes, 0, length)
SparkSqlSerializer.deserialize(bytes)
Expand All @@ -136,7 +136,7 @@ class ColumnTypeSuite extends FunSuite with Logging {
buffer.rewind()
buffer.putInt(serializedObj.length).put(serializedObj)

expectResult(obj, "Deserialized object didn't equal to the original object") {
assertResult(obj, "Deserialized object didn't equal to the original object") {
buffer.rewind()
SparkSqlSerializer.deserialize(GENERIC.extract(buffer))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class NullableColumnBuilderSuite extends FunSuite {
val columnBuilder = TestNullableColumnBuilder(columnType)
val buffer = columnBuilder.build()

expectResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
expectResult(0, "Wrong null count")(buffer.getInt())
assertResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
assertResult(0, "Wrong null count")(buffer.getInt())
assert(!buffer.hasRemaining)
}

Expand All @@ -63,8 +63,8 @@ class NullableColumnBuilderSuite extends FunSuite {

val buffer = columnBuilder.build()

expectResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
expectResult(0, "Wrong null count")(buffer.getInt())
assertResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
assertResult(0, "Wrong null count")(buffer.getInt())
}

test(s"$typeName column builder: null values") {
Expand All @@ -79,11 +79,11 @@ class NullableColumnBuilderSuite extends FunSuite {

val buffer = columnBuilder.build()

expectResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
expectResult(4, "Wrong null count")(buffer.getInt())
assertResult(columnType.typeId, "Wrong column type ID")(buffer.getInt())
assertResult(4, "Wrong null count")(buffer.getInt())

// For null positions
(1 to 7 by 2).foreach(expectResult(_, "Wrong null position")(buffer.getInt()))
(1 to 7 by 2).foreach(assertResult(_, "Wrong null position")(buffer.getInt()))

// For non-null values
(0 until 4).foreach { _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ class BooleanBitSetSuite extends FunSuite {
}

// 4 extra bytes for compression scheme type ID
expectResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)
assertResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)

// Skips column header
buffer.position(headerSize)
expectResult(BooleanBitSet.typeId, "Wrong compression scheme ID")(buffer.getInt())
expectResult(count, "Wrong element count")(buffer.getInt())
assertResult(BooleanBitSet.typeId, "Wrong compression scheme ID")(buffer.getInt())
assertResult(count, "Wrong element count")(buffer.getInt())

var word = 0: Long
for (i <- 0 until count) {
val bit = i % BITS_PER_LONG
word = if (bit == 0) buffer.getLong() else word
expectResult(values(i), s"Wrong value in compressed buffer, index=$i") {
assertResult(values(i), s"Wrong value in compressed buffer, index=$i") {
(word & ((1: Long) << bit)) != 0
}
}
Expand All @@ -75,7 +75,7 @@ class BooleanBitSetSuite extends FunSuite {
if (values.nonEmpty) {
values.foreach {
assert(decoder.hasNext)
expectResult(_, "Wrong decoded value")(decoder.next())
assertResult(_, "Wrong decoded value")(decoder.next())
}
}
assert(!decoder.hasNext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ class DictionaryEncodingSuite extends FunSuite {
// 2 bytes for each `Short`
val compressedSize = 4 + dictionarySize + 2 * inputSeq.length
// 4 extra bytes for compression scheme type ID
expectResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)
assertResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)

// Skips column header
buffer.position(headerSize)
expectResult(DictionaryEncoding.typeId, "Wrong compression scheme ID")(buffer.getInt())
assertResult(DictionaryEncoding.typeId, "Wrong compression scheme ID")(buffer.getInt())

val dictionary = buildDictionary(buffer).toMap

dictValues.foreach { i =>
expectResult(i, "Wrong dictionary entry") {
assertResult(i, "Wrong dictionary entry") {
dictionary(values(i))
}
}

inputSeq.foreach { i =>
expectResult(i.toShort, "Wrong column element value")(buffer.getShort())
assertResult(i.toShort, "Wrong column element value")(buffer.getShort())
}

// -------------
Expand All @@ -101,7 +101,7 @@ class DictionaryEncodingSuite extends FunSuite {
if (inputSeq.nonEmpty) {
inputSeq.foreach { i =>
assert(decoder.hasNext)
expectResult(values(i), "Wrong decoded value")(decoder.next())
assertResult(values(i), "Wrong decoded value")(decoder.next())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ class IntegralDeltaSuite extends FunSuite {
})

// 4 extra bytes for compression scheme type ID
expectResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)
assertResult(headerSize + compressedSize, "Wrong buffer capacity")(buffer.capacity)

buffer.position(headerSize)
expectResult(scheme.typeId, "Wrong compression scheme ID")(buffer.getInt())
assertResult(scheme.typeId, "Wrong compression scheme ID")(buffer.getInt())

if (input.nonEmpty) {
expectResult(Byte.MinValue, "The first byte should be an escaping mark")(buffer.get())
expectResult(input.head, "The first value is wrong")(columnType.extract(buffer))
assertResult(Byte.MinValue, "The first byte should be an escaping mark")(buffer.get())
assertResult(input.head, "The first value is wrong")(columnType.extract(buffer))

(input.tail, deltas).zipped.foreach { (value, delta) =>
if (math.abs(delta) <= Byte.MaxValue) {
expectResult(delta, "Wrong delta")(buffer.get())
assertResult(delta, "Wrong delta")(buffer.get())
} else {
expectResult(Byte.MinValue, "Expecting escaping mark here")(buffer.get())
expectResult(value, "Wrong value")(columnType.extract(buffer))
assertResult(Byte.MinValue, "Expecting escaping mark here")(buffer.get())
assertResult(value, "Wrong value")(columnType.extract(buffer))
}
}
}
Expand All @@ -99,7 +99,7 @@ class IntegralDeltaSuite extends FunSuite {
if (input.nonEmpty) {
input.foreach{
assert(decoder.hasNext)
expectResult(_, "Wrong decoded value")(decoder.next())
assertResult(_, "Wrong decoded value")(decoder.next())
}
}
assert(!decoder.hasNext)
Expand Down
Loading