Browse Source

TestCase fixed, works now also on nagoya (Solaris).

The problem was that I did not allow enough time for java to start.
1 second is OK, 400 millis were not enough.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274993 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
00e6624c19
2 changed files with 49 additions and 33 deletions
  1. +7
    -2
      src/etc/testcases/taskdefs/java.xml
  2. +42
    -31
      src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java

+ 7
- 2
src/etc/testcases/taskdefs/java.xml View File

@@ -1,7 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>


<project name="java-test" basedir="." default="foo"> <project name="java-test" basedir="." default="foo">

<!-- this property gets overridden programmatically-->
<property name="timeToWait" value="4"/>
<!-- this property gets overridden programmatically-->
<property name="logFile" value="spawn.log"/>
<property name="app" <property name="app"
value="org.apache.tools.ant.taskdefs.JavaTest$$EntryPoint" /> value="org.apache.tools.ant.taskdefs.JavaTest$$EntryPoint" />


@@ -119,6 +122,8 @@
<arg value="${logFile}" /> <arg value="${logFile}" />
</java> </java>
</target> </target>

<target name="cleanup">
<delete file="${logFile}"/>
</target>
<target name="foo" /> <target name="foo" />
</project> </project>

+ 42
- 31
src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java View File

@@ -62,26 +62,30 @@ import org.apache.tools.ant.util.FileUtils;
/** /**
* stress out java task * stress out java task
* @author steve loughran * @author steve loughran
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @author <a href="mailto:donal@savvion.com">Donal Quinlan</a> * @author <a href="mailto:donal@savvion.com">Donal Quinlan</a>
* */ * */
public class JavaTest extends BuildFileTest { public class JavaTest extends BuildFileTest {


private static final int TIME_TO_WAIT = 4; private static final int TIME_TO_WAIT = 4;
// wait 1 second extra to allow for java to start ...
// this time was OK on a Win NT machine and on nagoya
private static final int SECURITY_MARGIN = 1000;

private boolean runFatalTests=false; private boolean runFatalTests=false;
public JavaTest(String name) {
public JavaTest(String name) {
super(name); super(name);
}
}
/** /**
* configure the project.
* configure the project.
* if the property junit.run.fatal.tests is set we run * if the property junit.run.fatal.tests is set we run
* the fatal tests * the fatal tests
*/ */
public void setUp() {
public void setUp() {
configureProject("src/etc/testcases/taskdefs/java.xml"); configureProject("src/etc/testcases/taskdefs/java.xml");
//final String propname="tests-classpath.value"; //final String propname="tests-classpath.value";
//String testClasspath=System.getProperty(propname); //String testClasspath=System.getProperty(propname);
//System.out.println("Test cp="+testClasspath); //System.out.println("Test cp="+testClasspath);
@@ -92,28 +96,30 @@ public class JavaTest extends BuildFileTest {
} }


public void tearDown() { public void tearDown() {
// remove log file from testSpawn
project.executeTarget("cleanup");
} }


public void testNoJarNoClassname(){ public void testNoJarNoClassname(){
expectBuildExceptionContaining("testNoJarNoClassname", expectBuildExceptionContaining("testNoJarNoClassname",
"parameter validation", "parameter validation",
"Classname must not be null.");
"Classname must not be null.");
} }


public void testJarNoFork() { public void testJarNoFork() {
expectBuildExceptionContaining("testJarNoFork", expectBuildExceptionContaining("testJarNoFork",
"parameter validation", "parameter validation",
"Cannot execute a jar in non-forked mode. "
+ "Please set fork='true'. ");
"Cannot execute a jar in non-forked mode. "
+ "Please set fork='true'. ");
} }
public void testJarAndClassName() {
public void testJarAndClassName() {
expectBuildException("testJarAndClassName", expectBuildException("testJarAndClassName",
"Should not be able to set both classname AND jar"); "Should not be able to set both classname AND jar");
} }


public void testClassnameAndJar() {

public void testClassnameAndJar() {
expectBuildException("testClassnameAndJar", expectBuildException("testClassnameAndJar",
"Should not be able to set both classname AND jar"); "Should not be able to set both classname AND jar");
} }
@@ -121,7 +127,7 @@ public class JavaTest extends BuildFileTest {
public void testRun() { public void testRun() {
executeTarget("testRun"); executeTarget("testRun");
} }




/** this test fails but we ignore the return value; /** this test fails but we ignore the return value;
@@ -132,7 +138,7 @@ public class JavaTest extends BuildFileTest {
executeTarget("testRunFail"); executeTarget("testRunFail");
} }
} }
public void testRunFailFoe() { public void testRunFailFoe() {
if(runFatalTests) { if(runFatalTests) {
expectBuildExceptionContaining("testRunFailFoe", expectBuildExceptionContaining("testRunFailFoe",
@@ -148,32 +154,32 @@ public class JavaTest extends BuildFileTest {
} }


public void testExcepting() { public void testExcepting() {
expectLogContaining("testExcepting",
expectLogContaining("testExcepting",
"Exception raised inside called program"); "Exception raised inside called program");
} }
public void testExceptingFork() { public void testExceptingFork() {
expectLogContaining("testExceptingFork",
expectLogContaining("testExceptingFork",
"Java Result:"); "Java Result:");
} }
public void testExceptingFoe() { public void testExceptingFoe() {
expectBuildExceptionContaining("testExceptingFoe", expectBuildExceptionContaining("testExceptingFoe",
"passes exception through", "passes exception through",
"Exception raised inside called program"); "Exception raised inside called program");
} }
public void testExceptingFoeFork() { public void testExceptingFoeFork() {
expectBuildExceptionContaining("testExceptingFoeFork", expectBuildExceptionContaining("testExceptingFoeFork",
"exceptions turned into error codes", "exceptions turned into error codes",
"Java returned:");
}
"Java returned:");
}
public void testResultPropertyZero() { public void testResultPropertyZero() {
executeTarget("testResultPropertyZero"); executeTarget("testResultPropertyZero");
assertEquals("0",project.getProperty("exitcode")); assertEquals("0",project.getProperty("exitcode"));
} }
public void testResultPropertyNonZero() { public void testResultPropertyNonZero() {
executeTarget("testResultPropertyNonZero"); executeTarget("testResultPropertyNonZero");
assertEquals("-1",project.getProperty("exitcode")); assertEquals("-1",project.getProperty("exitcode"));
@@ -188,10 +194,15 @@ public class JavaTest extends BuildFileTest {
project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT));
project.executeTarget("testSpawn"); project.executeTarget("testSpawn");
try { try {
Thread.sleep(TIME_TO_WAIT * 1000 + 400);
Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN);
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("my sleep was interrupted"); System.out.println("my sleep was interrupted");
} }
// let's be nice with the next generation of developers
if (!logFile.exists()) {
System.out.println("suggestion: increase the constant"
+ " SECURITY_MARGIN to give more time for java to start.");
}
assertTrue("log file exists", logFile.exists()); assertTrue("log file exists", logFile.exists());
} }


@@ -200,7 +211,7 @@ public class JavaTest extends BuildFileTest {
* than normal JRE runtime * than normal JRE runtime
*/ */
public static class EntryPoint { public static class EntryPoint {
/** /**
* this entry point is used by the java.xml tests to * this entry point is used by the java.xml tests to
* generate failure strings to handle * generate failure strings to handle
@@ -228,15 +239,15 @@ public class JavaTest extends BuildFileTest {
} }
} }
} }
/** /**
* entry point class with no dependencies other * entry point class with no dependencies other
* than normal JRE runtime * than normal JRE runtime
*/ */
public static class ExceptingEntryPoint { public static class ExceptingEntryPoint {
/** /**
* throw a run time exception which does not need
* throw a run time exception which does not need
* to be in the signature of the entry point * to be in the signature of the entry point
*/ */
public static void main(String[] argv) { public static void main(String[] argv) {


Loading…
Cancel
Save