You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@accumulo.apache.org by David Medinets <da...@gmail.com> on 2013/03/21 21:59:40 UTC

Using powermock-api-mockito in tests?

Is there any reason why I should not add a dependency in start/pom.xml
to powermock-api-mockito? With this library, we can mock the call to
System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest.
The two tests need these four lines of setup in order to pass:

      Map<String, String> mockSystemProperties = new HashMap<String, String>();
      mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));

      PowerMockito.mockStatic(System.class);
      Mockito.when(System.getenv()).thenReturn(mockSystemProperties);

You'll notice that set ACCUMULO_HOME is set to the value of HOME to
make the test cross-platform.

Re: Using powermock-api-mockito in tests?

Posted by David Medinets <da...@gmail.com>.
Thank you. Sometimes I get lost in the microscopic. Now I understand.

On Fri, Mar 22, 2013 at 6:48 PM, Dave Marion <dl...@comcast.net> wrote:
> David,
>
>   I was not trying to prevent you from being productive, I was trying to
> prevent you from wasting your time. I stated several times that
> MiniDFSCluster does not work on Windows. I'll try to be more specific.
>
>  After you mock the bash execution, you will likely find that you have
> broken the test for everyone else because MiniDFSCluster expects a certain
> directory permission, see [1] and [2] for lengthy discussions on the topic.
> In addition, when you get to the point of starting MiniDFSCluster, you will
> find that it does not work on Windows due to non-portable paths and such,
> see [3]. At that point you will be left with removing MiniDFSCluster and
> mocking every call to HDFS from the tests.
>
>   I think a better solution is to move the classloader tests that use
> AccumuloDFSBase to integration tests. These can be run on Hudson, which I
> think is using a *nix flavor of O/S and should run with no problem. Maybe a
> future version of MiniDFSCluster will work on Windows.
>
> [1] https://issues.apache.org/jira/browse/ACCUMULO-708
> [2]
> http://www.google.com/#hl=en&sclient=psy-ab&q=MiniDFSCluster+directory+permi
> ssions
> [3] http://www.google.com/#q=MiniDFSCluster+windows+paths&hl=en
>
>
> Dave
>
> -----Original Message-----
> From: David Medinets [mailto:david.medinets@gmail.com]
> Sent: Friday, March 22, 2013 5:43 PM
> To: dev@accumulo.apache.org
> Subject: Re: Using powermock-api-mockito in tests?
>
> How does it hurt the project if I spend time on this? Accumulo already
> compiles on Windows. It's the tests that are failing. How does skipping
> failing tests help? I suggest that unit tests should not spawn exec
> processes in any case because that is a source of slowness.
> Mocking the unix-specific stuff on Windows will lead to faster tests.
>
> On Fri, Mar 22, 2013 at 10:42 AM, Jim Klucar <kl...@gmail.com> wrote:
>> +1 to Dave's comment. I don't think we should be spending effort
>> +supporting
>> compiling on an unsupported runtime environment. If something fails
>> because it is too *nix-y then just skip that test with a local pom.xml
>> override or something.
>>
>>
>> On Fri, Mar 22, 2013 at 10:11 AM, Keith Turner <ke...@deenlo.com> wrote:
>>
>>> On Thu, Mar 21, 2013 at 10:16 PM,  <dl...@comcast.net> wrote:
>>> >
>>> > So we are getting into an area where you want to compile the
>>> > software on
>>> a platform that is not supported. If you want to compile on an
>>> unsupported platform, then I would suggest just ignoring the tests
>>> that won't work on that system.
>>>
>>> My thought on this is that if changes to make it work on windows
>>> improve the test and/or build process, then thats good.  On the other
>>> hand I would be opposed to making test and/or build more complex
>>> inorder to support windows.   I would define increasing complexity as
>>> making it more difficult to run, maintain, or improve the test and/or
>>> build process.
>>>
>>> >
>>> > I don't think that this needs to be changed now as Hadoop only
>>> > supports
>>> *nix based systems and we are close to a 1.5.0 release. If you want
>>> to tackle this in 1.6 (trunk) thats a different story.
>>> >
>>> >
>>> > ----- Original Message -----
>>> > From: "David Medinets" <da...@gmail.com>
>>> > To: dev@accumulo.apache.org
>>> > Sent: Thursday, March 21, 2013 10:08:48 PM
>>> > Subject: Re: Using powermock-api-mockito in tests?
>>> >
>>> > I hate ignoring things. It makes me uneasy. I'm looking at the
>>> > other tests as well. For example, the AccumuloDFSBase class depends
>>> > on running /bin/sh to find a umask. No reason that dependency can't
>>> > be mocked out during testing... If nothing else, this research will
>>> > form my own set of Accumulo Zen Koans.
>>> >
>>> > On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote:
>>> >>
>>> >> Take a look at my other email on this subject, it might be better
>>> >> to
>>> just add the profile that I mentioned and add this to the list of
>>> ignored tests for now. I know that there is a ticket for removing
>>> ACCUMULO_HOME in all places.
>>> >>
>>> >> ----- Original Message -----
>>> >> From: "David Medinets" <da...@gmail.com>
>>> >> To: dev@accumulo.apache.org
>>> >> Sent: Thursday, March 21, 2013 9:58:18 PM
>>> >> Subject: Re: Using powermock-api-mockito in tests?
>>> >>
>>> >> Dave, you were very close. Here is the mocking code that I used.
>>> >>
>>> >> Map<String, String> mockSystemProperties = new HashMap<String,
>>> String>();
>>> >> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>>> >>
>>> >> PowerMock.mockStaticPartial(System.class, "getenv");
>>> >>
>>> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyT
>>> imes();
>>> >>
>>> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").any
>>> Times();
>>> >> PowerMock.replayAll();
>>> >>
>>> >> I'd like write a JIRA ticket and commit this code. I'll wait until
>>> >> tomorrow for feedback though. No rush for this kind of change.
>>> >>
>>> >> The message that started this investigation was:
>>> >>
>>> >>
>>>
> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClass
> LoaderTest):
>>> >> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
>>> >> relative path, and no base URI was provided.
>>> >>
>>> >> It occured on line 135 of AccumuloVFSClassLoader.java because
>>> >> ACCUMULO_HOME was blank and therefore no base URI was provided.
>>>
>

