Skip to content

Commit

Permalink
SPARK-4459 added failing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Saldanha committed Nov 17, 2014
1 parent 0f3ceb5 commit 62ddd4b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/test/java/org/apache/spark/JavaAPISuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ public Boolean call(Integer x) {
Assert.assertEquals(2, Iterables.size(oddsAndEvens.lookup(true).get(0))); // Evens
Assert.assertEquals(5, Iterables.size(oddsAndEvens.lookup(false).get(0))); // Odds
}

@Test
public void groupByOnPairRDD() {
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 1, 2, 3, 5, 8, 13));
Function<scala.Tuple2<Integer, Integer>, Boolean> areOdd = new Function<scala.Tuple2<Integer, Integer>, Boolean>() {
@Override
public Boolean call(scala.Tuple2<Integer, Integer> x) {
return x._1 % 2 == 0 && x._2 % 2 == 0;
}
};
JavaPairRDD<Integer, Integer> pairrdd = rdd.zip(rdd);
JavaPairRDD<Boolean, Iterable<scala.Tuple2<Integer, Integer>>> oddsAndEvens = pairrdd.groupBy(areOdd);
Assert.assertEquals(2, oddsAndEvens.count());
Assert.assertEquals(2, Iterables.size(oddsAndEvens.lookup(true).get(0))); // Evens
Assert.assertEquals(5, Iterables.size(oddsAndEvens.lookup(false).get(0))); // Odds

oddsAndEvens = pairrdd.groupBy(areOdd, 1);
Assert.assertEquals(2, oddsAndEvens.count());
Assert.assertEquals(2, Iterables.size(oddsAndEvens.lookup(true).get(0))); // Evens
Assert.assertEquals(5, Iterables.size(oddsAndEvens.lookup(false).get(0))); // Odds
}

@SuppressWarnings("unchecked")
@Test
Expand Down

0 comments on commit 62ddd4b

Please sign in to comment.