Skip to content

Commit 928e1e3

Browse files
author
liguoqiang
committed
Added a unit test for PairRDDFunctions.lookup with bad partitioner
1 parent db6ecc5 commit 928e1e3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/src/test/scala/org/apache/spark/rdd/PairRDDFunctionsSuite.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
373373
assert(shuffled.lookup(5) === Seq(6,7))
374374
assert(shuffled.lookup(-1) === Seq())
375375
}
376+
377+
test("lookup with bad partitioner") {
378+
val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))
379+
380+
val p = new Partitioner {
381+
def numPartitions: Int = 2
382+
383+
def getPartition(key: Any): Int = key.hashCode() % 2
384+
}
385+
val shuffled = pairs.partitionBy(p)
386+
387+
assert(shuffled.partitioner === Some(p))
388+
assert(shuffled.lookup(1) === Seq(2))
389+
intercept[IllegalArgumentException] {shuffled.lookup(-1)}
390+
}
391+
376392
}
377393

378394
/*

0 commit comments

Comments
 (0)