Tomcat: automatic deploy and test

53 views
Skip to first unread message

dall...@gmail.com

unread,
Oct 12, 2006, 12:07:26 PM10/12/06
to jchav
I had to dig around a fair amount to find out how to automatically
start Tomcat, deploy a WAR file, run my JMeter tests, shutdown Tomcat
and then, of course, update my JChav results.

I hope this Ant script can be of help to someone. There's a bunch of
properties in the init target you'll need to change, and the run-tests
target has a couple of sleep calls in there that you'll want to
twiddle.

Cheers
Richard
--

<project basedir=".." default="exercise" name="jchav">

<target name="exercise"
description="Exercise the web site, recording performance"
depends="init,deploy-webapp,run-tests,run-jchav">
</target>

<target name="init">

<echo>Loading properties from ${user.name}.properties</echo>
<property file="${user.name}.properties" />

<tstamp description="An ID for this run">
<format property="build.id" pattern="dMMhhmmss" locale="en"/>
</tstamp>

<property name="war" value="deploy/jchav.war"
description="The WAR file to deploy" />

<property name="tomcat.home"
value="/Applications/tomcat/apache-tomcat-5.5.12"
description="Location of the Tomcat install" />

<property name="jmeter.install.dir"
value="/Applications/jakarta-jmeter-2.2"
description="The location of the install of JMeter" />

<property name="jchav.libs.dir"
value="/Applications/jchav-1_0_0"
description="The directory containing the jchav jars" />

<property name="jmeter.testplan"
value="clickaround.jmx"
description="The JMeter test plan script we want to run" />

<property name="jmeter.result.dir" value="jmeter-results"
description="The location to store the per run files" />

<property name="jmeter.result.file"
value="${jmeter.result.dir}/${build.id}.xml"
description="The resulting file location" />

<property name="jchav.result.dir"
value="jchav-results"
description="The location to generate the html and charts to." />

</target>

<!--
The start-tomcat target alone doesn't return, so we run it in parallel
with the tests we want. Note the sleep calls to allow Tomcat to do
start up etc. You will want to tweek the values dependng on your
application and hardware etc.

Note: if you find this target hanging, it may be because there's an
error in the script. Hit CTRL-C to terminate the target and at that
point you'll see the error output.
-->
<target name="run-tests" depends="init"
description="Start Tomcat, run JMeter tests, shutdown tomcat">
<parallel>
<antcall target="start-tomcat" />
<sequential>
<sleep seconds="15" description="Allow Tomcat time to start "/>
<antcall target="run-jmeter" />
<antcall target="undeploy-webapp" />
<sleep seconds="10" description="Allow time to uninstall app"/>
<antcall target="stop-tomcat" />
</sequential>
</parallel>
</target>

<!--
Thanks to:

http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/
-->
<target name="start-tomcat" depends="init">

<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true"
failonerror="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>

</target>

<target name="deploy-webapp" depends="init">
<copy file="${war}" todir="${tomcat.home}/webapps/" overwrite="true"
/>
</target>

<target name="undeploy-webapp" depends="init">
<delete file="${tomcat.home}/webapps/${war}" />
</target>

<target name="stop-tomcat" depends="init">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<arg line="stop"/>
</java>
</target>

<target name="run-jmeter" depends="init">

<taskdef
name="jmeter"
classpath="${jmeter.install.dir}/extras/ant-jmeter.jar"

classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

<jmeter
jmeterhome="${jmeter.install.dir}"
testplan="${jmeter.testplan}"
resultlog="${jmeter.result.file}">
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</jmeter>

</target>

<target name="run-jchav" depends="init">

<taskdef name="jchav" classname="com.googlecode.jchav.ant.JChavTask">
<classpath>
<fileset dir="${jchav.libs.dir}/">
<include name="**/*.jar"/>
</fileset>
</classpath>
</taskdef>

<jchav srcdir="${jmeter.result.dir}" destdir="${jchav.result.dir}"/>

</target>


</project>

Reply all
Reply to author
Forward
0 new messages