FileDocCategorySizeDatePackage
ParallelTest.javaAPI DocApache Ant 1.705380Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

ParallelTest

public class ParallelTest extends org.apache.tools.ant.BuildFileTest
Test of the parallel TaskContainer
created
21 February 2002

Fields Summary
public static final String
DIRECT_MESSAGE
Standard property value for the basic test
public static final String
DELAYED_MESSAGE
Standard property value for the basic and fail test
public static final String
FAILURE_MESSAGE
Standard property value for the fail test
public static final String
TEST_BUILD_FILE
the build fiel associated with this test
Constructors Summary
public ParallelTest(String name)
Constructor for the ParallelTest object

param
name name of the test


                    
       
        super(name);
    
Methods Summary
static intcountThreads(java.lang.String s, int start)
the test result string should match the regex ^(\|\d+\/(+-)*)+\|$ for someting like |3/++--+-|5/+++++-----|

returns
-1 no more tests # start pos of next test
throws
AssertionFailedException when a constraint is invalid

        int firstPipe = s.indexOf('|", start);
        int beginSlash = s.indexOf('/", firstPipe);
        int lastPipe = s.indexOf('|", beginSlash);
        if ((firstPipe == -1) || (beginSlash == -1) || (lastPipe == -1)) {
            return -1;
        }

        int max = Integer.parseInt(s.substring(firstPipe + 1, beginSlash));
        int current = 0;
        int pos = beginSlash + 1;
        while (pos < lastPipe) {
            switch (s.charAt(pos++)) {
                case '+":
                    current++;
                    break;
                case '-":
                    current--;
                    break;
                default:
                    throw new AssertionFailedError("Only expect '+-' in result count, found "
                        + s.charAt(--pos) + " at position " + pos);
            }
            if (current > max) {
                throw new AssertionFailedError("Number of executing threads exceeded number allowed: "
                    + current + " > " + max);
            }
        }
        return lastPipe;
    
public voidsetUp()
The JUnit setup method

        configureProject(TEST_BUILD_FILE);
    
public voidtestBasic()
tests basic operation of the parallel task

        // should get no output at all
        Project p = getProject();
        p.setUserProperty("test.direct", DIRECT_MESSAGE);
        p.setUserProperty("test.delayed", DELAYED_MESSAGE);
        expectOutputAndError("testBasic", "", "");
        String log = getLog();
        assertEquals("parallel tasks didn't output correct data", log,
            DIRECT_MESSAGE + DELAYED_MESSAGE);

    
public voidtestDemux()
tests the demuxing of output streams in a multithreaded situation

        Project p = getProject();
        p.addTaskDefinition("demuxtest", DemuxOutputTask.class);
        PrintStream out = System.out;
        PrintStream err = System.err;
        System.setOut(new PrintStream(new DemuxOutputStream(p, false)));
        System.setErr(new PrintStream(new DemuxOutputStream(p, true)));

        try {
            p.executeTarget("testDemux");
        } finally {
            System.setOut(out);
            System.setErr(err);
        }
    
public voidtestFail()
tests the failure of a task within a parallel construction

        // should get no output at all
        Project p = getProject();
        p.setUserProperty("test.failure", FAILURE_MESSAGE);
        p.setUserProperty("test.delayed", DELAYED_MESSAGE);
        expectBuildExceptionContaining("testFail",
            "fail task in one parallel branch", FAILURE_MESSAGE);
    
public voidtestThreadCount()
tests basic operation of the parallel task

        // should get no output at all
        Project p = getProject();
        p.setUserProperty("test.direct", DIRECT_MESSAGE);
        p.setUserProperty("test.delayed", DELAYED_MESSAGE);
        expectOutputAndError("testThreadCount", "", "");
        String log = getLog();
        int pos = 0;
        while (pos > -1) {
            pos = countThreads(log, pos);
        }