Dashboard > CruiseControl > Frequently Asked Questions > Running Servertests with Ant
Running Servertests with Ant Log In View a printable version of the current page.

Added by Robert Watkins , last edited by uli kortmann on Oct 15, 2007  (view change)
Labels: 
(None)

Just use Ant! It's plattform independent.
I assume that you start your server with Ant anyway. If not, you should do so.
The snippet below does quite the same as the cactus task (but without an external task).

<parallel>
    <antcall target="run-local-tests"/>
    <antcall target="start-server"/>
    <sequential>
        <waitfor maxwait="10" maxwaitunit="minute" checkevery="1000">
            <socket server="${server.host}" port="${server.http.port}" />
        </waitfor>
        <antcall target="run-server-tests"/>
        <antcall target="stop-server"/>
    </sequential>
</parallel>

We call this in the complete and clean nightly build.

To redeploy the application if the server is already running, do something like

<target name="run-server-tests" depends="copy-webapp" description="">
        <if>
            <socket server="${server.host}" port="${server.http.port}" />
            <then>
                <antcall target="reload-webapp"    inheritrefs="true" />
                <antcall target="run-server-tests" inheritrefs="true" />
            </then>
            <else>
                <parallel>
                    <antcall target="spawn-server" />
                    <sequential>
                        <waitfor checkevery="500" maxwaitunit="minute" maxwait="2">
                            <socket server="${server.host}" port="${server.http.port}" />
                        </waitfor>
                        <antcall target="run-server-tests" inheritrefs="true" />
                    </sequential>
                </parallel>
            </else>
        </if>
    </target>

We usually use that for development (e.g. inside eclipse) or the CC developer builds to get fast feedback without server restarts.
See also Starting a server with cc on how to spawn a process from ant.


From Ant 1.6.1 you can specify the spawn="true" as part of the exec tag. The result of this will be that the exec'ed command will keep on running after your ant script has terminated.


 This solution was originally found on the ant mailing lists somewhere. It has been tested successfully on Solaris. (if anyone can provide the original post from the ant-user list or confirmation on other platforms, please add it here).

And yes, this is an "ant" issue. But the question comes up often for cruisers wanting to kick off a server (rmi, tomcat, etc) during the build to allow for 'live' tests to be run.


If you're looking to start a server, run a test, and then shut it down again, all as part of your ant build w/in cruisecontrol take a look at the runservertests task from the Cactus project: http://jakarta.apache.org/cactus/integration/ant/index.html


Use the following snippet in your ant build file (edit where appropriate):

<exec executable="antRunAsync.sh" failonerror="yes">
   <env key="ANTRUN_NOHUP" value="true" />  <!-- optional -->
   <env key="ANTRUN_OUTPUT" value="output.log" />  <!-- required, may be /dev/null -->
   <arg value="/usr/local/real/executable/here" />
 </exec>



Here is the script that will be invoked (no editing needed):

 #!/bin/sh
 # antRunAsync - Wrapper script to run an executable detached in the
 # background from Ant's <exec> task.  This works be redirecting stdin,
 # stdout and stderr so Ant finds them closed and doesn't wait for the
 # program to exit.
 #
 # usage:
 # <exec executable="antRunAsync.sh" failonerror="yes">
 #   <env key="ANTRUN_NOHUP" value="true" />  <!-- optional -->
 #   <env key="ANTRUN_OUTPUT" value="output.log" />  <!-- required, may be /dev/null -->
 #   <arg value="real executable" />
 # </exec>

 # If ANTRUN_NOHUP environment variable is set to true/yes/nohup, run the
 # executable prefixed with "nohup" making it immune to logging out.
 case "$ANTRUN_NOHUP" in
    true|yes|nohup) ANTRUN_NOHUP=nohup ;;
    *) unset ANTRUN_NOHUP ;;
 esac

 # ANTRUN_OUTPUT environment variable must be set to output file name or
 # executable can't run detached
 if [ -n "$ANTRUN_OUTPUT" ]
 then
    $ANTRUN_NOHUP $@ </dev/null > "$ANTRUN_OUTPUT" 2>&1 &
    exit 0
 else
    echo "$0: ERROR: variable ANTRUN_OUTPUT must be set to  output file name!"
    exit 1
 fi






Neat! Just tested this, and it sailed on X86 and SPARC. Very thin, too. Can we describe this jewel well enough to link to the source, as opposed to supplying it as the description? - Randy


I've written a ant task to achieve this. See the ant-FAQ question "How do i start a shell command in such a way that ant doesn't wait?" on http://www.jguru.com/faq/printablefaq.jsp?topic=Ant
- Marcus Ludvigson


Also tested under Linux (Mandrake 9.2 x86) and SunOS (sun4u sparc). One pitful: the script returns 0 or 1 based on its success, not on the underlying programs success. A work-around we use is to do a short sleep, allowing the underlying program to start, and then check for a file that is known only to be present when the underlying program is read.
- kkvenkit

Powered by a free Atlassian Confluence Open Source Project / Non-profit License granted to ThoughtWorks, Inc.. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators