HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / dev-support / adhoc_run_tests / adhoc_run_tests.sh
blobfad7fffcdb2cb940f9cd9de903097244d6fec7f9
1 #!/usr/bin/env bash
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
17 # under the License.
19 set -e
20 function usage {
21 echo "Usage: ${0} [options] TestSomeTestName [TestOtherTest...]"
22 echo ""
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"
30 exit 1
32 # Get arguments
33 declare -i force_timeout=7200
34 declare fork_count="0.5C"
35 declare -i attempts=1
36 declare maven_repo="${HOME}/.m2/repository"
37 declare output="."
38 declare hadoop_profile
39 while [ $# -gt 0 ]
41 case "$1" in
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;;
48 --) shift; break;;
49 -*) usage ;;
50 *) break;; # terminate while loop
51 esac
52 done
54 if [ "$#" -lt 1 ]; then
55 usage
58 function find_modules
60 declare testmaybepattern=$1
61 declare path
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
66 echo "${path}"
67 break
69 done
70 done < <(find . -name "${testmaybepattern}.java" -a -type f -a -not -path '*/target/*' -print0)
73 function echo_run_redirect
75 declare log=$1
76 shift
77 echo "${*}" >"${log}"
78 "${@}" >>"${log}" 2>&1
81 declare -a modules
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}")
89 done
90 done
92 declare -a mvn_module_arg
93 for module in "${modules[@]}"; do
94 mvn_module_arg+=(-pl "${module}")
95 done
97 declare tests="${*}"
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
107 mkdir -p "${output}"
110 for attempt in $(seq "${attempts}"); do
111 echo "Attempt ${attempt}" >&2
112 echo_run_redirect "${output}/mvn_test.log" mvn "${maven_args[@]}"
113 done