| <?xml version="1.0" encoding="ISO-8859-1"?> | |
| <!DOCTYPE project [ | |
| <!-- | |
| Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. | |
| This program and the accompanying materials are made available under the | |
| terms of the Eclipse Public License v. 2.0, which is available at | |
| http://www.eclipse.org/legal/epl-2.0. | |
| This Source Code may also be made available under the following Secondary | |
| Licenses when the conditions for such availability set forth in the | |
| Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | |
| version 2 with the GNU Classpath Exception, which is available at | |
| https://www.gnu.org/software/classpath/license.html. | |
| SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | |
| --> | |
| <!ENTITY commonBuild SYSTEM "./../../config/common.xml"> | |
| ]> | |
| <!-- | |
| Note that this currently assumes that the ear/earwithejb and ejb/statelesshello projects have run to build | |
| the ear used for this test. | |
| Also note that this test expects the 'grep' command to be present in the operating environment. | |
| This is fine on Solaris and Linux systems, and should be fine on Windows systems prepared | |
| according to the requirements for building the app server. | |
| --> | |
| <project name="autodeployWithEJB" default="all" basedir="."> | |
| &commonBuild; | |
| <property name="testName" value="withEJB"/> | |
| <property name="dateFormat" value="yyyy-MM-dd-HH:mm:ss.SSS"/> | |
| <property name="archivedir" value="${build}/archives"/> | |
| <!-- | |
| The following property defines the exception text that appears in the server.log file if | |
| the bug is present. | |
| --> | |
| <property name="exceptionText" value="EJBClassLoader instance that has already been shutdown"/> | |
| <target name="prepare" depends="init"> | |
| <property name="archiveName" value="earwithejb.ear"/> | |
| <property name="all.ear" value="${archivedir}/${archiveName}"/> | |
| <property name="server.log.file" value="${env.S1AS_HOME}/domains/domain1/logs/server.log"/> | |
| <property name="autodeploy.dir" value="${env.S1AS_HOME}/domains/domain1/autodeploy"/> | |
| <property name="result.property.file" value="${build}/result.properties"/> | |
| <mkdir dir="${build}" /> | |
| <path id="test.compile.classpath"> | |
| <pathelement location="${inst}/lib/j2ee.jar"/> | |
| <pathelement location="${java.home}/lib/tools.jar"/> | |
| <pathelement location="${env.S1AS_HOME}/lib/appserv-rt.jar"/> | |
| <pathelement location="${build}"/> | |
| </path> | |
| </target> | |
| <target name="build" depends="prepare"> | |
| <echo>Building ear</echo> | |
| <!-- | |
| The earlier tests should have run already, so the app we use for autodeploy testing | |
| should already be in place. | |
| --> | |
| <!-- | |
| <ant dir="${testsRoot}/ejb/statelesshello" target="assemble"> | |
| <property name="build" value="${testsRoot}/build/ejb/statelesshello"/> | |
| </ant> | |
| <ant dir="${testsRoot}/ear/earwithejb" target="assemble"> | |
| <property name="build" value="${testsRoot}/build/ear/earwithejb"/> | |
| </ant> | |
| --> | |
| </target> | |
| <target name="compile" depends="prepare"> | |
| <javac srcdir="." | |
| destdir="${build}" | |
| debug="on" | |
| failonerror="true"> | |
| <classpath refid="test.compile.classpath"/> | |
| </javac> | |
| </target> | |
| <!-- | |
| This target runs a Java class that watches the app server's autodeploy directory and detects | |
| when the app server has deployed or undeployed the app (or has reported a failure to do so) by observing | |
| when the marker files appear in the directory. | |
| The target records its results in a temporary properties file in the ${build} directory. | |
| This provides a simple way (relatively simple, at least) to use the same target more than once | |
| and store different result values in a way that can be retrieved and used from the main | |
| target. (This basically works around the behavior of ant in which a called target's property | |
| settings are NOT propagated out to the calling target. It also avoids the practice of creating | |
| a set of marker files that, by their presence or absence, convey success or failure of a substep.) | |
| --> | |
| <target name="runAutoDeployMonitor"> | |
| <javaWithResult | |
| fork="true" | |
| failonerror="false" | |
| jvm="${JAVA}" | |
| classname="autodeploy.test.AutoDeployMonitor" | |
| resultproperty="autodeployResult" | |
| output="${build}/${log.id}.output.log" | |
| > | |
| <jvmarg value="-Dmonitor.debug=true"/> | |
| <classpath> | |
| <path location="${inst}/lib/j2ee.jar"/> | |
| <path location="${build}"/> | |
| </classpath> | |
| <arg line="${arg.list}"/> | |
| </javaWithResult> | |
| <!-- | |
| The result property name used in the next task is an argument to the called target. | |
| Note that the echo is a little oddly formatted. The </echo> is on a line by itself and left-justified so | |
| that the output to the file being written will reside on a line by itself. The | |
| left-justification is not really needed but the properties file looks a bit nicer | |
| if you open it in an editor. This is because the next line in the properties file being | |
| written is indented as far as the </echo> is indented here in the build.xml file. | |
| --> | |
| <echo file="${result.property.file}" append="true">${resultPropertyName}=${autodeployResult} | |
| </echo> | |
| </target> | |
| <target name="deploy.autodeploy"> | |
| <!-- | |
| To monitor auto-deployment or auto-undeployment, we start by getting the current time. | |
| Then we copy the archive file into the autodeploy directory (for auto-deploy) or delete | |
| it (for auto-undeploy). All marker files created by the server during auto-deployment of | |
| the newly-copied archive file will have later timestamps than the timestamp just created. | |
| There could be earlier marker files for the same archive in the directory and the monitor | |
| wants to ignore those, which is why we get the current time and pass it to the monitor. | |
| The monitor will check for marker files for the copied archive file | |
| and whose last modification time are after the current timestamp, returning 0 if the | |
| auto-deployer creates a _deployed or _undeployed file, 1 if it creates a _deploy_failed | |
| or _undeploy_failed file, and -1 if it recognized no marker file. | |
| --> | |
| <tstamp prefix="deploy"> | |
| <format property="NOW" pattern="${dateFormat}"/> | |
| </tstamp> | |
| <!-- | |
| Trigger the auto-deploy. | |
| --> | |
| <copy file="${archive.file}" todir="${autodeploy.dir}" overwrite="true"/> | |
| <!-- | |
| Use the monitor to detect when the auto-deploy has completed. | |
| --> | |
| <echo>Waiting for autodeployment to complete...</echo> | |
| <antcall target="runAutoDeployMonitor"> | |
| <param name="arg.list" value="${archiveName} ${autodeploy.dir} ${dateFormat} ${deploy.NOW}"/> | |
| <param name="resultPropertyName" value="${deployResultPropertyName}"/> | |
| <param name="log.id" value="1"/> | |
| </antcall> | |
| </target> | |
| <target name="deploy.autoundeploy"> | |
| <!-- | |
| This target works very much like the deploy.autodeploy target except that instead of | |
| copying the archive into the autodeploy directory it deletes the previously copied | |
| archive from that directory. | |
| --> | |
| <tstamp prefix="undeploy"> | |
| <format property="NOW" pattern="${dateFormat}"/> | |
| </tstamp> | |
| <!-- | |
| Trigger auto-undeploy by deleting the file. | |
| --> | |
| <delete quiet="true"> | |
| <fileset dir="${autodeploy.dir}" includes="${archiveName}"/> | |
| </delete> | |
| <echo>Waiting for autoundeployment to complete...</echo> | |
| <antcall target="runAutoDeployMonitor"> | |
| <param name="arg.list" value="${archiveName} ${autodeploy.dir} ${dateFormat} ${undeploy.NOW}"/> | |
| <param name="resultPropertyName" value="${undeployResultPropertyName}"/> | |
| <param name="log.id" value="2"/> | |
| </antcall> | |
| </target> | |
| <target name="searchForException"> | |
| <!-- | |
| See if the exception text appears in the server.log file. This step assumes the operating | |
| environment supports the grep command. This should be fine for Solaris and Linux systems | |
| and for Windows systems that support building the product. | |
| The output from the grep is saved into a property (grepOutput),then the property is written | |
| into a file. The file to be written (output.file) is also provided as an argument so this | |
| target can be called from different places and the results stored in different files for | |
| later comparison. | |
| --> | |
| <exec | |
| executable="grep" | |
| resultproperty="grepResult" | |
| outputproperty="grepOutput" | |
| > | |
| <arg value="${exceptionText}"/> | |
| <arg value="${server.log.file}"/> | |
| </exec> | |
| <!-- | |
| If grep does not find the error string it displays Result: 1 which looks like a failure. The | |
| next couple of steps prepare and display a message that reassures someone looking at the log | |
| that Result: 1 is not a problem in this context. | |
| --> | |
| <condition property="statusMessage" value="The preceding Result: 1 message is expected; it means grep did not find the error string."> | |
| <equals arg1="${grepResult}" arg2="1"/> | |
| </condition> | |
| <property name="statusMessage" value=""/> | |
| <echo>${statusMessage}</echo> | |
| <echo file="${output.file}">${grepOutput}</echo> | |
| <echo file="${result.property.file}" append="true">${resultPropertyName}=${grepResult} | |
| </echo> | |
| </target> | |
| <target name="checkForRegression" if="fileMatchError"> | |
| <echo>${fileMatchError} | |
| The string "${exceptionText}" was found, implying that the bug is present. | |
| </echo> | |
| </target> | |
| <target name="private-all" depends="compile"> | |
| <antcall target="build"/> | |
| <antcall target="declare-test"> | |
| <param name="description" value="autodeploy/loadertest Test autodeploy and context class loader"/> | |
| </antcall> | |
| <!-- | |
| The next task discards any previous temporary file used to gather property settings that | |
| record the results of the autodeploy directory monitoring Java class. | |
| --> | |
| <delete file="${result.property.file}" quiet="true"/> | |
| <!-- | |
| Do the auto-deployment. | |
| --> | |
| <antcall target="deploy.autodeploy"> | |
| <param name="archive.file" value="${all.ear}"/> | |
| <param name="autodeploy.dir" value="${autodeploy.dir}"/> | |
| <param name="deployResultPropertyName" value="deployResult"/> | |
| </antcall> | |
| <!-- | |
| Search the server's log file for occurrences of the exception we're interested in. | |
| We do this now, before undeploying, and capture the output in a file. Then we'll | |
| do the same thing after undeploying, capturing that output to s separate file. We | |
| hope the two output files will be the same, meaning that no new exceptions were | |
| thrown as a result of the undeploy. If the bug has resurfaced, then the second | |
| output file will contain an additional exception as compared to the first output file. | |
| --> | |
| <antcall target="searchForException"> | |
| <param name="resultPropertyName" value="firstSearchResult"/> | |
| <param name="output.file" value="${build}/before2nddeploy.log"/> | |
| </antcall> | |
| <!-- | |
| Now undeploy the app. | |
| --> | |
| <antcall target="deploy.autoundeploy"> | |
| <param name="archive.file" value="${all.ear}"/> | |
| <param name="autodeploy.dir" value="${autodeploy.dir}"/> | |
| <param name="undeployResultPropertyName" value="undeployResult"/> | |
| </antcall> | |
| <!-- | |
| Trigger another autodeployment. If the bug is present, this will trigger | |
| an exception message in the server's log file although the autodeployment | |
| will succeed. | |
| --> | |
| <antcall target="deploy.autodeploy"> | |
| <param name="archive.file" value="${all.ear}"/> | |
| <param name="autodeploy.dir" value="${autodeploy.dir}"/> | |
| <param name="deployResultPropertyName" value="secondDeployResult"/> | |
| </antcall> | |
| <!-- | |
| Search the file again looking for the error message that the bug would trigger. | |
| --> | |
| <antcall target="searchForException"> | |
| <param name="resultPropertyName" value="secondSearchResult"/> | |
| <param name="output.file" value="${build}/after2nddeploy.log"/> | |
| </antcall> | |
| <!-- | |
| Autoundeploy the app once more just to clean up. | |
| --> | |
| <antcall target="deploy.autoundeploy"> | |
| <param name="archive.file" value="${all.ear}"/> | |
| <param name="autodeploy.dir" value="${autodeploy.dir}"/> | |
| <param name="undeployResultPropertyName" value="secondUndeployResult"/> | |
| </antcall> | |
| <!-- | |
| Make the result properties of the several substeps accessible now because we need them in | |
| the next several steps. The prefix attribute helps avoid possible collisions with other | |
| property names that might already be present. | |
| --> | |
| <property file="${result.property.file}" prefix="autodeploy"/> | |
| <!-- | |
| Compare the two grep output files. They will be the same if the test was successful, and | |
| the fileMatchError property will be set if the grep outputs do NOT match. | |
| --> | |
| <condition property="fileMatchError" value="An exception was recorded in the server.log file that indicates a regression of bug 5003242."> | |
| <not> | |
| <filesmatch file1="${build}/before2nddeploy.log" file2="${build}/after2nddeploy.log"/> | |
| </not> | |
| </condition> | |
| <!-- | |
| Decide whether the test was successful or not. Make sure that the deploy and | |
| undeploy results are good and that the grep for the error string of the server.log | |
| file was the same before and after the second autodeployment. We don't really care | |
| if the second undeploy worked or not so we don't check its result property here. | |
| --> | |
| <condition property="result" value="0"> | |
| <and> | |
| <equals arg1="${autodeploy.deployResult}" arg2="0"/> | |
| <equals arg1="${autodeploy.undeployResult}" arg2="0"/> | |
| <equals arg1="${autodeploy.secondDeployResult}" arg2="0"/> | |
| <not> | |
| <isset property="fileMatchError"/> | |
| </not> | |
| </and> | |
| </condition> | |
| <antcall target="checkForRegression"/> | |
| <!-- | |
| If the property "result" was not set by the "condition" task just above then something | |
| went wrong and we set result to 1 now. Normally checkForRegression will set the value to 0 or 1. | |
| --> | |
| <condition property="result" value="1"> | |
| <not> | |
| <isset property="result"/> | |
| </not> | |
| </condition> | |
| <antcall target="processResult"> | |
| <param name="result" value="${result}"/> | |
| <param name="log" value="${build}/output.log"/> | |
| </antcall> | |
| </target> | |
| </project> |