2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
21 echo "Usage: ${0} [options] TestSomeTestName [TestOtherTest...]"
23 echo " --repeat times number of times to repeat if successful"
24 echo " --force-timeout seconds Seconds to wait before killing a given test run."
25 echo " --maven-local-repo /path/to/use Path for maven artifacts while building"
26 echo " --surefire-fork-count set the fork-count. only useful if multiple " \
27 "tests running (default 0.5C)"
28 echo " --log-output /path/to/use path to directory to hold attempt log"
32 declare -i force_timeout
=7200
33 declare fork_count
="0.5C"
35 declare maven_repo
="${HOME}/.m2/repository"
40 --force-timeout) shift; force_timeout
=$1; shift;;
41 --maven-local-repo) shift; maven_repo
=$1; shift;;
42 --repeat) shift; attempts
=$1; shift;;
43 --log-output) shift; output
=$1; shift;;
44 --surefire-fork-count) shift; fork_count
=$1; shift;;
47 *) break;; # terminate while loop
51 if [ "$#" -lt 1 ]; then
57 declare testmaybepattern
=$1
59 while IFS
= read -r -d $
'\0' path
; do
60 while [ -n "${path}" ]; do
61 path
=$
(dirname "${path}")
62 if [ -f "${path}/pom.xml" ]; then
67 done < <(find .
-name "${testmaybepattern}.java" -a -type f
-a -not -path '*/target/*' -print0)
70 function echo_run_redirect
75 "${@}" >>"${log}" 2>&1
80 for test in "${@}"; do
81 for module
in $
(find_modules
"${test}"); do
82 if [[ ! "${modules[*]}" =~
${module} ]]; then
83 echo "adding module '${module}' to set."
89 declare -a mvn_module_arg
91 for module
in "${modules[@]}"; do
92 mvn_module_arg
+=(-pl "${module}")
95 for attempt
in $
(seq "${attempts}"); do
96 echo "Attempt ${attempt}" >&2
97 echo_run_redirect
"${output}/mvn_test.log" mvn
--batch-mode -Dmaven.repo.
local="${maven_repo}" \
98 -Dtest="${tests// /,}" \
99 -Dsurefire.rerunFailingTestsCount
=0 -Dsurefire.parallel.forcedTimeout
="${force_timeout}" \
100 -Dsurefire.shutdown
=kill -DtrimStackTrace=false
-am "${mvn_module_arg[@]}" \
101 -DforkCount="${fork_count}" package