RE: Using powermock-api-mockito in tests?

Posted by Dave Marion <dl...@comcast.net>.
David,

  I was not trying to prevent you from being productive, I was trying to
prevent you from wasting your time. I stated several times that
MiniDFSCluster does not work on Windows. I'll try to be more specific.

 After you mock the bash execution, you will likely find that you have
broken the test for everyone else because MiniDFSCluster expects a certain
directory permission, see [1] and [2] for lengthy discussions on the topic.
In addition, when you get to the point of starting MiniDFSCluster, you will
find that it does not work on Windows due to non-portable paths and such,
see [3]. At that point you will be left with removing MiniDFSCluster and
mocking every call to HDFS from the tests.

  I think a better solution is to move the classloader tests that use
AccumuloDFSBase to integration tests. These can be run on Hudson, which I
think is using a *nix flavor of O/S and should run with no problem. Maybe a
future version of MiniDFSCluster will work on Windows.

[1] https://issues.apache.org/jira/browse/ACCUMULO-708
[2]
http://www.google.com/#hl=en&sclient=psy-ab&q=MiniDFSCluster+directory+permi
ssions
[3] http://www.google.com/#q=MiniDFSCluster+windows+paths&hl=en


Dave

-----Original Message-----
From: David Medinets [mailto:david.medinets@gmail.com] 
Sent: Friday, March 22, 2013 5:43 PM
To: dev@accumulo.apache.org
Subject: Re: Using powermock-api-mockito in tests?

How does it hurt the project if I spend time on this? Accumulo already
compiles on Windows. It's the tests that are failing. How does skipping
failing tests help? I suggest that unit tests should not spawn exec
processes in any case because that is a source of slowness.
Mocking the unix-specific stuff on Windows will lead to faster tests.

