Skip to content

Commit b215dea

Browse files
committed
Fixed spurious failures in ImplicitOrderingSuite
1 parent be1ecd6 commit b215dea

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

core/src/test/scala/org/apache/spark/ImplicitOrderingSuite.scala

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,29 @@ package org.apache.spark
1919

2020
import org.scalatest.FunSuite
2121

22+
import org.apache.spark.rdd.RDD
2223
import org.apache.spark.SparkContext._
2324

2425
class ImplicitOrderingSuite extends FunSuite with LocalSparkContext {
26+
// Tests that PairRDDFunctions grabs an implicit Ordering in various cases where it should.
27+
test("basic inference of Orderings"){
28+
sc = new SparkContext("local", "test")
29+
val rdd = sc.parallelize(1 to 10)
30+
31+
// These RDD methods are in the companion object so that the unserializable ScalaTest Engine
32+
// won't be reachable from the closure object
33+
34+
// Infer orderings after basic maps to particular types
35+
val basicMapExpectations = ImplicitOrderingSuite.basicMapExpectations(rdd)
36+
basicMapExpectations.map({case (met, explain) => assert(met, explain)})
37+
38+
// Infer orderings for other RDD methods
39+
val otherRDDMethodExpectations = ImplicitOrderingSuite.otherRDDMethodExpectations(rdd)
40+
otherRDDMethodExpectations.map({case (met, explain) => assert(met, explain)})
41+
}
42+
}
43+
44+
private object ImplicitOrderingSuite {
2545
class NonOrderedClass {}
2646

2747
class ComparableClass extends Comparable[ComparableClass] {
@@ -31,27 +51,36 @@ class ImplicitOrderingSuite extends FunSuite with LocalSparkContext {
3151
class OrderedClass extends Ordered[OrderedClass] {
3252
override def compare(o: OrderedClass): Int = ???
3353
}
34-
35-
// Tests that PairRDDFunctions grabs an implicit Ordering in various cases where it should.
36-
test("basic inference of Orderings"){
37-
sc = new SparkContext("local", "test")
38-
val rdd = sc.parallelize(1 to 10)
39-
40-
// Infer orderings after basic maps to particular types
41-
assert(rdd.map(x => (x, x)).keyOrdering.isDefined)
42-
assert(rdd.map(x => (1, x)).keyOrdering.isDefined)
43-
assert(rdd.map(x => (x.toString, x)).keyOrdering.isDefined)
44-
assert(rdd.map(x => (null, x)).keyOrdering.isDefined)
45-
assert(rdd.map(x => (new NonOrderedClass, x)).keyOrdering.isEmpty)
46-
assert(rdd.map(x => (new ComparableClass, x)).keyOrdering.isDefined)
47-
assert(rdd.map(x => (new OrderedClass, x)).keyOrdering.isDefined)
48-
49-
// Infer orderings for other RDD methods
50-
assert(rdd.groupBy(x => x).keyOrdering.isDefined)
51-
assert(rdd.groupBy(x => new NonOrderedClass).keyOrdering.isEmpty)
52-
assert(rdd.groupBy(x => new ComparableClass).keyOrdering.isDefined)
53-
assert(rdd.groupBy(x => new OrderedClass).keyOrdering.isDefined)
54-
assert(rdd.groupBy((x: Int) => x, 5).keyOrdering.isDefined)
55-
assert(rdd.groupBy((x: Int) => x, new HashPartitioner(5)).keyOrdering.isDefined)
54+
55+
def basicMapExpectations(rdd: RDD[Int]) = {
56+
List((rdd.map(x => (x, x)).keyOrdering.isDefined,
57+
"rdd.map(x => (x, x)).keyOrdering.isDefined"),
58+
(rdd.map(x => (1, x)).keyOrdering.isDefined,
59+
"rdd.map(x => (1, x)).keyOrdering.isDefined"),
60+
(rdd.map(x => (x.toString, x)).keyOrdering.isDefined,
61+
"rdd.map(x => (x.toString, x)).keyOrdering.isDefined"),
62+
(rdd.map(x => (null, x)).keyOrdering.isDefined,
63+
"rdd.map(x => (null, x)).keyOrdering.isDefined"),
64+
(rdd.map(x => (new NonOrderedClass, x)).keyOrdering.isEmpty,
65+
"rdd.map(x => (new NonOrderedClass, x)).keyOrdering.isEmpty"),
66+
(rdd.map(x => (new ComparableClass, x)).keyOrdering.isDefined,
67+
"rdd.map(x => (new ComparableClass, x)).keyOrdering.isDefined"),
68+
(rdd.map(x => (new OrderedClass, x)).keyOrdering.isDefined,
69+
"rdd.map(x => (new OrderedClass, x)).keyOrdering.isDefined"))
5670
}
57-
}
71+
72+
def otherRDDMethodExpectations(rdd: RDD[Int]) = {
73+
List((rdd.groupBy(x => x).keyOrdering.isDefined,
74+
"rdd.groupBy(x => x).keyOrdering.isDefined"),
75+
(rdd.groupBy(x => new NonOrderedClass).keyOrdering.isEmpty,
76+
"rdd.groupBy(x => new NonOrderedClass).keyOrdering.isEmpty"),
77+
(rdd.groupBy(x => new ComparableClass).keyOrdering.isDefined,
78+
"rdd.groupBy(x => new ComparableClass).keyOrdering.isDefined"),
79+
(rdd.groupBy(x => new OrderedClass).keyOrdering.isDefined,
80+
"rdd.groupBy(x => new OrderedClass).keyOrdering.isDefined"),
81+
(rdd.groupBy((x: Int) => x, 5).keyOrdering.isDefined,
82+
"rdd.groupBy((x: Int) => x, 5).keyOrdering.isDefined"),
83+
(rdd.groupBy((x: Int) => x, new HashPartitioner(5)).keyOrdering.isDefined,
84+
"rdd.groupBy((x: Int) => x, new HashPartitioner(5)).keyOrdering.isDefined"))
85+
}
86+
}

0 commit comments

Comments
 (0)