Skip to content

Commit

Permalink
Added a unit test for PairRDDFunctions.lookup
Browse files Browse the repository at this point in the history
Lookup didn't have a unit test. Added two tests, one for with a partitioner, and one for without.

Author: Bryn Keller <bryn.keller@intel.com>

Closes apache#36 from xoltar/lookup and squashes the following commits:

3bc0d44 [Bryn Keller] Added a unit test for PairRDDFunctions.lookup
  • Loading branch information
xoltar authored and mateiz committed Mar 4, 2014
1 parent b55cade commit 923dba5
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,32 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
*/
pairs.saveAsNewAPIHadoopFile[ConfigTestFormat]("ignored")
}

test("lookup") {
val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))

assert(pairs.partitioner === None)
assert(pairs.lookup(1) === Seq(2))
assert(pairs.lookup(5) === Seq(6,7))
assert(pairs.lookup(-1) === Seq())

}

test("lookup with partitioner") {
val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))

val p = new Partitioner {
def numPartitions: Int = 2

def getPartition(key: Any): Int = Math.abs(key.hashCode() % 2)
}
val shuffled = pairs.partitionBy(p)

assert(shuffled.partitioner === Some(p))
assert(shuffled.lookup(1) === Seq(2))
assert(shuffled.lookup(5) === Seq(6,7))
assert(shuffled.lookup(-1) === Seq())
}
}

/*
Expand Down

0 comments on commit 923dba5

Please sign in to comment.