On Fri, Mar 22, 2013 at 10:42 AM, Jim Klucar <kl...@gmail.com> wrote:
> +1 to Dave's comment. I don't think we should be spending effort 
> +supporting
> compiling on an unsupported runtime environment. If something fails 
> because it is too *nix-y then just skip that test with a local pom.xml 
> override or something.
>
>
> On Fri, Mar 22, 2013 at 10:11 AM, Keith Turner <ke...@deenlo.com> wrote:
>
>> On Thu, Mar 21, 2013 at 10:16 PM,  <dl...@comcast.net> wrote:
>> >
>> > So we are getting into an area where you want to compile the 
>> > software on
>> a platform that is not supported. If you want to compile on an 
>> unsupported platform, then I would suggest just ignoring the tests 
>> that won't work on that system.
>>
>> My thought on this is that if changes to make it work on windows 
>> improve the test and/or build process, then thats good.  On the other 
>> hand I would be opposed to making test and/or build more complex
>> inorder to support windows.   I would define increasing complexity as
>> making it more difficult to run, maintain, or improve the test and/or 
>> build process.
>>
>> >
>> > I don't think that this needs to be changed now as Hadoop only 
>> > supports
>> *nix based systems and we are close to a 1.5.0 release. If you want 
>> to tackle this in 1.6 (trunk) thats a different story.
>> >
>> >
>> > ----- Original Message -----
>> > From: "David Medinets" <da...@gmail.com>
>> > To: dev@accumulo.apache.org
>> > Sent: Thursday, March 21, 2013 10:08:48 PM
>> > Subject: Re: Using powermock-api-mockito in tests?
>> >
>> > I hate ignoring things. It makes me uneasy. I'm looking at the 
>> > other tests as well. For example, the AccumuloDFSBase class depends 
>> > on running /bin/sh to find a umask. No reason that dependency can't 
>> > be mocked out during testing... If nothing else, this research will 
>> > form my own set of Accumulo Zen Koans.
>> >
>> > On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote:
>> >>
>> >> Take a look at my other email on this subject, it might be better 
>> >> to
>> just add the profile that I mentioned and add this to the list of 
>> ignored tests for now. I know that there is a ticket for removing 
>> ACCUMULO_HOME in all places.
>> >>
>> >> ----- Original Message -----
>> >> From: "David Medinets" <da...@gmail.com>
>> >> To: dev@accumulo.apache.org
>> >> Sent: Thursday, March 21, 2013 9:58:18 PM
>> >> Subject: Re: Using powermock-api-mockito in tests?
>> >>
>> >> Dave, you were very close. Here is the mocking code that I used.
>> >>
>> >> Map<String, String> mockSystemProperties = new HashMap<String,
>> String>();
>> >> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>> >>
>> >> PowerMock.mockStaticPartial(System.class, "getenv");
>> >>
>> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyT
>> imes();
>> >>
>> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").any
>> Times();
>> >> PowerMock.replayAll();
>> >>
>> >> I'd like write a JIRA ticket and commit this code. I'll wait until 
>> >> tomorrow for feedback though. No rush for this kind of change.
>> >>
>> >> The message that started this investigation was:
>> >>
>> >>
>>
testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClass
LoaderTest):
>> >> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a 
>> >> relative path, and no base URI was provided.
>> >>
>> >> It occured on line 135 of AccumuloVFSClassLoader.java because 
>> >> ACCUMULO_HOME was blank and therefore no base URI was provided.
>>


Re: Using powermock-api-mockito in tests?

Posted by David Medinets <da...@gmail.com>.
How does it hurt the project if I spend time on this? Accumulo already
compiles on Windows. It's the tests that are failing. How does
skipping failing tests help? I suggest that unit tests should not
spawn exec processes in any case because that is a source of slowness.
Mocking the unix-specific stuff on Windows will lead to faster tests.

On Fri, Mar 22, 2013 at 10:42 AM, Jim Klucar <kl...@gmail.com> wrote:
> +1 to Dave's comment. I don't think we should be spending effort supporting
> compiling on an unsupported runtime environment. If something fails because
> it is too *nix-y then just skip that test with a local pom.xml override or
> something.
>
>
> On Fri, Mar 22, 2013 at 10:11 AM, Keith Turner <ke...@deenlo.com> wrote:
>
>> On Thu, Mar 21, 2013 at 10:16 PM,  <dl...@comcast.net> wrote:
>> >
>> > So we are getting into an area where you want to compile the software on
>> a platform that is not supported. If you want to compile on an unsupported
>> platform, then I would suggest just ignoring the tests that won't work on
>> that system.
>>
>> My thought on this is that if changes to make it work on windows
>> improve the test and/or build process, then thats good.  On the other
>> hand I would be opposed to making test and/or build more complex
>> inorder to support windows.   I would define increasing complexity as
>> making it more difficult to run, maintain, or improve the test and/or
>> build process.
>>
>> >
>> > I don't think that this needs to be changed now as Hadoop only supports
>> *nix based systems and we are close to a 1.5.0 release. If you want to
>> tackle this in 1.6 (trunk) thats a different story.
>> >
>> >
>> > ----- Original Message -----
>> > From: "David Medinets" <da...@gmail.com>
>> > To: dev@accumulo.apache.org
>> > Sent: Thursday, March 21, 2013 10:08:48 PM
>> > Subject: Re: Using powermock-api-mockito in tests?
>> >
>> > I hate ignoring things. It makes me uneasy. I'm looking at the other
>> > tests as well. For example, the AccumuloDFSBase class depends on
>> > running /bin/sh to find a umask. No reason that dependency can't be
>> > mocked out during testing... If nothing else, this research will form
>> > my own set of Accumulo Zen Koans.
>> >
>> > On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote:
>> >>
>> >> Take a look at my other email on this subject, it might be better to
>> just add the profile that I mentioned and add this to the list of ignored
>> tests for now. I know that there is a ticket for removing ACCUMULO_HOME in
>> all places.
>> >>
>> >> ----- Original Message -----
>> >> From: "David Medinets" <da...@gmail.com>
>> >> To: dev@accumulo.apache.org
>> >> Sent: Thursday, March 21, 2013 9:58:18 PM
>> >> Subject: Re: Using powermock-api-mockito in tests?
>> >>
>> >> Dave, you were very close. Here is the mocking code that I used.
>> >>
>> >> Map<String, String> mockSystemProperties = new HashMap<String,
>> String>();
>> >> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>> >>
>> >> PowerMock.mockStaticPartial(System.class, "getenv");
>> >>
>> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes();
>> >>
>> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes();
>> >> PowerMock.replayAll();
>> >>
>> >> I'd like write a JIRA ticket and commit this code. I'll wait until
>> >> tomorrow for feedback though. No rush for this kind of change.
>> >>
>> >> The message that started this investigation was:
>> >>
>> >>
>> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest):
>> >> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
>> >> relative path, and no base URI was provided.
>> >>
>> >> It occured on line 135 of AccumuloVFSClassLoader.java because
>> >> ACCUMULO_HOME was blank and therefore no base URI was provided.
>>

