Neeme Praks has sent me an interesting patch that allows the <ftp> task
to execute with a certain number of retries specified. That is, it
won't fail until the specified number of retries has passed.
I want to write some JUnit tests to test this patch. My idea was to
simulate failure by subclassing the FTP task class
(o.a.t.a.taskdefs.optional.net.FTP) within the JUnit test with a version
that allows setting a numberOfFailuresToSimulate member, and a modified
transferFiles() method that would, if numberOfFailuresToSimulate > 0,
simply decrement this value by 1 and throw a dummy BuildException,
otherwise, simply execute the regular transferFiles. This seems like a
good way to test Neeme's retry handler. Then this can be tested with a
build file that specifies the number of retry times, and the test can
then illustrate what happens with this buildfile when numbers >, <, or
== to the specified number of simulated failures occur.
To wit:
private static class myRetryableFTP extends FTP {
private int numberOfFailuresToSimulate;
int getNumberOfFailuresToSimulate() {
return numberOfFailuresToSimulate;
}
void setNumberOfFailuresToSimulate(int numberOfFailuresToSimulate) {
this.numberOfFailuresToSimulate = numberOfFailuresToSimulate;
}
protected int transferFiles(FTPClient ftp, FileSet fs)
throws IOException, BuildException
{
if (this.numberOfFailuresToSimulate > 0) {
this.numberOfFailuresToSimulate--;
throw new BuildException("Simulated failure for testing");
}
return super.transferFiles(ftp, fs);
}
}
However, my knowledge of Ant internals is somewhat limited. How can I
tell an ant project in my test code that when it sees an <ftp> tag, it
should delegate the performance of this task to myRetryableFTP, instead
of to the standard FTP as it would normally do? Is there an example of
this sort of thing within the existing Ant test suite?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
|