You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by David Hoffer <dh...@gmail.com> on 2009/09/03 22:15:25 UTC

maven-surefire-plugin forkMode question

How does forking work with respect to the @BeforeClass/@AfterClass methods?
My use case is that I have some setup code that creates file/db connections
that are not destroyed until the jvm is shutdown, therefore I can't cleanup
in the @After method.  However it doesn't work using
@BeforeClass/@AfterClass either and I'm clear why.

I tried using all the fork modes with no success.  What's the way to run
tests in one process and then cleanup in another?

Re: maven-surefire-plugin forkMode question

Posted by David Hoffer <dh...@gmail.com>.
Using the clean plugin does seem much better but I could not find any docs
on how to drop a folder only files in a folder.

-Dave

On Fri, Sep 4, 2009 at 7:44 AM, Brett Porter <br...@apache.org> wrote:

>
>
> On 04/09/2009, at 11:33 PM, David Hoffer wrote:
>
>  Do you know of a way, using gmaven, to drop a folder containing files
>> and/or
>> subfolders?  Currently I consider my solution to be a hack because its bad
>> enough that the logic of what to cleanup is not in the test case source
>> file, but when I have to manually specify each and every file to delete
>> it's
>> a hack.  This will never stay in sync over time.
>>
>> If I could put all my temp test files/folders in a folder called 'tmp' and
>> then just drop 'tmp' using gmaven that's less of a hack.
>>
>>
> I think you'd be better off configuring an instance of the clean plugin
> instead of gmaven if all you want to do is delete a directory. It can take
> an arbitrary set of files / directories to clean.
>
>  You are right on the lifecyle, I forgot that I had set a phase...I'll
>> change
>> it to 'test'.  I always get confused on this issue...do plugins ALWAYS run
>> AFTER the phase they are attached to?
>>
>
> No, they run in that phase, but are added after any already specified (so
> after anything built in).
>
>
> - Brett
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: maven-surefire-plugin forkMode question

Posted by Brett Porter <br...@apache.org>.

On 04/09/2009, at 11:33 PM, David Hoffer wrote:

> Do you know of a way, using gmaven, to drop a folder containing  
> files and/or
> subfolders?  Currently I consider my solution to be a hack because  
> its bad
> enough that the logic of what to cleanup is not in the test case  
> source
> file, but when I have to manually specify each and every file to  
> delete it's
> a hack.  This will never stay in sync over time.
>
> If I could put all my temp test files/folders in a folder called  
> 'tmp' and
> then just drop 'tmp' using gmaven that's less of a hack.
>

I think you'd be better off configuring an instance of the clean  
plugin instead of gmaven if all you want to do is delete a directory.  
It can take an arbitrary set of files / directories to clean.

> You are right on the lifecyle, I forgot that I had set a  
> phase...I'll change
> it to 'test'.  I always get confused on this issue...do plugins  
> ALWAYS run
> AFTER the phase they are attached to?

No, they run in that phase, but are added after any already specified  
(so after anything built in).

- Brett


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-surefire-plugin forkMode question

Posted by David Hoffer <dh...@gmail.com>.
Do you know of a way, using gmaven, to drop a folder containing files and/or
subfolders?  Currently I consider my solution to be a hack because its bad
enough that the logic of what to cleanup is not in the test case source
file, but when I have to manually specify each and every file to delete it's
a hack.  This will never stay in sync over time.

If I could put all my temp test files/folders in a folder called 'tmp' and
then just drop 'tmp' using gmaven that's less of a hack.

You are right on the lifecyle, I forgot that I had set a phase...I'll change
it to 'test'.  I always get confused on this issue...do plugins ALWAYS run
AFTER the phase they are attached to?

-Dave

On Fri, Sep 4, 2009 at 12:14 AM, Brett Porter <br...@apache.org> wrote:

>
> On 04/09/2009, at 4:04 PM, David Hoffer wrote:
>
>  Do you know of any example of using the 'exec plugin from the test phase
>> in
>> the POM '?
>>
>> Currently the workaround I have found is to use the GMaven plugin that
>> deletes the DB.  However I don't have known control over when this
>> runs...it
>> just happens to work at the moment.
>>
>
> That's an equivalent solution. Adding <phase>test</phase> inside that
> execution is the right place.
>
>
>> BTW, do non-lifecyle bound plugins run in order they are specified in the
>> pom?
>>
>
> All plugins are lifecycle bound if they are run via the POM.
>
>
> - Brett
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: maven-surefire-plugin forkMode question

Posted by Brett Porter <br...@apache.org>.
On 04/09/2009, at 4:04 PM, David Hoffer wrote:

> Do you know of any example of using the 'exec plugin from the test  
> phase in
> the POM '?
>
> Currently the workaround I have found is to use the GMaven plugin that
> deletes the DB.  However I don't have known control over when this  
> runs...it
> just happens to work at the moment.

That's an equivalent solution. Adding <phase>test</phase> inside that  
execution is the right place.

>
> BTW, do non-lifecyle bound plugins run in order they are specified  
> in the
> pom?

All plugins are lifecycle bound if they are run via the POM.

- Brett


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-surefire-plugin forkMode question

Posted by David Hoffer <dh...@gmail.com>.
Do you know of any example of using the 'exec plugin from the test phase in
the POM '?

Currently the workaround I have found is to use the GMaven plugin that
deletes the DB.  However I don't have known control over when this runs...it
just happens to work at the moment.

BTW, do non-lifecyle bound plugins run in order they are specified in the
pom?

-Dave

On Thu, Sep 3, 2009 at 11:40 PM, Brett Porter <br...@apache.org> wrote:

> On 04/09/2009, at 3:35 PM, David Hoffer wrote:
>
>  During the setup for the test, actually I do this in the @BeforeClass
>> because its expensive, we make some calls into legacy code that creates db
>> connections.  I need to delete the access db after the test but can't
>> because the db connections still exist.
>>
>> So ideally I need some (tearDown) process to come along after each test
>> and
>> do a cleanup.  Doing this in the AfterClass would be fine but I can't get
>> it
>> to work...it seems to be the same process as the tests.
>>
>
> It is.
>
> I think your best alternative is to delete the database using the exec
> plugin from the test phase in the POM (which will run after the surefire
> tests have concluded). It also means you don't need to fork multiple JVMs
> for your tests if you don't want to.
>
> - Brett
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: maven-surefire-plugin forkMode question

Posted by Brett Porter <br...@apache.org>.
On 04/09/2009, at 3:35 PM, David Hoffer wrote:

> During the setup for the test, actually I do this in the @BeforeClass
> because its expensive, we make some calls into legacy code that  
> creates db
> connections.  I need to delete the access db after the test but can't
> because the db connections still exist.
>
> So ideally I need some (tearDown) process to come along after each  
> test and
> do a cleanup.  Doing this in the AfterClass would be fine but I  
> can't get it
> to work...it seems to be the same process as the tests.

It is.

I think your best alternative is to delete the database using the exec  
plugin from the test phase in the POM (which will run after the  
surefire tests have concluded). It also means you don't need to fork  
multiple JVMs for your tests if you don't want to.

- Brett


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-surefire-plugin forkMode question

Posted by David Hoffer <dh...@gmail.com>.
During the setup for the test, actually I do this in the @BeforeClass
because its expensive, we make some calls into legacy code that creates db
connections.  I need to delete the access db after the test but can't
because the db connections still exist.

So ideally I need some (tearDown) process to come along after each test and
do a cleanup.  Doing this in the AfterClass would be fine but I can't get it
to work...it seems to be the same process as the tests.

-Dave

On Thu, Sep 3, 2009 at 11:22 PM, Brett Porter <br...@apache.org> wrote:

> If the forkMode is always, the @before/@after should be run for each test
> and JVM, but is still before the JVM shuts down.
>
> What type of cleanup do you need to do after the JVM is shutdown?
>
> - Brett
>
>
> On 04/09/2009, at 6:15 AM, David Hoffer wrote:
>
>  How does forking work with respect to the @BeforeClass/@AfterClass
>> methods?
>> My use case is that I have some setup code that creates file/db
>> connections
>> that are not destroyed until the jvm is shutdown, therefore I can't
>> cleanup
>> in the @After method.  However it doesn't work using
>> @BeforeClass/@AfterClass either and I'm clear why.
>>
>> I tried using all the fork modes with no success.  What's the way to run
>> tests in one process and then cleanup in another?
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: maven-surefire-plugin forkMode question

Posted by Brett Porter <br...@apache.org>.
If the forkMode is always, the @before/@after should be run for each  
test and JVM, but is still before the JVM shuts down.

What type of cleanup do you need to do after the JVM is shutdown?

- Brett

On 04/09/2009, at 6:15 AM, David Hoffer wrote:

> How does forking work with respect to the @BeforeClass/@AfterClass  
> methods?
> My use case is that I have some setup code that creates file/db  
> connections
> that are not destroyed until the jvm is shutdown, therefore I can't  
> cleanup
> in the @After method.  However it doesn't work using
> @BeforeClass/@AfterClass either and I'm clear why.
>
> I tried using all the fork modes with no success.  What's the way to  
> run
> tests in one process and then cleanup in another?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org