Re: Using powermock-api-mockito in tests?

Posted by Jim Klucar <kl...@gmail.com>.
+1 to Dave's comment. I don't think we should be spending effort supporting
compiling on an unsupported runtime environment. If something fails because
it is too *nix-y then just skip that test with a local pom.xml override or
something.


On Fri, Mar 22, 2013 at 10:11 AM, Keith Turner <ke...@deenlo.com> wrote:

> On Thu, Mar 21, 2013 at 10:16 PM,  <dl...@comcast.net> wrote:
> >
> > So we are getting into an area where you want to compile the software on
> a platform that is not supported. If you want to compile on an unsupported
> platform, then I would suggest just ignoring the tests that won't work on
> that system.
>
> My thought on this is that if changes to make it work on windows
> improve the test and/or build process, then thats good.  On the other
> hand I would be opposed to making test and/or build more complex
> inorder to support windows.   I would define increasing complexity as
> making it more difficult to run, maintain, or improve the test and/or
> build process.
>
> >
> > I don't think that this needs to be changed now as Hadoop only supports
> *nix based systems and we are close to a 1.5.0 release. If you want to
> tackle this in 1.6 (trunk) thats a different story.
> >
> >
> > ----- Original Message -----
> > From: "David Medinets" <da...@gmail.com>
> > To: dev@accumulo.apache.org
> > Sent: Thursday, March 21, 2013 10:08:48 PM
> > Subject: Re: Using powermock-api-mockito in tests?
> >
> > I hate ignoring things. It makes me uneasy. I'm looking at the other
> > tests as well. For example, the AccumuloDFSBase class depends on
> > running /bin/sh to find a umask. No reason that dependency can't be
> > mocked out during testing... If nothing else, this research will form
> > my own set of Accumulo Zen Koans.
> >
> > On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote:
> >>
> >> Take a look at my other email on this subject, it might be better to
> just add the profile that I mentioned and add this to the list of ignored
> tests for now. I know that there is a ticket for removing ACCUMULO_HOME in
> all places.
> >>
> >> ----- Original Message -----
> >> From: "David Medinets" <da...@gmail.com>
> >> To: dev@accumulo.apache.org
> >> Sent: Thursday, March 21, 2013 9:58:18 PM
> >> Subject: Re: Using powermock-api-mockito in tests?
> >>
> >> Dave, you were very close. Here is the mocking code that I used.
> >>
> >> Map<String, String> mockSystemProperties = new HashMap<String,
> String>();
> >> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
> >>
> >> PowerMock.mockStaticPartial(System.class, "getenv");
> >>
> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes();
> >>
> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes();
> >> PowerMock.replayAll();
> >>
> >> I'd like write a JIRA ticket and commit this code. I'll wait until
> >> tomorrow for feedback though. No rush for this kind of change.
> >>
> >> The message that started this investigation was:
> >>
> >>
> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest):
> >> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
> >> relative path, and no base URI was provided.
> >>
> >> It occured on line 135 of AccumuloVFSClassLoader.java because
> >> ACCUMULO_HOME was blank and therefore no base URI was provided.
>

Re: Using powermock-api-mockito in tests?

Posted by Keith Turner <ke...@deenlo.com>.
On Thu, Mar 21, 2013 at 10:16 PM,  <dl...@comcast.net> wrote:
>
> So we are getting into an area where you want to compile the software on a platform that is not supported. If you want to compile on an unsupported platform, then I would suggest just ignoring the tests that won't work on that system.

My thought on this is that if changes to make it work on windows
improve the test and/or build process, then thats good.  On the other
hand I would be opposed to making test and/or build more complex
inorder to support windows.   I would define increasing complexity as
making it more difficult to run, maintain, or improve the test and/or
build process.

