tags:

views:

317

answers:

4

I'm running unit test using ant

<target name="test" depends="tomcatDeploy" description="Build and run tests">
    <ant dir="${aDir}" target="test"/>
    <ant dir="${bDir}" target="test"/>
    <ant dir="${cDir}" target="test"/>
    <ant dir="${dDir}/ExtFramework"  target="test"/>
</target>

and I want to run them all on the same VM - otherwise I get a lot of overhead in the creation of the jvm & re-creation of statics and so forth.

Is there a way to do this?

A: 

The task by itself doesn't create a new VM. Are your tests creating a new VM?

yep , so it seems
yossale
+1  A: 

I think the subant task is what you're looking for. Assuming all of your subdirectories have a common parent, you can do something like the following:

<target name="test" depends="tomcatDeploy" description="Build and run tests">
    <subant target="test">
        <fileset dir="${parent}" includes="**/build.xml"/>
    </subant>
</target>

EDIT How are you running the tests? If you are using the junit task, do you have fork="yes"? If so, that will run the tests in a new VM. Change that to fork="no" to run the tests in the same VM.

Jason Day
Isn't it the same effect like yossale's approach? Since it's the same text in the manual: "Calls a given target for all defined sub-builds. This is an extension of ant for bulk project execution. This task must not be used outside of a target if it invokes the same build file it is part of." (http://ant.apache.org/manual/CoreTasks/subant.html) and "Runs Ant on a supplied buildfile. This can be used to build subprojects. This task must not be used outside of a target if it invokes the same build file it is part of." (http://ant.apache.org/manual/CoreTasks/ant.html)
furtelwart
Edited answer in response to comment.
Jason Day
Jason, <subant> uses <ant> under the covers, so you comment about efficiency makes no sense.
Well, I really screwed that one up; antcall reparses the buildfile and runs all dependent targets, making it much slower than subant. Mea Culpa.
Jason Day
A: 

Try to minimize the problem: Does your test create a new VM if you start it manually via JUnit? Or does the problem only occur in combination with ant?
Probably it's JUnit or your tests creating a new VM and leak memory.

furtelwart
A: 
<parallel threadCount='4'>
  <ant target='TargetThatConsumesLotsOfCPUTimeAndMemory'>
    <param name='file' value='one.txt'/>
  </ant>
  <ant target='TargetThatConsumesLotsOfCPUTimeAndMemory'>
    <param name='file' value='two.txt'/>

  </ant>
  <ant target='TargetThatConsumesLotsOfCPUTimeAndMemory'>
    <param name='file' value='three.txt'/>
  </ant>
  <!-- repeated about 40 times -->
</parallel>

http://www.java-tips.org/other-api-tips/ant/how-to-use-parallel-task.html

Brian
I think he wants to do this in ONE VM?
furtelwart
Thanks , but I need it all to run in one VM. I did it using the "junit" task (~new ant feature) but then I ran into another problem - the local directory is set by the jvm , and if use the same one for all , I have a problem with the classpathes
yossale