ParallelTestpublic class ParallelTest extends org.apache.tools.ant.BuildFileTest Test of the parallel TaskContainer |
Fields Summary |
---|
public static final String | DIRECT_MESSAGEStandard property value for the basic test | public static final String | DELAYED_MESSAGEStandard property value for the basic and fail test | public static final String | FAILURE_MESSAGEStandard property value for the fail test | public static final String | TEST_BUILD_FILEthe build fiel associated with this test |
Constructors Summary |
---|
public ParallelTest(String name)Constructor for the ParallelTest object
super(name);
|
Methods Summary |
---|
static int | countThreads(java.lang.String s, int start)the test result string should match the regex
^(\|\d+\/(+-)*)+\|$ for someting like
|3/++--+-|5/+++++-----|
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 void | setUp()The JUnit setup method
configureProject(TEST_BUILD_FILE);
| public void | testBasic()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 void | testDemux()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 void | testFail()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 void | testThreadCount()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);
}
|
|