>
> I don't think that this needs to be changed now as Hadoop only supports *nix based systems and we are close to a 1.5.0 release. If you want to tackle this in 1.6 (trunk) thats a different story.
>
>
> ----- Original Message -----
> From: "David Medinets" <da...@gmail.com>
> To: dev@accumulo.apache.org
> Sent: Thursday, March 21, 2013 10:08:48 PM
> Subject: Re: Using powermock-api-mockito in tests?
>
> I hate ignoring things. It makes me uneasy. I'm looking at the other
> tests as well. For example, the AccumuloDFSBase class depends on
> running /bin/sh to find a umask. No reason that dependency can't be
> mocked out during testing... If nothing else, this research will form
> my own set of Accumulo Zen Koans.
>
> On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote:
>>
>> Take a look at my other email on this subject, it might be better to just add the profile that I mentioned and add this to the list of ignored tests for now. I know that there is a ticket for removing ACCUMULO_HOME in all places.
>>
>> ----- Original Message -----
>> From: "David Medinets" <da...@gmail.com>
>> To: dev@accumulo.apache.org
>> Sent: Thursday, March 21, 2013 9:58:18 PM
>> Subject: Re: Using powermock-api-mockito in tests?
>>
>> Dave, you were very close. Here is the mocking code that I used.
>>
>> Map<String, String> mockSystemProperties = new HashMap<String, String>();
>> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>>
>> PowerMock.mockStaticPartial(System.class, "getenv");
>> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes();
>> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes();
>> PowerMock.replayAll();
>>
>> I'd like write a JIRA ticket and commit this code. I'll wait until
>> tomorrow for feedback though. No rush for this kind of change.
>>
>> The message that started this investigation was:
>>
>> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest):
>> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
>> relative path, and no base URI was provided.
>>
>> It occured on line 135 of AccumuloVFSClassLoader.java because
>> ACCUMULO_HOME was blank and therefore no base URI was provided.

Re: Using powermock-api-mockito in tests?

Posted by dl...@comcast.net.
So we are getting into an area where you want to compile the software on a platform that is not supported. If you want to compile on an unsupported platform, then I would suggest just ignoring the tests that won't work on that system. 

I don't think that this needs to be changed now as Hadoop only supports *nix based systems and we are close to a 1.5.0 release. If you want to tackle this in 1.6 (trunk) thats a different story. 


----- Original Message -----
From: "David Medinets" <da...@gmail.com> 
To: dev@accumulo.apache.org 
Sent: Thursday, March 21, 2013 10:08:48 PM 
Subject: Re: Using powermock-api-mockito in tests? 

I hate ignoring things. It makes me uneasy. I'm looking at the other 
tests as well. For example, the AccumuloDFSBase class depends on 
running /bin/sh to find a umask. No reason that dependency can't be 
mocked out during testing... If nothing else, this research will form 
my own set of Accumulo Zen Koans. 

On Thu, Mar 21, 2013 at 10:03 PM, <dl...@comcast.net> wrote: 
> 
> Take a look at my other email on this subject, it might be better to just add the profile that I mentioned and add this to the list of ignored tests for now. I know that there is a ticket for removing ACCUMULO_HOME in all places. 
> 
> ----- Original Message ----- 
> From: "David Medinets" <da...@gmail.com> 
> To: dev@accumulo.apache.org 
> Sent: Thursday, March 21, 2013 9:58:18 PM 
> Subject: Re: Using powermock-api-mockito in tests? 
> 
> Dave, you were very close. Here is the mocking code that I used. 
> 
> Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 
> 
> PowerMock.mockStaticPartial(System.class, "getenv"); 
> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes(); 
> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes(); 
> PowerMock.replayAll(); 
> 
> I'd like write a JIRA ticket and commit this code. I'll wait until 
> tomorrow for feedback though. No rush for this kind of change. 
> 
> The message that started this investigation was: 
> 
> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest): 
> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a 
> relative path, and no base URI was provided. 
> 
> It occured on line 135 of AccumuloVFSClassLoader.java because 
> ACCUMULO_HOME was blank and therefore no base URI was provided. 

Re: Using powermock-api-mockito in tests?

Posted by David Medinets <da...@gmail.com>.
I hate ignoring things. It makes me uneasy. I'm looking at the other
tests as well. For example, the AccumuloDFSBase class depends on
running /bin/sh to find a umask. No reason that dependency can't be
mocked out during testing... If nothing else, this research will form
my own set of Accumulo Zen Koans.

