Class JUnit4
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- com.carrotsearch.ant.tasks.junit4.JUnit4
-
- All Implemented Interfaces:
java.lang.Cloneable
public class JUnit4 extends org.apache.tools.ant.Task
An ANT task to run JUnit4 tests. Differences (benefits?) compared to ANT's default JUnit task:- Built-in parallel test execution support (spawns multiple JVMs to avoid test interactions).
- Randomization of the order of test suites within a single JVM.
- Aggregates and synchronizes test events from executors. All reports run on the task's JVM (not on the test JVM).
- Fully configurable reporting via listeners (console, ANT-compliant XML, JSON).
Report listeners use Google Guava's
EventBus
and receive full information about tests' execution (including skipped, assumption-skipped tests, streamlined output and error stream chunks, etc.). - JUnit 4.10+ is required both for the task and for the tests classpath. Older versions will cause build failure.
- Integration with
RandomizedRunner
(randomization seed is passed to children JVMs).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JUnit4.ExtendedPropertySet
APropertySet
with an additional attribute specifying whether or not empty values should be propagated or ignored.static class
JUnit4.ExtendedVariable
AEnvironment.Variable
with an additional attribute specifying whether or not empty values should be propagated or ignored.static class
JUnit4.JvmOutputAction
What to do on JVM output?static class
JUnit4.NoTestsAction
What to do when there were no executed tests (all ignored or none at all?).
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANTLIB_RESOURCE_NAME
Name of the antlib resource inside JUnit4 JAR.private java.util.List<SuiteBalancer>
balancers
Balancers scheduling tests for individual JVMs in parallel mode.private org.apache.tools.ant.types.Path
bootclasspath
private static java.lang.String
CHILDVM_SYSPROP_CWD
System property passed to forked VMs: current working directory (absolute).private org.apache.tools.ant.types.Path
classpath
Multiple path resolution inCommandlineJava.getCommandline()
is very slow so we construct and canonicalize paths.private boolean
debugStream
static boolean
DEFAULT_DEBUGSTREAM
Default value ofsetDebugStream(boolean)
.static float
DEFAULT_DYNAMIC_ASSIGNMENT_RATIO
Default value ofsetDynamicAssignmentRatio(float)
static boolean
DEFAULT_HALT_ON_FAILURE
Default value ofsetHaltOnFailure(boolean)
.static boolean
DEFAULT_ISOLATE_WORKING_DIRECTORIES
Default value ofsetIsolateWorkingDirectories(boolean)
.static NonEmptyWorkDirectoryAction
DEFAULT_NON_EMPTY_WORKDIR_ACTION
Default valkue ofsetOnNonEmptyWorkDirectory(java.lang.String)
.static java.lang.String
DEFAULT_PARALLELISM
Default value ofsetParallelism(java.lang.String)
.static boolean
DEFAULT_PRINT_SUMMARY
Default value ofsetPrintSummary(boolean)
.static boolean
DEFAULT_SHUFFLE_ON_SLAVE
Default value ofsetShuffleOnSlave(boolean)
.static boolean
DEFAULT_SYSOUTS
Default value ofsetSysouts(boolean)
.static boolean
DEFAULT_UNIQUE_SUITE_NAME
Default value ofsetUniqueSuiteNames(boolean)
private java.nio.file.Path
dir
Directory to invoke forked VMs in.private float
dynamicAssignmentRatio
private org.apache.tools.ant.types.Environment
env
Environment variables to use in the forked JVM.private java.lang.String
failureProperty
Property to set if there were test failures or errors.private boolean
haltOnFailure
Stop the build process if there were errors?private long
heartbeat
private JUnit4.NoTestsAction
ifNoTests
private boolean
isolateWorkingDirectories
java.util.EnumSet<JUnit4.JvmOutputAction>
jvmOutputAction
private boolean
leaveTemporary
Set to true to leave temporary files (for diagnostics).private java.util.List<java.lang.Object>
listeners
Listeners listening on the event bus.private boolean
newEnvironment
Set new environment for the forked process?private NonEmptyWorkDirectoryAction
nonEmptyWorkDirAction
private java.lang.String
parallelism
static java.lang.Object
PARALLELISM_AUTO
static java.lang.String
PARALLELISM_MAX
private boolean
printSummary
Print summary of all tests at the end.private java.lang.String
random
private org.apache.tools.ant.types.resources.Resources
resources
Test names.private boolean
shuffleOnSlave
private org.apache.tools.ant.types.CommandlineJava
slaveCommand
Slave VM command line.private java.lang.String
statsPropertyPrefix
private boolean
sysouts
private java.nio.file.Path
tempDir
A folder to store temporary files in.private java.util.List<java.nio.file.Path>
temporaryFiles
A list of temporary files to leave or remove if build passes.private org.apache.tools.ant.AntClassLoader
testsClassLoader
Class loader used to resolve annotations and classes referenced from annotations whenDescription
s containing them are passed from slaves.private boolean
uniqueSuiteNames
private static java.lang.String[]
WELCOME_MESSAGES
Welcome messages.
-
Constructor Summary
Constructors Constructor Description JUnit4()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(org.apache.tools.ant.types.ResourceCollection rc)
Adds a set of tests based on pattern matching.void
addAssertions(org.apache.tools.ant.types.Assertions asserts)
Add assertions to tests execution.void
addConfiguredSysproperty(JUnit4.ExtendedVariable sysp)
Adds a system property to any forked JVM.void
addConfiguredSyspropertyset(JUnit4.ExtendedPropertySet sysp)
Adds a set of properties that will be used as system properties that tests can access.void
addEnv(JUnit4.ExtendedVariable var)
Adds an environment variable; used when forking.void
addFileSet(org.apache.tools.ant.types.FileSet fs)
Adds a set of tests based on pattern matching.private org.apache.tools.ant.types.Path
addSlaveClasspath()
Adds a classpath source which contains the given resource.private void
checkJvmOutput(com.google.common.eventbus.EventBus aggregatedBus, java.nio.file.Path file, ForkedJvmInfo forked, java.lang.String fileName)
BalancersList
createBalancers()
Creates a new list of balancers.java.lang.Object
createBatchtest()
org.apache.tools.ant.types.Path
createBootclasspath()
Adds a path to the bootclasspath.org.apache.tools.ant.types.Path
createClasspath()
Adds path to classpath used for tests.java.lang.Object
createFormatter()
org.apache.tools.ant.types.Commandline.Argument
createJvmarg()
Add an additional argument to any forked JVM.ListenersList
createListeners()
Creates a new list of listeners.java.lang.Object
createTest()
private int
determineForkedJvmCount(TestsCollection testCollection)
Determine how many forked JVMs to use.private java.lang.String
escapeAndJoin(java.lang.String[] commandline)
Try to provide an escaped, ready-to-use shell line to repeat a given command line.void
execute()
private void
executeSlave(ForkedJvmInfo slave, com.google.common.eventbus.EventBus aggregatedBus)
Attach listeners and execute a slave process.private org.apache.tools.ant.taskdefs.Execute
forkProcess(ForkedJvmInfo slaveInfo, com.google.common.eventbus.EventBus eventBus, org.apache.tools.ant.types.CommandlineJava commandline, java.io.InputStream eventStream, java.io.OutputStream sysout, java.io.OutputStream syserr, java.io.RandomAccessFile streamsBuffer)
Execute a slave process.private org.apache.tools.ant.types.CommandlineJava
getCommandline()
Returns the slave VM command line.java.lang.String
getSeed()
private java.nio.file.Path
getTempDir()
Resolve temporary folder.private java.nio.file.Path
getWorkingDirectory(ForkedJvmInfo jvmInfo)
boolean
isUniqueSuiteNames()
private static java.util.List<java.lang.String>
listFiles(java.nio.file.Path f)
private java.util.List<java.lang.String>
loadBalanceSuites(java.util.List<ForkedJvmInfo> jvmInfo, TestsCollection testsCollection, java.util.List<SuiteBalancer> balancers)
Perform load balancing of the set of suites.private long
masterSeed()
Return the master seed ofgetSeed()
.private TestsCollection
processTestResources()
Process test resources.private org.apache.tools.ant.types.Path
resolveFiles(org.apache.tools.ant.types.Path path)
Resolve all files from a given path and simplify its definition.void
setClonevm(java.lang.String v)
void
setDebugStream(boolean debugStream)
Enables a debug stream from each forked JVM.void
setDir(java.io.File dir)
The directory to invoke forked VMs in.void
setDynamicAssignmentRatio(float ratio)
Specifies the ratio of suites moved to dynamic assignment list.void
setEnableTestListenerEvents(java.lang.String v)
void
setErrorproperty(java.lang.String v)
void
setFailureProperty(java.lang.String failureProperty)
Property to set to "true" if there is a failure in a test.void
setFiltertrace(boolean filterTrace)
void
setFork(boolean fork)
void
setForkmode(java.lang.String forkMode)
void
setHaltOnError(boolean haltOnError)
void
setHaltOnFailure(boolean haltOnFailure)
Stop the build process if there were failures or errors during test execution.void
setHeartbeat(long heartbeat)
Sets the heartbeat used to detect inactive/ hung forked tests (JVMs) to the given number of seconds.void
setIfNoTests(java.lang.String value)
What to do when no tests were executed (all tests were ignored)?void
setIncludeantruntime(java.lang.String v)
void
setIsolateWorkingDirectories(boolean isolateWorkingDirectories)
If set totrue
each slave JVM gets a separate working directory under whatever is set insetDir(File)
.void
setJvm(java.lang.String jvm)
The command used to invoke the Java Virtual Machine, default is 'java'.void
setJvmOutputAction(java.lang.String jvmOutputActions)
What should be done on unexpected JVM output? JVM may write directly to the original descriptors, bypassing redirections of System.out and System.err.void
setLeaveTemporary(boolean leaveTemporary)
Set to true to leave temporary files for diagnostics.void
setLogfailedtests(java.lang.String v)
void
setMaxmemory(java.lang.String max)
Set the maximum memory to be used by all forked JVMs.void
setNewEnvironment(boolean v)
Do not propagate the old environment when new environment variables are specified.void
setOnNonEmptyWorkDirectory(java.lang.String value)
Determines the behavior on detecting non-empty existing current working directory for a forked JVM, before the tests commence.void
setOutputtoformatters(java.lang.String v)
void
setParallelism(java.lang.String parallelism)
The number of parallel slaves.void
setPrefix(java.lang.String prefix)
Initializes custom prefix for all junit4 properties.void
setPrintSummary(boolean printSummary)
Prints the summary of all executed, ignored etc.void
setProject(org.apache.tools.ant.Project project)
void
setReloading(java.lang.String v)
void
setSeed(java.lang.String randomSeed)
Initial random seed used for shuffling test suites and other sources of pseudo-randomness.void
setShowoutput(java.lang.String v)
void
setShuffleOnSlave(boolean shuffle)
Predictably shuffle tests order after balancing.void
setStatsPropertyPrefix(java.lang.String statsPropertyPrefix)
Sets the property prefix to which test statistics are saved.void
setSysouts(boolean sysouts)
If set to true, any sysout and syserr calls will be written to original output and error streams (and in effect will appear as "jvm output".void
setTempDir(java.io.File tempDir)
The directory to store temporary files in.void
setTimeout(java.lang.String v)
void
setUniqueSuiteNames(boolean uniqueSuiteNames)
Allow or disallow duplicate suite names in resource collections.private java.util.Map<java.lang.Boolean,java.util.List<java.lang.String>>
sortAndSplitReplicated(java.util.List<TestClass> testClasses)
private java.nio.file.Path
tempFile(java.lang.String uniqueSeed, java.lang.String base, java.lang.String suffix, java.nio.file.Path tempDir)
private void
validateArguments()
Validate arguments.private void
validateJUnit4()
Validate JUnit4 presence in a concrete version.private void
warnUnsupported(java.lang.String attName)
-
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
-
-
-
-
Field Detail
-
WELCOME_MESSAGES
private static java.lang.String[] WELCOME_MESSAGES
Welcome messages.
-
ANTLIB_RESOURCE_NAME
public static final java.lang.String ANTLIB_RESOURCE_NAME
Name of the antlib resource inside JUnit4 JAR.- See Also:
- Constant Field Values
-
PARALLELISM_AUTO
public static final java.lang.Object PARALLELISM_AUTO
- See Also:
setParallelism(String)
-
PARALLELISM_MAX
public static final java.lang.String PARALLELISM_MAX
- See Also:
setParallelism(String)
, Constant Field Values
-
DEFAULT_SHUFFLE_ON_SLAVE
public static final boolean DEFAULT_SHUFFLE_ON_SLAVE
Default value ofsetShuffleOnSlave(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_PARALLELISM
public static final java.lang.String DEFAULT_PARALLELISM
Default value ofsetParallelism(java.lang.String)
.- See Also:
- Constant Field Values
-
DEFAULT_PRINT_SUMMARY
public static final boolean DEFAULT_PRINT_SUMMARY
Default value ofsetPrintSummary(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_HALT_ON_FAILURE
public static final boolean DEFAULT_HALT_ON_FAILURE
Default value ofsetHaltOnFailure(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_ISOLATE_WORKING_DIRECTORIES
public static final boolean DEFAULT_ISOLATE_WORKING_DIRECTORIES
Default value ofsetIsolateWorkingDirectories(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_NON_EMPTY_WORKDIR_ACTION
public static final NonEmptyWorkDirectoryAction DEFAULT_NON_EMPTY_WORKDIR_ACTION
Default valkue ofsetOnNonEmptyWorkDirectory(java.lang.String)
.
-
DEFAULT_DYNAMIC_ASSIGNMENT_RATIO
public static final float DEFAULT_DYNAMIC_ASSIGNMENT_RATIO
Default value ofsetDynamicAssignmentRatio(float)
- See Also:
- Constant Field Values
-
DEFAULT_SYSOUTS
public static final boolean DEFAULT_SYSOUTS
Default value ofsetSysouts(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_DEBUGSTREAM
public static final boolean DEFAULT_DEBUGSTREAM
Default value ofsetDebugStream(boolean)
.- See Also:
- Constant Field Values
-
DEFAULT_UNIQUE_SUITE_NAME
public static final boolean DEFAULT_UNIQUE_SUITE_NAME
Default value ofsetUniqueSuiteNames(boolean)
- See Also:
- Constant Field Values
-
CHILDVM_SYSPROP_CWD
private static final java.lang.String CHILDVM_SYSPROP_CWD
System property passed to forked VMs: current working directory (absolute).- See Also:
- Constant Field Values
-
jvmOutputAction
public java.util.EnumSet<JUnit4.JvmOutputAction> jvmOutputAction
- See Also:
setJvmOutputAction(String)
-
sysouts
private boolean sysouts
- See Also:
setSysouts(boolean)
-
debugStream
private boolean debugStream
- See Also:
setDebugStream(boolean)
-
slaveCommand
private org.apache.tools.ant.types.CommandlineJava slaveCommand
Slave VM command line.
-
newEnvironment
private boolean newEnvironment
Set new environment for the forked process?
-
uniqueSuiteNames
private boolean uniqueSuiteNames
- See Also:
setUniqueSuiteNames(boolean)
-
env
private org.apache.tools.ant.types.Environment env
Environment variables to use in the forked JVM.
-
dir
private java.nio.file.Path dir
Directory to invoke forked VMs in.
-
resources
private final org.apache.tools.ant.types.resources.Resources resources
Test names.
-
haltOnFailure
private boolean haltOnFailure
Stop the build process if there were errors?
-
printSummary
private boolean printSummary
Print summary of all tests at the end.
-
failureProperty
private java.lang.String failureProperty
Property to set if there were test failures or errors.
-
tempDir
private java.nio.file.Path tempDir
A folder to store temporary files in. Defaults todir
or the project's basedir.
-
listeners
private java.util.List<java.lang.Object> listeners
Listeners listening on the event bus.
-
balancers
private java.util.List<SuiteBalancer> balancers
Balancers scheduling tests for individual JVMs in parallel mode.
-
testsClassLoader
private org.apache.tools.ant.AntClassLoader testsClassLoader
Class loader used to resolve annotations and classes referenced from annotations whenDescription
s containing them are passed from slaves.
-
parallelism
private java.lang.String parallelism
- See Also:
setParallelism(String)
-
leaveTemporary
private boolean leaveTemporary
Set to true to leave temporary files (for diagnostics).
-
temporaryFiles
private java.util.List<java.nio.file.Path> temporaryFiles
A list of temporary files to leave or remove if build passes.
-
random
private java.lang.String random
- See Also:
setSeed(String)
-
isolateWorkingDirectories
private boolean isolateWorkingDirectories
- See Also:
setIsolateWorkingDirectories(boolean)
-
nonEmptyWorkDirAction
private NonEmptyWorkDirectoryAction nonEmptyWorkDirAction
- See Also:
setIsolateWorkingDirectories(boolean)
-
classpath
private org.apache.tools.ant.types.Path classpath
Multiple path resolution inCommandlineJava.getCommandline()
is very slow so we construct and canonicalize paths.
-
bootclasspath
private org.apache.tools.ant.types.Path bootclasspath
-
dynamicAssignmentRatio
private float dynamicAssignmentRatio
- See Also:
setDynamicAssignmentRatio(float)
-
shuffleOnSlave
private boolean shuffleOnSlave
- See Also:
setShuffleOnSlave(boolean)
-
heartbeat
private long heartbeat
- See Also:
setHeartbeat(long)
-
ifNoTests
private JUnit4.NoTestsAction ifNoTests
- See Also:
setIfNoTests(java.lang.String)
-
statsPropertyPrefix
private java.lang.String statsPropertyPrefix
- See Also:
setStatsPropertyPrefix(java.lang.String)
-
-
Method Detail
-
setJvmOutputAction
public void setJvmOutputAction(java.lang.String jvmOutputActions)
What should be done on unexpected JVM output? JVM may write directly to the original descriptors, bypassing redirections of System.out and System.err. Typically, these messages will be important and should fail the build (permgen space exceeded, compiler errors, crash dumps). However, certain legitimate logs (gc activity, class loading logs) are also printed to these streams so sometimes the output can be ignored.Allowed values (any comma-delimited combination of):
JUnit4.JvmOutputAction
constants.
-
setSysouts
public void setSysouts(boolean sysouts)
If set to true, any sysout and syserr calls will be written to original output and error streams (and in effect will appear as "jvm output". By default sysout and syserrs are captured and proxied to the event stream to be synchronized with other test events but occasionally one may want to synchronize them with direct JVM output (to synchronize with compiler output or GC output for example).
-
setDebugStream
public void setDebugStream(boolean debugStream)
Enables a debug stream from each forked JVM. This will create an additional file next to each events file. For debugging the framework only, not a general-purpose setting.
-
setUniqueSuiteNames
public void setUniqueSuiteNames(boolean uniqueSuiteNames)
Allow or disallow duplicate suite names in resource collections. By default this option istrue
because certain ANT-compatible report types (like XML reports) will have a problem with duplicate suite names (will overwrite files).
-
isUniqueSuiteNames
public boolean isUniqueSuiteNames()
- See Also:
setUniqueSuiteNames(boolean)
-
setDynamicAssignmentRatio
public void setDynamicAssignmentRatio(float ratio)
Specifies the ratio of suites moved to dynamic assignment list. A dynamic assignment list dispatches suites to the first idle slave JVM. Theoretically this is an optimal strategy, but it is usually better to have some static assignments to avoid communication costs.A ratio of 0 means only static assignments are used. A ratio of 1 means only dynamic assignments are used.
The list of dynamic assignments is sorted by decreasing cost (always) and is inherently prone to race conditions in distributing suites. Should there be an error based on suite-dependency it will not be directly repeatable. In such case use the per-slave-jvm list of suites file dumped to disk for each slave JVM. (see
setLeaveTemporary(boolean)
).
-
setParallelism
public void setParallelism(java.lang.String parallelism)
The number of parallel slaves. Can be set to a constant "max" for the number of cores returned fromRuntime.availableProcessors()
or "auto" for sensible defaults depending on the number of cores. The default is a single subprocess.Note that this setting forks physical JVM processes so it multiplies the requirements for heap memory, IO, etc.
-
setFailureProperty
public void setFailureProperty(java.lang.String failureProperty)
Property to set to "true" if there is a failure in a test.
-
setNewEnvironment
public void setNewEnvironment(boolean v)
Do not propagate the old environment when new environment variables are specified.
-
setSeed
public void setSeed(java.lang.String randomSeed)
Initial random seed used for shuffling test suites and other sources of pseudo-randomness. If not set, any random value is set.The seed's format is compatible with
RandomizedRunner
so that seed can be fixed for suites and methods alike.
-
setPrefix
public void setPrefix(java.lang.String prefix)
Initializes custom prefix for all junit4 properties. This must be consistent across all junit4 invocations if done from the same classpath. Use only when REALLY needed.
-
getSeed
public java.lang.String getSeed()
- See Also:
setSeed(String)
-
setShuffleOnSlave
public void setShuffleOnSlave(boolean shuffle)
Predictably shuffle tests order after balancing. This will help in spreading lighter and heavier tests over a single slave's execution timeline while still keeping the same tests order depending on the seed.
-
setProject
public void setProject(org.apache.tools.ant.Project project)
- Overrides:
setProject
in classorg.apache.tools.ant.ProjectComponent
-
setPrintSummary
public void setPrintSummary(boolean printSummary)
Prints the summary of all executed, ignored etc. tests at the end.
-
setHaltOnFailure
public void setHaltOnFailure(boolean haltOnFailure)
Stop the build process if there were failures or errors during test execution.
-
setMaxmemory
public void setMaxmemory(java.lang.String max)
Set the maximum memory to be used by all forked JVMs.- Parameters:
max
- the value as defined by -mx or -Xmx in the java command line options.
-
setLeaveTemporary
public void setLeaveTemporary(boolean leaveTemporary)
Set to true to leave temporary files for diagnostics.
-
createJvmarg
public org.apache.tools.ant.types.Commandline.Argument createJvmarg()
Add an additional argument to any forked JVM.
-
setDir
public void setDir(java.io.File dir)
The directory to invoke forked VMs in.
-
setTempDir
public void setTempDir(java.io.File tempDir)
The directory to store temporary files in.
-
setIfNoTests
public void setIfNoTests(java.lang.String value)
What to do when no tests were executed (all tests were ignored)?- See Also:
JUnit4.NoTestsAction
-
addConfiguredSysproperty
public void addConfiguredSysproperty(JUnit4.ExtendedVariable sysp)
Adds a system property to any forked JVM.
-
addConfiguredSyspropertyset
public void addConfiguredSyspropertyset(JUnit4.ExtendedPropertySet sysp)
Adds a set of properties that will be used as system properties that tests can access. This might be useful to transfer Ant properties to the testcases.
-
setJvm
public void setJvm(java.lang.String jvm)
The command used to invoke the Java Virtual Machine, default is 'java'. The command is resolved by java.lang.Runtime.exec().
-
setIsolateWorkingDirectories
public void setIsolateWorkingDirectories(boolean isolateWorkingDirectories)
If set totrue
each slave JVM gets a separate working directory under whatever is set insetDir(File)
. The directory naming for each slave follows: "Snum", where num is slave's number. Directories are created automatically and removed unlesssetLeaveTemporary(boolean)
is set totrue
.
-
setOnNonEmptyWorkDirectory
public void setOnNonEmptyWorkDirectory(java.lang.String value)
Determines the behavior on detecting non-empty existing current working directory for a forked JVM, before the tests commence. This action is performed only if work directory isolation is set to true (seesetIsolateWorkingDirectories(boolean)
).
-
addEnv
public void addEnv(JUnit4.ExtendedVariable var)
Adds an environment variable; used when forking.
-
addFileSet
public void addFileSet(org.apache.tools.ant.types.FileSet fs)
Adds a set of tests based on pattern matching.
-
add
public void add(org.apache.tools.ant.types.ResourceCollection rc)
Adds a set of tests based on pattern matching.
-
createListeners
public ListenersList createListeners()
Creates a new list of listeners.
-
addAssertions
public void addAssertions(org.apache.tools.ant.types.Assertions asserts)
Add assertions to tests execution.
-
createBalancers
public BalancersList createBalancers()
Creates a new list of balancers.
-
createClasspath
public org.apache.tools.ant.types.Path createClasspath()
Adds path to classpath used for tests.- Returns:
- reference to the classpath in the embedded java command line
-
createBootclasspath
public org.apache.tools.ant.types.Path createBootclasspath()
Adds a path to the bootclasspath.- Returns:
- reference to the bootclasspath in the embedded java command line
-
setFork
public void setFork(boolean fork)
-
setForkmode
public void setForkmode(java.lang.String forkMode)
-
setHaltOnError
public void setHaltOnError(boolean haltOnError)
-
setFiltertrace
public void setFiltertrace(boolean filterTrace)
-
setTimeout
public void setTimeout(java.lang.String v)
-
setIncludeantruntime
public void setIncludeantruntime(java.lang.String v)
-
setShowoutput
public void setShowoutput(java.lang.String v)
-
setOutputtoformatters
public void setOutputtoformatters(java.lang.String v)
-
setReloading
public void setReloading(java.lang.String v)
-
setClonevm
public void setClonevm(java.lang.String v)
-
setErrorproperty
public void setErrorproperty(java.lang.String v)
-
setLogfailedtests
public void setLogfailedtests(java.lang.String v)
-
setEnableTestListenerEvents
public void setEnableTestListenerEvents(java.lang.String v)
-
createFormatter
public java.lang.Object createFormatter()
-
createTest
public java.lang.Object createTest()
-
createBatchtest
public java.lang.Object createBatchtest()
-
warnUnsupported
private void warnUnsupported(java.lang.String attName)
-
setHeartbeat
public void setHeartbeat(long heartbeat)
Sets the heartbeat used to detect inactive/ hung forked tests (JVMs) to the given number of seconds. The heartbeat detects no-event intervals and will report them to listeners. Notably, text report report will emit heartbeat information (to a file or console).Setting the heartbeat to zero means no detection.
-
setStatsPropertyPrefix
public void setStatsPropertyPrefix(java.lang.String statsPropertyPrefix)
Sets the property prefix to which test statistics are saved.
-
execute
public void execute() throws org.apache.tools.ant.BuildException
- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.BuildException
-
listFiles
private static java.util.List<java.lang.String> listFiles(java.nio.file.Path f) throws java.io.IOException
- Throws:
java.io.IOException
-
validateArguments
private void validateArguments() throws org.apache.tools.ant.BuildException
Validate arguments.- Throws:
org.apache.tools.ant.BuildException
-
validateJUnit4
private void validateJUnit4() throws org.apache.tools.ant.BuildException
Validate JUnit4 presence in a concrete version.- Throws:
org.apache.tools.ant.BuildException
-
loadBalanceSuites
private java.util.List<java.lang.String> loadBalanceSuites(java.util.List<ForkedJvmInfo> jvmInfo, TestsCollection testsCollection, java.util.List<SuiteBalancer> balancers)
Perform load balancing of the set of suites. SetsForkedJvmInfo.testSuites
to suites preassigned to a given slave and returns a pool of suites that should be load-balanced dynamically based on job stealing.
-
sortAndSplitReplicated
private java.util.Map<java.lang.Boolean,java.util.List<java.lang.String>> sortAndSplitReplicated(java.util.List<TestClass> testClasses)
-
masterSeed
private long masterSeed()
Return the master seed ofgetSeed()
.
-
resolveFiles
private org.apache.tools.ant.types.Path resolveFiles(org.apache.tools.ant.types.Path path)
Resolve all files from a given path and simplify its definition.
-
determineForkedJvmCount
private int determineForkedJvmCount(TestsCollection testCollection)
Determine how many forked JVMs to use.
-
executeSlave
private void executeSlave(ForkedJvmInfo slave, com.google.common.eventbus.EventBus aggregatedBus) throws java.lang.Exception
Attach listeners and execute a slave process.- Throws:
java.lang.Exception
-
checkJvmOutput
private void checkJvmOutput(com.google.common.eventbus.EventBus aggregatedBus, java.nio.file.Path file, ForkedJvmInfo forked, java.lang.String fileName) throws java.io.IOException
- Throws:
java.io.IOException
-
tempFile
private java.nio.file.Path tempFile(java.lang.String uniqueSeed, java.lang.String base, java.lang.String suffix, java.nio.file.Path tempDir) throws java.io.IOException
- Throws:
java.io.IOException
-
escapeAndJoin
private java.lang.String escapeAndJoin(java.lang.String[] commandline)
Try to provide an escaped, ready-to-use shell line to repeat a given command line.
-
forkProcess
private org.apache.tools.ant.taskdefs.Execute forkProcess(ForkedJvmInfo slaveInfo, com.google.common.eventbus.EventBus eventBus, org.apache.tools.ant.types.CommandlineJava commandline, java.io.InputStream eventStream, java.io.OutputStream sysout, java.io.OutputStream syserr, java.io.RandomAccessFile streamsBuffer)
Execute a slave process. Pump events to the given event bus.
-
getWorkingDirectory
private java.nio.file.Path getWorkingDirectory(ForkedJvmInfo jvmInfo) throws java.io.IOException
- Throws:
java.io.IOException
-
getTempDir
private java.nio.file.Path getTempDir()
Resolve temporary folder.
-
processTestResources
private TestsCollection processTestResources()
Process test resources. If there are any test resources that are _not_ class files, this will cause a build error.
-
getCommandline
private org.apache.tools.ant.types.CommandlineJava getCommandline()
Returns the slave VM command line.
-
addSlaveClasspath
private org.apache.tools.ant.types.Path addSlaveClasspath()
Adds a classpath source which contains the given resource. TODO: [GH-213] this is extremely ugly; separate the code required to run on the forked JVM into an isolated bundle and either create it on-demand (in temp. files location?) or locate it in classpath somehow (in a portable way).
-
-