Hi Sudershan,

That's interesting. I don't have an answer to your question but considering
the functional nature of Spark, I have hardly had to use mock objects(maybe
you could inform us of your use case). Mock object 'expectations' are in
'most' cases implementation of 'Tell, Don't ask' principle which deals with
stateful object interactions unlike the 'value object/type' (POJO objects,
I think , in Java parlance) kind of design expected by data driven
computation or functional programming(and Spark , I guess).

Maybe you could map a value object from your stateful domain object and
then feed that to Spark? And then it may become easier.

Another question to ask is are the tests testing multiple responsibilities
which sometimes is a pain to maintain. Should one separate out the mocking
into a unit test just for that domain object and have a separate unit test
just to test the data computation done by spark(which I suggested above).



2014-09-09 20:38 GMT-04:00 Sudershan Malpani <sudershan.malp...@gmail.com>:

> Class1.java
>
> @Autowired
> Private ClassX cx;
>
> Public list method1(JavaPairRDD data){
>      List list1 = new ArrayList();
>      List list2 = new ArrayList();
>      JavaPairRDD computed = data.map(
>             new Function<Tuple2<object, list>>() {
>                 Public List call(object obj) throws exception {
>               cx.method2(list2);
>            Return list1;
> }});
>     Return computed.flatMap(new FlatMapfunc() { do something }}).collect();
>   }
> }
>
> Class1Test.java
>
> @Mock
> Private ClassX cx;
>
> @InjectMocks
> Private Class1 c1;
>
> @Before
> Public void init() {
>   Super.init();
>    Sc = getSparkContext();
>    doNothing().when(cx).method2(Collections.<object>emptyList());
> }
>
> @Test
> Public void testMethod1() {
>    JavaRDD alldata = Sc.paraalelize("");
>    JavaPairRDD data = createrdd(alldata);
>    c1.method1(rdd);
> }
>
>
>
> Sudershan Malpani
> Sent from my iPhone
>
> > On Sep 9, 2014, at 5:16 PM, Reynold Xin <r...@databricks.com> wrote:
> >
> > Can you be a little bit more specific, maybe give a code snippet?
> >
> >
> >> On Tue, Sep 9, 2014 at 5:14 PM, Sudershan Malpani <
> sudershan.malp...@gmail.com> wrote:
> >> Hi all,
> >>
> >> I am calling an object which in turn is calling a method inside a map
> RDD in spark. While writing the tests how can I mock that object's call?
> Currently I did doNothing().when(class).method() is called but it is giving
> task not serializable exception. I tried making the class both spy and mock.
> >>
> >> Sudershan Malpani
> >> Sent from my iPhone
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscr...@spark.apache.org
> >> For additional commands, e-mail: dev-h...@spark.apache.org
> >>
> >
>



-- 
Take care,
Rajiv

Reply via email to