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"
29 echo " --hadoop-profile profile specify a value passed via -Dhadoop.profile"
33 declare -i force_timeout
=7200
34 declare fork_count
="0.5C"
36 declare maven_repo
="${HOME}/.m2/repository"
38 declare hadoop_profile
42 --force-timeout) shift; force_timeout
=$1; shift;;
43 --maven-local-repo) shift; maven_repo
=$1; shift;;
44 --repeat) shift; attempts
=$1; shift;;
45 --log-output) shift; output
=$1; shift;;
46 --surefire-fork-count) shift; fork_count
=$1; shift;;
47 --hadoop-profile) shift; hadoop_profile
=$1; shift;;
50 *) break;; # terminate while loop
54 if [ "$#" -lt 1 ]; then
60 declare testmaybepattern
=$1
62 while IFS
= read -r -d $
'\0' path
; do
63 while [ -n "${path}" ]; do
64 path
=$
(dirname "${path}")
65 if [ -f "${path}/pom.xml" ]; then
70 done < <(find .
-name "${testmaybepattern}.java" -a -type f
-a -not -path '*/target/*' -print0)
73 function echo_run_redirect
78 "${@}" >>"${log}" 2>&1
83 for test in "${@}"; do
84 for module
in $
(find_modules
"${test}"); do
85 if [[ ! "${modules[*]}" =~
${module} ]]; then
86 echo "adding module '${module}' to set."
87 modules
+=("${module}")
92 declare -a mvn_module_arg
93 for module
in "${modules[@]}"; do
94 mvn_module_arg
+=(-pl "${module}")
98 declare -a maven_args
=('--batch-mode' "-Dmaven.repo.local=${maven_repo}" "-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}" test)
102 if [[ -n "${hadoop_profile}" ]] ; then
103 maven_args
+=("-Dhadoop.profile=${hadoop_profile}")
106 if [[ ! -d "${output}" ]] ; then
110 for attempt
in $
(seq "${attempts}"); do
111 echo "Attempt ${attempt}" >&2
112 echo_run_redirect
"${output}/mvn_test.log" mvn
"${maven_args[@]}"