You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mrunit.apache.org by Sahana Bhat <sa...@gmail.com> on 2012/09/13 14:06:17 UTC
Mocking Context in setup method of Mapper
Hi,
I am using Mockito along with MRUnit for unit testing mapreduce
programs.
I am currently encountering a problem in the setup method of the Mapper.
The snippet of code i am trying to mock is :
public void setup(Context context){
/// code here
//the below code gives me a null pointer although i have mocked the Context
class using mockito in my test method.
context.getTaskAttemptID.toString();
}
In the test method i have also set an expectation:
*
when*(context.getTaskAttemptID()).thenReturn(taskAttemptID);
Any idea why the setup is returning a null TaskAttemptID? Is there any
other way to mock the Context class? What is the use of the mock package
and the corresponding classes in *
import **org.apache.hadoop.mrunit.mapreduce.mock*.*;
Thanks in advance.
Regards,
Sahana
Re: Mocking Context in setup method of Mapper
Posted by Sahana Bhat <sa...@gmail.com>.
Hi,
Thanks for the info. :)
Regards,
Sahana
On Mon, Sep 17, 2012 at 8:28 PM, Brock Noland <br...@cloudera.com> wrote:
> Sorry, this is just in trunk and is unreleased.
>
> https://issues.apache.org/jira/browse/MRUNIT-122
>
> Brock
>
> On Mon, Sep 17, 2012 at 12:08 AM, Sahana Bhat <sa...@gmail.com> wrote:
> >
> > Hi,
> >
> > I might be missing something here, but i dont see a getContext
> method
> > available in org.apache.hadoop.mrunit.mapreduce.MapDriver.
> > Can you direct me to a code snippet of the same?
> >
> > Thanks,
> > Sahana
> > On Fri, Sep 14, 2012 at 6:04 PM, Brock Noland <br...@cloudera.com>
> wrote:
> >>
> >> Context is getting mocked internally, you should use the
> >> driver.getContext() to get access to the mocked context. You can then
> >> override any methods you wish.
> >>
> >> --
> >> Brock Noland
> >> Sent with Sparrow
> >>
> >> On Friday, September 14, 2012 at 1:09 AM, Sahana Bhat wrote:
> >>
> >>
> >> Hi,
> >>
> >> You can take a look at the snippet here :
> >> http://pastebin.com/NBfPBQhL
> >> I thought i needed to mock the Context using mockito, and there would
> be a
> >> way to pass the mocked Context object to the MapDriver, but didnt find
> any
> >> such methods exposed.
> >> I am able to see that the context is getting mocked internally. Printing
> >> the context gives me :
> >>
> >> Mock for Context, hashCode: 763970039
> >>
> >> But context.getTaskAttemptID returns null.
> >>
> >> I checked the source code, and if i understand it right,
> >> MockMapContextWrapper should set the Context internally.
> >>
> >> Any help would be great.Thanks.
> >>
> >> Regards,
> >> Sahana
> >>
> >>
> >> On Thu, Sep 13, 2012 at 6:03 PM, Brock Noland <br...@cloudera.com>
> wrote:
> >>
> >> Could you share the code? Pastebin is a good place to post it.
> >>
> >> --
> >> Brock Noland
> >> Sent with Sparrow
> >>
> >> On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
> >>
> >> Hi,
> >>
> >> I am using Mockito along with MRUnit for unit testing mapreduce
> >> programs.
> >>
> >> I am currently encountering a problem in the setup method of the Mapper.
> >> The snippet of code i am trying to mock is :
> >>
> >> public void setup(Context context){
> >>
> >> /// code here
> >>
> >> //the below code gives me a null pointer although i have mocked the
> >> Context class using mockito in my test method.
> >> context.getTaskAttemptID.toString();
> >>
> >> }
> >>
> >> In the test method i have also set an expectation:
> >>
> >> when
> >>
> >> (context.getTaskAttemptID()).thenReturn(taskAttemptID);
> >>
> >> Any idea why the setup is returning a null TaskAttemptID? Is there any
> >> other way to mock the Context class? What is the use of the mock
> package and
> >> the corresponding classes in
> >>
> >> import org.apache.hadoop.mrunit.mapreduce.mock.*;
> >>
> >> Thanks in advance.
> >>
> >> Regards,
> >> Sahana
> >>
> >>
> >>
> >>
> >
>
>
>
> --
> Apache MRUnit - Unit testing MapReduce -
> http://incubator.apache.org/mrunit/
>
Re: Mocking Context in setup method of Mapper
Posted by Brock Noland <br...@cloudera.com>.
Sorry, this is just in trunk and is unreleased.
https://issues.apache.org/jira/browse/MRUNIT-122
Brock
On Mon, Sep 17, 2012 at 12:08 AM, Sahana Bhat <sa...@gmail.com> wrote:
>
> Hi,
>
> I might be missing something here, but i dont see a getContext method
> available in org.apache.hadoop.mrunit.mapreduce.MapDriver.
> Can you direct me to a code snippet of the same?
>
> Thanks,
> Sahana
> On Fri, Sep 14, 2012 at 6:04 PM, Brock Noland <br...@cloudera.com> wrote:
>>
>> Context is getting mocked internally, you should use the
>> driver.getContext() to get access to the mocked context. You can then
>> override any methods you wish.
>>
>> --
>> Brock Noland
>> Sent with Sparrow
>>
>> On Friday, September 14, 2012 at 1:09 AM, Sahana Bhat wrote:
>>
>>
>> Hi,
>>
>> You can take a look at the snippet here :
>> http://pastebin.com/NBfPBQhL
>> I thought i needed to mock the Context using mockito, and there would be a
>> way to pass the mocked Context object to the MapDriver, but didnt find any
>> such methods exposed.
>> I am able to see that the context is getting mocked internally. Printing
>> the context gives me :
>>
>> Mock for Context, hashCode: 763970039
>>
>> But context.getTaskAttemptID returns null.
>>
>> I checked the source code, and if i understand it right,
>> MockMapContextWrapper should set the Context internally.
>>
>> Any help would be great.Thanks.
>>
>> Regards,
>> Sahana
>>
>>
>> On Thu, Sep 13, 2012 at 6:03 PM, Brock Noland <br...@cloudera.com> wrote:
>>
>> Could you share the code? Pastebin is a good place to post it.
>>
>> --
>> Brock Noland
>> Sent with Sparrow
>>
>> On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
>>
>> Hi,
>>
>> I am using Mockito along with MRUnit for unit testing mapreduce
>> programs.
>>
>> I am currently encountering a problem in the setup method of the Mapper.
>> The snippet of code i am trying to mock is :
>>
>> public void setup(Context context){
>>
>> /// code here
>>
>> //the below code gives me a null pointer although i have mocked the
>> Context class using mockito in my test method.
>> context.getTaskAttemptID.toString();
>>
>> }
>>
>> In the test method i have also set an expectation:
>>
>> when
>>
>> (context.getTaskAttemptID()).thenReturn(taskAttemptID);
>>
>> Any idea why the setup is returning a null TaskAttemptID? Is there any
>> other way to mock the Context class? What is the use of the mock package and
>> the corresponding classes in
>>
>> import org.apache.hadoop.mrunit.mapreduce.mock.*;
>>
>> Thanks in advance.
>>
>> Regards,
>> Sahana
>>
>>
>>
>>
>
--
Apache MRUnit - Unit testing MapReduce - http://incubator.apache.org/mrunit/
Re: Mocking Context in setup method of Mapper
Posted by Sahana Bhat <sa...@gmail.com>.
Hi,
I might be missing something here, but i dont see a getContext
method available in org.apache.hadoop.mrunit.mapreduce.MapDriver.
Can you direct me to a code snippet of the same?
Thanks,
Sahana
On Fri, Sep 14, 2012 at 6:04 PM, Brock Noland <br...@cloudera.com> wrote:
> Context is getting mocked internally, you should use the
> driver.getContext() to get access to the mocked context. You can then
> override any methods you wish.
>
> --
> Brock Noland
> Sent with Sparrow <http://www.sparrowmailapp.com/?sig>
>
> On Friday, September 14, 2012 at 1:09 AM, Sahana Bhat wrote:
>
>
> Hi,
>
> You can take a look at the snippet here :
> http://pastebin.com/NBfPBQhL
> I thought i needed to mock the Context using mockito, and there would be a
> way to pass the mocked Context object to the MapDriver, but didnt find any
> such methods exposed.
> I am able to see that the context is getting mocked internally. Printing
> the context gives me :
>
> Mock for Context, hashCode: 763970039
>
> But context.getTaskAttemptID returns null.
>
> I checked the source code, and if i understand it right,
> MockMapContextWrapper should set the Context internally.
>
> Any help would be great.Thanks.
>
> Regards,
> Sahana
>
> On Thu, Sep 13, 2012 at 6:03 PM, Brock Noland <br...@cloudera.com> wrote:
>
> Could you share the code? Pastebin is a good place to post it.
>
> --
> Brock Noland
> Sent with Sparrow <http://www.sparrowmailapp.com/?sig>
>
> On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
>
> Hi,
>
> I am using Mockito along with MRUnit for unit testing mapreduce
> programs.
>
> I am currently encountering a problem in the setup method of the Mapper.
> The snippet of code i am trying to mock is :
>
> public void setup(Context context){
>
> /// code here
>
> //the below code gives me a null pointer although i have mocked the
> Context class using mockito in my test method.
> context.getTaskAttemptID.toString();
>
> }
>
> In the test method i have also set an expectation:
> *
>
> when
> *(context.getTaskAttemptID()).thenReturn(taskAttemptID);
>
> Any idea why the setup is returning a null TaskAttemptID? Is there any
> other way to mock the Context class? What is the use of the mock package
> and the corresponding classes in **
>
> import *org.apache.hadoop.mrunit.mapreduce.mock*.*;
>
> Thanks in advance.
>
> Regards,
> Sahana
>
>
>
>
>
Re: Mocking Context in setup method of Mapper
Posted by Brock Noland <br...@cloudera.com>.
Context is getting mocked internally, you should use the driver.getContext() to get access to the mocked context. You can then override any methods you wish.
--
Brock Noland
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Friday, September 14, 2012 at 1:09 AM, Sahana Bhat wrote:
>
> Hi,
>
> You can take a look at the snippet here : http://pastebin.com/NBfPBQhL
> I thought i needed to mock the Context using mockito, and there would be a way to pass the mocked Context object to the MapDriver, but didnt find any such methods exposed.
> I am able to see that the context is getting mocked internally. Printing the context gives me :
> Mock for Context, hashCode: 763970039
> But context.getTaskAttemptID returns null.
> I checked the source code, and if i understand it right, MockMapContextWrapper should set the Context internally.
> Any help would be great.Thanks.
> Regards,
> Sahana
> On Thu, Sep 13, 2012 at 6:03 PM, Brock Noland <brock@cloudera.com (mailto:brock@cloudera.com)> wrote:
> > Could you share the code? Pastebin is a good place to post it.
> >
> > --
> > Brock Noland
> > Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> >
> >
> > On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
> >
> > > Hi,
> > >
> > > I am using Mockito along with MRUnit for unit testing mapreduce programs.
> > >
> > > I am currently encountering a problem in the setup method of the Mapper.
> > > The snippet of code i am trying to mock is :
> > >
> > > public void setup(Context context){
> > >
> > > /// code here
> > >
> > > //the below code gives me a null pointer although i have mocked the Context class using mockito in my test method.
> > > context.getTaskAttemptID.toString();
> > >
> > > }
> > >
> > > In the test method i have also set an expectation:
> > > when
> > > (context.getTaskAttemptID()).thenReturn(taskAttemptID);
> > > Any idea why the setup is returning a null TaskAttemptID? Is there any other way to mock the Context class? What is the use of the mock package and the corresponding classes in
> > > import org.apache.hadoop.mrunit.mapreduce.mock.*;
> > > Thanks in advance.
> > > Regards,
> > > Sahana
> >
>
Re: Mocking Context in setup method of Mapper
Posted by Sahana Bhat <sa...@gmail.com>.
Hi,
You can take a look at the snippet here :
http://pastebin.com/NBfPBQhL
I thought i needed to mock the Context using mockito, and there would be a
way to pass the mocked Context object to the MapDriver, but didnt find any
such methods exposed.
I am able to see that the context is getting mocked internally. Printing
the context gives me :
Mock for Context, hashCode: 763970039
But context.getTaskAttemptID returns null.
I checked the source code, and if i understand it right,
MockMapContextWrapper should set the Context internally.
Any help would be great.Thanks.
Regards,
Sahana
On Thu, Sep 13, 2012 at 6:03 PM, Brock Noland <br...@cloudera.com> wrote:
> Could you share the code? Pastebin is a good place to post it.
>
> --
> Brock Noland
> Sent with Sparrow <http://www.sparrowmailapp.com/?sig>
>
> On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
>
> Hi,
>
> I am using Mockito along with MRUnit for unit testing mapreduce
> programs.
>
> I am currently encountering a problem in the setup method of the Mapper.
> The snippet of code i am trying to mock is :
>
> public void setup(Context context){
>
> /// code here
>
> //the below code gives me a null pointer although i have mocked the
> Context class using mockito in my test method.
> context.getTaskAttemptID.toString();
>
> }
>
> In the test method i have also set an expectation:
> *
>
> when
> *(context.getTaskAttemptID()).thenReturn(taskAttemptID);
>
> Any idea why the setup is returning a null TaskAttemptID? Is there any
> other way to mock the Context class? What is the use of the mock package
> and the corresponding classes in **
>
> import *org.apache.hadoop.mrunit.mapreduce.mock*.*;
>
> Thanks in advance.
>
> Regards,
> Sahana
>
>
>
Re: Mocking Context in setup method of Mapper
Posted by Brock Noland <br...@cloudera.com>.
Could you share the code? Pastebin is a good place to post it.
--
Brock Noland
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Thursday, September 13, 2012 at 7:06 AM, Sahana Bhat wrote:
> Hi,
>
> I am using Mockito along with MRUnit for unit testing mapreduce programs.
>
> I am currently encountering a problem in the setup method of the Mapper.
> The snippet of code i am trying to mock is :
>
> public void setup(Context context){
>
> /// code here
>
> //the below code gives me a null pointer although i have mocked the Context class using mockito in my test method.
> context.getTaskAttemptID.toString();
>
> }
>
> In the test method i have also set an expectation:
> when
> (context.getTaskAttemptID()).thenReturn(taskAttemptID);
> Any idea why the setup is returning a null TaskAttemptID? Is there any other way to mock the Context class? What is the use of the mock package and the corresponding classes in
> import org.apache.hadoop.mrunit.mapreduce.mock.*;
> Thanks in advance.
> Regards,
> Sahana