On Thu, Mar 21, 2013 at 10:03 PM,  <dl...@comcast.net> wrote:
>
> Take a look at my other email on this subject, it might be better to just add the profile that I mentioned and add this to the list of ignored tests for now. I know that there is a ticket for removing ACCUMULO_HOME in all places.
>
> ----- Original Message -----
> From: "David Medinets" <da...@gmail.com>
> To: dev@accumulo.apache.org
> Sent: Thursday, March 21, 2013 9:58:18 PM
> Subject: Re: Using powermock-api-mockito in tests?
>
> Dave, you were very close. Here is the mocking code that I used.
>
> Map<String, String> mockSystemProperties = new HashMap<String, String>();
> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>
> PowerMock.mockStaticPartial(System.class, "getenv");
> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes();
> EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes();
> PowerMock.replayAll();
>
> I'd like write a JIRA ticket and commit this code. I'll wait until
> tomorrow for feedback though. No rush for this kind of change.
>
> The message that started this investigation was:
>
> testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest):
> Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
> relative path, and no base URI was provided.
>
> It occured on line 135 of AccumuloVFSClassLoader.java because
> ACCUMULO_HOME was blank and therefore no base URI was provided.

Re: Using powermock-api-mockito in tests?

Posted by dl...@comcast.net.
Take a look at my other email on this subject, it might be better to just add the profile that I mentioned and add this to the list of ignored tests for now. I know that there is a ticket for removing ACCUMULO_HOME in all places. 

----- Original Message -----
From: "David Medinets" <da...@gmail.com> 
To: dev@accumulo.apache.org 
Sent: Thursday, March 21, 2013 9:58:18 PM 
Subject: Re: Using powermock-api-mockito in tests? 

Dave, you were very close. Here is the mocking code that I used. 

Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 

PowerMock.mockStaticPartial(System.class, "getenv"); 
EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes(); 
EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes(); 
PowerMock.replayAll(); 

I'd like write a JIRA ticket and commit this code. I'll wait until 
tomorrow for feedback though. No rush for this kind of change. 

The message that started this investigation was: 

testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest): 
Could not find file with URI "/lib/ext/[^.].*.jar" because it is a 
relative path, and no base URI was provided. 

It occured on line 135 of AccumuloVFSClassLoader.java because 
ACCUMULO_HOME was blank and therefore no base URI was provided. 

Re: Using powermock-api-mockito in tests?

Posted by David Medinets <da...@gmail.com>.
Dave, you were very close. Here is the mocking code that I used.

      Map<String, String> mockSystemProperties = new HashMap<String, String>();
      mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));

      PowerMock.mockStaticPartial(System.class, "getenv");
      EasyMock.expect(System.getenv()).andReturn(mockSystemProperties).anyTimes();
      EasyMock.expect(System.getenv("ACCUMULO_XTRAJARS")).andReturn("").anyTimes();
      PowerMock.replayAll();

I'd like write a JIRA ticket and commit this code. I'll wait until
tomorrow for feedback though. No rush for this kind of change.

The message that started this investigation was:

testDefaultConfig(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest):
Could not find file with URI "/lib/ext/[^.].*.jar" because it is a
relative path, and no base URI was provided.

It occured on line 135 of AccumuloVFSClassLoader.java because
ACCUMULO_HOME was blank and therefore no base URI was provided.

Re: Using powermock-api-mockito in tests?

Posted by dl...@comcast.net.
I'm not seeing where. Do you have a stack trace? 

----- Original Message -----
From: "David Medinets" <da...@gmail.com> 
To: dev@accumulo.apache.org 
Sent: Thursday, March 21, 2013 9:26:25 PM 
Subject: Re: Using powermock-api-mockito in tests? 

The AccumuloVFSClassLoaderTest tests require ACCUMULO_HOME to be 
defined. It is not defined on my Windows computer. Therefore, the 
tests failed. I argue that a unit test should be independent of the 
underlying system otherwise it is some kind of integration or 
functional test. And in this case, mocking the System.getenv() call 
should be easy to do. 

On Thu, Mar 21, 2013 at 6:40 PM, Dave Marion <dl...@comcast.net> wrote: 
> Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now? 

Re: Using powermock-api-mockito in tests?

Posted by David Medinets <da...@gmail.com>.
The AccumuloVFSClassLoaderTest tests require ACCUMULO_HOME to be
defined. It is not defined on my Windows computer. Therefore, the
tests failed. I argue that a unit test should be independent of the
underlying system otherwise it is some kind of integration or
functional test. And in this case, mocking the System.getenv() call
should be easy to do.

On Thu, Mar 21, 2013 at 6:40 PM, Dave Marion <dl...@comcast.net> wrote:
> Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now?

Re: Using powermock-api-mockito in tests?

Posted by dl...@comcast.net.
I do think that the tests that use the MiniDFSCluster (anything that uses AccumuloDFSBase) will fail on Windows. I had to use the following profile in the commons vfs package. Of course the test names will be different here... 

