From 00e6624c1927ca0775d4d2cf2b3c8a227814c971 Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Wed, 30 Jul 2003 15:25:51 +0000 Subject: [PATCH] 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 --- src/etc/testcases/taskdefs/java.xml | 9 ++- .../apache/tools/ant/taskdefs/JavaTest.java | 73 +++++++++++-------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/etc/testcases/taskdefs/java.xml b/src/etc/testcases/taskdefs/java.xml index 0e5defdf0..58379b095 100644 --- a/src/etc/testcases/taskdefs/java.xml +++ b/src/etc/testcases/taskdefs/java.xml @@ -1,7 +1,10 @@ - + + + + @@ -119,6 +122,8 @@ - + + + diff --git a/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java b/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java index b72baa90a..3c1250486 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java @@ -62,26 +62,30 @@ import org.apache.tools.ant.util.FileUtils; /** * stress out java task * @author steve loughran - * @author Stephane Bailliez + * @author Stephane Bailliez * @author Donal Quinlan * */ public class JavaTest extends BuildFileTest { 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; - - public JavaTest(String name) { + + public JavaTest(String name) { super(name); - } - + } + /** - * configure the project. + * configure the project. * if the property junit.run.fatal.tests is set we run * the fatal tests */ - public void setUp() { + public void setUp() { configureProject("src/etc/testcases/taskdefs/java.xml"); - + //final String propname="tests-classpath.value"; //String testClasspath=System.getProperty(propname); //System.out.println("Test cp="+testClasspath); @@ -92,28 +96,30 @@ public class JavaTest extends BuildFileTest { } public void tearDown() { + // remove log file from testSpawn + project.executeTarget("cleanup"); } public void testNoJarNoClassname(){ expectBuildExceptionContaining("testNoJarNoClassname", "parameter validation", - "Classname must not be null."); + "Classname must not be null."); } public void testJarNoFork() { expectBuildExceptionContaining("testJarNoFork", "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", "Should not be able to set both classname AND jar"); } - - public void testClassnameAndJar() { + + public void testClassnameAndJar() { expectBuildException("testClassnameAndJar", "Should not be able to set both classname AND jar"); } @@ -121,7 +127,7 @@ public class JavaTest extends BuildFileTest { public void testRun() { executeTarget("testRun"); } - + /** this test fails but we ignore the return value; @@ -132,7 +138,7 @@ public class JavaTest extends BuildFileTest { executeTarget("testRunFail"); } } - + public void testRunFailFoe() { if(runFatalTests) { expectBuildExceptionContaining("testRunFailFoe", @@ -148,32 +154,32 @@ public class JavaTest extends BuildFileTest { } public void testExcepting() { - expectLogContaining("testExcepting", + expectLogContaining("testExcepting", "Exception raised inside called program"); } - + public void testExceptingFork() { - expectLogContaining("testExceptingFork", + expectLogContaining("testExceptingFork", "Java Result:"); } - + public void testExceptingFoe() { expectBuildExceptionContaining("testExceptingFoe", "passes exception through", "Exception raised inside called program"); } - + public void testExceptingFoeFork() { expectBuildExceptionContaining("testExceptingFoeFork", "exceptions turned into error codes", - "Java returned:"); - } - + "Java returned:"); + } + public void testResultPropertyZero() { executeTarget("testResultPropertyZero"); assertEquals("0",project.getProperty("exitcode")); } - + public void testResultPropertyNonZero() { executeTarget("testResultPropertyNonZero"); assertEquals("-1",project.getProperty("exitcode")); @@ -188,10 +194,15 @@ public class JavaTest extends BuildFileTest { project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); project.executeTarget("testSpawn"); try { - Thread.sleep(TIME_TO_WAIT * 1000 + 400); + Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN); } catch (Exception ex) { 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()); } @@ -200,7 +211,7 @@ public class JavaTest extends BuildFileTest { * than normal JRE runtime */ public static class EntryPoint { - + /** * this entry point is used by the java.xml tests to * generate failure strings to handle @@ -228,15 +239,15 @@ public class JavaTest extends BuildFileTest { } } } - + /** * entry point class with no dependencies other * than normal JRE runtime */ 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 */ public static void main(String[] argv) {