<profile> 
<id>hdfs</id> 
<activation> 
<activeByDefault>false</activeByDefault> 
<os> 
<family>Windows</family> 
</os> 
</activation> 
<build> 
<plugins> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-surefire-plugin</artifactId> 
<configuration> 
<excludes> 
<exclude>**/HdfsFileProviderTest.java</exclude> 
<exclude>**/HdfsFileProviderTestCase.java</exclude> 
</excludes> 
</configuration> 
</plugin> 
</plugins> 
</build> 
</profile> 


----- Original Message -----
From: "Dave Marion" <dl...@comcast.net> 
To: dev@accumulo.apache.org 
Sent: Thursday, March 21, 2013 7:11:11 PM 
Subject: RE: Using powermock-api-mockito in tests? 


The Hadoop MiniDFSCluster won't work on Windoze. He'll have to exclude most of the new classloader tests from running on that platform. 

-----Original Message----- 
From: Josh Elser [mailto:josh.elser@gmail.com] 
Sent: Thursday, March 21, 2013 6:44 PM 
To: dev@accumulo.apache.org 
Subject: Re: Using powermock-api-mockito in tests? 

David is trying to build on Windows. 

On 03/21/2013 06:40 PM, Dave Marion wrote: 
> Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now? 
> 
> -- Dave 
> 
> -----Original Message----- 
> From: dlmarion@comcast.net [mailto:dlmarion@comcast.net] 
> Sent: Thursday, March 21, 2013 5:12 PM 
> To: dev@accumulo.apache.org 
> Subject: Re: Using powermock-api-mockito in tests? 
> 
> 
> 
> We can do it with PowerMock, no need to add Mockito. This should work, going from memory here. I should be able to help when I get back to a computer if you have problems. 
> 
> 
> 
> //Mock the method 
> 
> PowerMock.mockStatic(System.class, System.class.getMethod("getenv")); 
> 
> 
> 
> //Invoke it 
> 
> Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 
> EasyMock.expect(System.getenv()).andReturn(mockSystemProperties); 
> 
> 
> 
> ----- Original Message ----- 
> 
> 
> From: "David Medinets" <da...@gmail.com> 
> To: "accumulo-dev" <de...@accumulo.apache.org> 
> Sent: Thursday, March 21, 2013 4:59:40 PM 
> Subject: Using powermock-api-mockito in tests? 
> 
> Is there any reason why I should not add a dependency in start/pom.xml to powermock-api-mockito? With this library, we can mock the call to 
> System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest. 
> The two tests need these four lines of setup in order to pass: 
> 
> Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
> mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 
> 
> PowerMockito.mockStatic(System.class); 
> Mockito.when(System.getenv()).thenReturn(mockSystemProperties); 
> 
> You'll notice that set ACCUMULO_HOME is set to the value of HOME to make the test cross-platform. 
> 


RE: Using powermock-api-mockito in tests?

Posted by Dave Marion <dl...@comcast.net>.
 The Hadoop MiniDFSCluster won't work on Windoze. He'll have to exclude most of the new classloader tests from running on that platform. 

-----Original Message-----
From: Josh Elser [mailto:josh.elser@gmail.com] 
Sent: Thursday, March 21, 2013 6:44 PM
To: dev@accumulo.apache.org
Subject: Re: Using powermock-api-mockito in tests?

David is trying to build on Windows.

On 03/21/2013 06:40 PM, Dave Marion wrote:
> Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now?
>
> -- Dave
>
> -----Original Message-----
> From: dlmarion@comcast.net [mailto:dlmarion@comcast.net]
> Sent: Thursday, March 21, 2013 5:12 PM
> To: dev@accumulo.apache.org
> Subject: Re: Using powermock-api-mockito in tests?
>
>
>
> We can do it with PowerMock, no need to add  Mockito. This should work, going from memory here. I should be able to help when I get back to a computer if you have problems.
>
>
>
>    //Mock the method
>
>    PowerMock.mockStatic(System.class, System.class.getMethod("getenv"));
>
>
>
>    //Invoke it
>
>    Map<String, String> mockSystemProperties = new HashMap<String, String>();
>    mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>    EasyMock.expect(System.getenv()).andReturn(mockSystemProperties);
>
>
>
> ----- Original Message -----
>
>
> From: "David Medinets" <da...@gmail.com>
> To: "accumulo-dev" <de...@accumulo.apache.org>
> Sent: Thursday, March 21, 2013 4:59:40 PM
> Subject: Using powermock-api-mockito in tests?
>
> Is there any reason why I should not add a dependency in start/pom.xml to powermock-api-mockito? With this library, we can mock the call to
> System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest.
> The two tests need these four lines of setup in order to pass:
>
>        Map<String, String> mockSystemProperties = new HashMap<String, String>();
>        mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>
>        PowerMockito.mockStatic(System.class);
>        Mockito.when(System.getenv()).thenReturn(mockSystemProperties);
>
> You'll notice that set ACCUMULO_HOME is set to the value of HOME to make the test cross-platform.
>


Re: Using powermock-api-mockito in tests?

Posted by Josh Elser <jo...@gmail.com>.
David is trying to build on Windows.

On 03/21/2013 06:40 PM, Dave Marion wrote:
> Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now?
>
> -- Dave
>
> -----Original Message-----
> From: dlmarion@comcast.net [mailto:dlmarion@comcast.net]
> Sent: Thursday, March 21, 2013 5:12 PM
> To: dev@accumulo.apache.org
> Subject: Re: Using powermock-api-mockito in tests?
>
>
>
> We can do it with PowerMock, no need to add  Mockito. This should work, going from memory here. I should be able to help when I get back to a computer if you have problems.
>
>
>
>    //Mock the method
>
>    PowerMock.mockStatic(System.class, System.class.getMethod("getenv"));
>
>
>
>    //Invoke it
>
>    Map<String, String> mockSystemProperties = new HashMap<String, String>();
>    mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>    EasyMock.expect(System.getenv()).andReturn(mockSystemProperties);
>
>
>
> ----- Original Message -----
>
>
> From: "David Medinets" <da...@gmail.com>
> To: "accumulo-dev" <de...@accumulo.apache.org>
> Sent: Thursday, March 21, 2013 4:59:40 PM
> Subject: Using powermock-api-mockito in tests?
>
> Is there any reason why I should not add a dependency in start/pom.xml to powermock-api-mockito? With this library, we can mock the call to
> System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest.
> The two tests need these four lines of setup in order to pass:
>
>        Map<String, String> mockSystemProperties = new HashMap<String, String>();
>        mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
>
>        PowerMockito.mockStatic(System.class);
>        Mockito.when(System.getenv()).thenReturn(mockSystemProperties);
>
> You'll notice that set ACCUMULO_HOME is set to the value of HOME to make the test cross-platform.
>


RE: Using powermock-api-mockito in tests?

Posted by Dave Marion <dl...@comcast.net>.
Out of curiosity, why do you say that " System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest?" It's worked fine for a while. What is different now?

-- Dave

-----Original Message-----
From: dlmarion@comcast.net [mailto:dlmarion@comcast.net] 
Sent: Thursday, March 21, 2013 5:12 PM
To: dev@accumulo.apache.org
Subject: Re: Using powermock-api-mockito in tests?



We can do it with PowerMock, no need to add  Mockito. This should work, going from memory here. I should be able to help when I get back to a computer if you have problems. 



  //Mock the method 

  PowerMock.mockStatic(System.class, System.class.getMethod("getenv")); 



  //Invoke it 

  Map<String, String> mockSystemProperties = new HashMap<String, String>();
  mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME"));
  EasyMock.expect(System.getenv()).andReturn(mockSystemProperties); 



----- Original Message -----


From: "David Medinets" <da...@gmail.com>
To: "accumulo-dev" <de...@accumulo.apache.org>
Sent: Thursday, March 21, 2013 4:59:40 PM
Subject: Using powermock-api-mockito in tests? 

Is there any reason why I should not add a dependency in start/pom.xml to powermock-api-mockito? With this library, we can mock the call to
System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest. 
The two tests need these four lines of setup in order to pass: 

      Map<String, String> mockSystemProperties = new HashMap<String, String>();
      mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 

      PowerMockito.mockStatic(System.class);
      Mockito.when(System.getenv()).thenReturn(mockSystemProperties); 

You'll notice that set ACCUMULO_HOME is set to the value of HOME to make the test cross-platform. 


Re: Using powermock-api-mockito in tests?

Posted by dl...@comcast.net.

We can do it with PowerMock, no need to add  Mockito. This should work, going from memory here. I should be able to help when I get back to a computer if you have problems. 



  //Mock the method 

  PowerMock.mockStatic(System.class, System.class.getMethod("getenv")); 



  //Invoke it 

  Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
  mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 
  EasyMock.expect(System.getenv()).andReturn(mockSystemProperties); 



----- Original Message -----


From: "David Medinets" <da...@gmail.com> 
To: "accumulo-dev" <de...@accumulo.apache.org> 
Sent: Thursday, March 21, 2013 4:59:40 PM 
Subject: Using powermock-api-mockito in tests? 

Is there any reason why I should not add a dependency in start/pom.xml 
to powermock-api-mockito? With this library, we can mock the call to 
System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest. 
The two tests need these four lines of setup in order to pass: 

      Map<String, String> mockSystemProperties = new HashMap<String, String>(); 
      mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 

      PowerMockito.mockStatic(System.class); 
      Mockito.when(System.getenv()).thenReturn(mockSystemProperties); 

You'll notice that set ACCUMULO_HOME is set to the value of HOME to 
make the test cross-platform.