2 # Licensed to the Apache Software Foundation (ASF) under one or more
3 # contributor license agreements. See the NOTICE file distributed with
4 # this work for additional information regarding copyright ownership.
5 # The ASF licenses this file to You under the Apache License, Version 2.0
6 # (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # You'll need a local installation of
18 # [Apache Yetus' precommit checker](http://yetus.apache.org/documentation/0.1.0/#yetus-precommit)
19 # to use this personality.
21 # Download from: http://yetus.apache.org/downloads/ . You can either grab the source artifact and
22 # build from it, or use the convenience binaries provided on that download page.
24 # To run against, e.g. HBASE-15074 you'd then do
26 # test-patch --personality=dev-support/hbase-personality.sh HBASE-15074
29 # If you want to skip the ~1 hour it'll take to do all the hadoop API checks, use
31 # test-patch --plugins=all,-hadoopcheck --personality=dev-support/hbase-personality.sh HBASE-15074
34 # pass the `--jenkins` flag if you want to allow test-patch to destructively alter local working
35 # directory / branch in order to have things match what the issue patch requests.
37 personality_plugins
"all"
39 if ! declare -f "yetus_info" >/dev
/null
; then
43 echo "[$(date) INFO]: $*" 1>&2
48 ## @description Globals specific to this personality
50 ## @stability evolving
51 function personality_globals
54 #shellcheck disable=SC2034
56 #shellcheck disable=SC2034
57 PATCH_BRANCH_DEFAULT
=master
58 #shellcheck disable=SC2034
59 JIRA_ISSUE_RE
='^HBASE-[0-9]+$'
60 #shellcheck disable=SC2034
61 GITHUB_REPO
="apache/hbase"
63 # TODO use PATCH_BRANCH to select jdk versions to use.
65 # Override the maven options
66 MAVEN_OPTS
="${MAVEN_OPTS:-"-Xmx3100M"}"
68 # Yetus 0.7.0 enforces limits. Default proclimit is 1000.
69 # Up it. See HBASE-19902 for how we arrived at this number.
70 #shellcheck disable=SC2034
73 # Set docker container to run with 20g. Default is 4g in yetus.
74 # See HBASE-19902 for how we arrived at 20g.
75 #shellcheck disable=SC2034
79 ## @description Parse extra arguments required by personalities, if any.
81 ## @stability evolving
82 function personality_parse_args
88 --exclude-tests-url=*)
89 EXCLUDE_TESTS_URL
=${i#*=}
91 --include-tests-url=*)
92 INCLUDE_TESTS_URL
=${i#*=}
95 HADOOP_PROFILE
=${i#*=}
101 ## @description Queue up modules for this personality
103 ## @stability evolving
106 function personality_modules
111 local MODULES
=("${CHANGED_MODULES[@]}")
113 yetus_info
"Personality: ${repostatus} ${testtype}"
115 clear_personality_queue
117 extra
="-DHBasePatchProcess"
118 if [[ "${PATCH_BRANCH}" = branch-1
* ]]; then
119 extra
="${extra} -Dhttps.protocols=TLSv1.2"
122 if [[ -n "${HADOOP_PROFILE}" ]]; then
123 extra
="${extra} -Dhadoop.profile=${HADOOP_PROFILE}"
126 # BUILDMODE value is 'full' when there is no patch to be tested, and we are running checks on
127 # full source code instead. In this case, do full compiles, tests, etc instead of per
129 # Used in nightly runs.
130 # If BUILDMODE is 'patch', for unit and compile testtypes, there is no need to run individual
131 # modules if root is included. HBASE-18505
132 if [[ "${BUILDMODE}" == "full" ]] || \
133 ( ( [[ "${testtype}" == unit ]] || [[ "${testtype}" == compile ]] || [[ "${testtype}" == checkstyle
]] ) && \
134 [[ "${MODULES[*]}" =~ \.
]] ); then
138 # If the checkstyle configs change, check everything.
139 if [[ "${testtype}" == checkstyle
]] && [[ "${MODULES[*]}" =~ hbase-checkstyle
]]; then
143 if [[ ${testtype} == mvninstall
]]; then
144 # shellcheck disable=SC2086
145 personality_enqueue_module .
${extra}
149 if [[ ${testtype} == findbugs
]]; then
150 # Run findbugs on each module individually to diff pre-patch and post-patch results and
151 # report new warnings for changed modules only.
152 # For some reason, findbugs on root is not working, but running on individual modules is
153 # working. For time being, let it run on original list of CHANGED_MODULES. HBASE-19491
154 for module
in "${CHANGED_MODULES[@]}"; do
155 # skip findbugs on hbase-shell and hbase-it. hbase-it has nothing
156 # in src/main/java where findbugs goes to look
157 if [[ ${module} == hbase-shell
]]; then
159 elif [[ ${module} == hbase-it
]]; then
162 # shellcheck disable=SC2086
163 personality_enqueue_module
${module} ${extra}
169 if [[ ${testtype} == compile
]]; then
170 extra
="${extra} -PerrorProne"
173 # If EXCLUDE_TESTS_URL/INCLUDE_TESTS_URL is set, fetches the url
174 # and sets -Dtest.exclude.pattern/-Dtest to exclude/include the
175 # tests respectively.
176 if [[ ${testtype} == unit
]]; then
178 get_include_exclude_tests_arg tests_arg
179 extra
="${extra} -PrunAllTests ${tests_arg}"
181 # Inject the jenkins build-id for our surefire invocations
182 # Used by zombie detection stuff, even though we're not including that yet.
183 if [ -n "${BUILD_ID}" ]; then
184 extra
="${extra} -Dbuild.id=${BUILD_ID}"
187 # If the set of changed files includes CommonFSUtils then add the hbase-server
188 # module to the set of modules (if not already included) to be tested
189 for f
in "${CHANGED_FILES[@]}"
191 if [[ "${f}" =~ CommonFSUtils
]]; then
192 if [[ ! "${MODULES[*]}" =~ hbase-server
]] && [[ ! "${MODULES[*]}" =~ \.
]]; then
193 MODULES
+=("hbase-server")
200 for module
in "${MODULES[@]}"; do
201 # shellcheck disable=SC2086
202 personality_enqueue_module
${module} ${extra}
206 ## @description places where we override the built in assumptions about what tests to run
208 ## @stability evolving
209 ## @param filename of changed file
210 function personality_file_tests
213 yetus_debug
"HBase specific personality_file_tests"
214 # If the change is to the refguide, then we don't need any builtin yetus tests
215 # the refguide test (below) will suffice for coverage.
216 if [[ ${filename} =~ src
/main
/asciidoc
]] ||
217 [[ ${filename} =~ src
/main
/xslt
]]; then
218 yetus_debug
"Skipping builtin yetus checks for ${filename}. refguide test should pick it up."
220 # If we change our asciidoc, rebuild mvnsite
221 if [[ ${BUILDTOOL} = maven
]]; then
222 if [[ ${filename} =~ src
/site ||
${filename} =~ src
/main
/asciidoc
]]; then
223 yetus_debug
"tests/mvnsite: ${filename}"
227 # If we change checkstyle configs, run checkstyle
228 if [[ ${filename} =~ checkstyle.
*\.xml
]]; then
229 yetus_debug
"tests/checkstyle: ${filename}"
232 # fallback to checking which tests based on what yetus would do by default
233 if declare -f "${BUILDTOOL}_builtin_personality_file_tests" >/dev
/null
; then
234 "${BUILDTOOL}_builtin_personality_file_tests" "${filename}"
235 elif declare -f builtin_personality_file_tests
>/dev
/null
; then
236 builtin_personality_file_tests
"${filename}"
241 ## @description Uses relevant include/exclude env variable to fetch list of included/excluded
242 # tests and sets given variable to arguments to be passes to maven command.
244 ## @stability evolving
245 ## @param name of variable to set with maven arguments
246 function get_include_exclude_tests_arg
249 yetus_info
"EXCLUDE_TESTS_URL=${EXCLUDE_TESTS_URL}"
250 yetus_info
"INCLUDE_TESTS_URL=${INCLUDE_TESTS_URL}"
251 if [[ -n "${EXCLUDE_TESTS_URL}" ]]; then
252 if wget
"${EXCLUDE_TESTS_URL}" -O "excludes"; then
253 excludes
=$
(cat excludes
)
254 yetus_debug
"excludes=${excludes}"
255 if [[ -n "${excludes}" ]]; then
256 eval "${__resultvar}='-Dtest.exclude.pattern=${excludes}'"
260 yetus_error
"Wget error $? in fetching excludes file from url" \
261 "${EXCLUDE_TESTS_URL}. Ignoring and proceeding."
263 elif [[ -n "$INCLUDE_TESTS_URL" ]]; then
264 if wget
"$INCLUDE_TESTS_URL" -O "includes"; then
265 includes
=$
(cat includes
)
266 yetus_debug
"includes=${includes}"
267 if [[ -n "${includes}" ]]; then
268 eval "${__resultvar}='-Dtest=${includes}'"
272 yetus_error
"Wget error $? in fetching includes file from url" \
273 "${INCLUDE_TESTS_URL}. Ignoring and proceeding."
276 # Use branch specific exclude list when EXCLUDE_TESTS_URL and INCLUDE_TESTS_URL are empty
277 FLAKY_URL
="https://builds.apache.org/job/HBase-Find-Flaky-Tests/job/${PATCH_BRANCH}/lastSuccessfulBuild/artifact/excludes/"
278 if wget
"${FLAKY_URL}" -O "excludes"; then
279 excludes
=$
(cat excludes
)
280 yetus_debug
"excludes=${excludes}"
281 if [[ -n "${excludes}" ]]; then
282 eval "${__resultvar}='-Dtest.exclude.pattern=${excludes}'"
286 yetus_error
"Wget error $? in fetching excludes file from url" \
287 "${FLAKY_URL}. Ignoring and proceeding."
292 ###################################################
293 # Below here are our one-off tests specific to hbase.
294 # TODO break them into individual files so it's easier to maintain them?
296 # TODO line length check? could ignore all java files since checkstyle gets them.
298 ###################################################
300 add_test_type refguide
302 function refguide_initialize
304 maven_add_install refguide
307 function refguide_filefilter
311 if [[ ${filename} =~ src
/main
/asciidoc
]] ||
312 [[ ${filename} =~ src
/main
/xslt
]] ||
313 [[ ${filename} =~ hbase-common
/src
/main
/resources
/hbase-default.xml
]]; then
318 function refguide_rebuild
321 local logfile
="${PATCH_DIR}/${repostatus}-refguide.log"
325 if ! verify_needed_test refguide
; then
329 big_console_header
"Checking we can create the ref guide on ${repostatus}"
333 # disabled because "maven_executor" needs to return both command and args
334 # shellcheck disable=2046
335 echo_and_redirect
"${logfile}" \
336 $
(maven_executor
) clean site
--batch-mode \
338 -Dtest=NoUnitTests
-DHBasePatchProcess -Prelease \
339 -Dmaven.javadoc.skip
=true
-Dcheckstyle.skip
=true
-Dfindbugs.skip
=true
341 count
=$
(${GREP} -c '\[ERROR\]' "${logfile}")
342 if [[ ${count} -gt 0 ]]; then
343 add_vote_table
-1 refguide
"${repostatus} has ${count} errors when building the reference guide."
344 add_footer_table refguide
"@@BASE@@/${repostatus}-refguide.log"
348 if ! mv target
/site
"${PATCH_DIR}/${repostatus}-site"; then
349 add_vote_table
-1 refguide
"${repostatus} failed to produce a site directory."
350 add_footer_table refguide
"@@BASE@@/${repostatus}-refguide.log"
354 if [[ ! -f "${PATCH_DIR}/${repostatus}-site/book.html" ]]; then
355 add_vote_table
-1 refguide
"${repostatus} failed to produce the html version of the reference guide."
356 add_footer_table refguide
"@@BASE@@/${repostatus}-refguide.log"
360 if [[ "${PATCH_BRANCH}" = branch-1
* ]]; then
361 pdf_output
="book.pdf"
363 pdf_output
="apache_hbase_reference_guide.pdf"
366 if [[ ! -f "${PATCH_DIR}/${repostatus}-site/${pdf_output}" ]]; then
367 add_vote_table
-1 refguide
"${repostatus} failed to produce the pdf version of the reference guide."
368 add_footer_table refguide
"@@BASE@@/${repostatus}-refguide.log"
372 add_vote_table
0 refguide
"${repostatus} has no errors when building the reference guide. See footer for rendered docs, which you should manually inspect."
373 add_footer_table refguide
"@@BASE@@/${repostatus}-site/book.html"
377 add_test_type shadedjars
380 function shadedjars_initialize
382 yetus_debug
"initializing shaded client checks."
383 maven_add_install shadedjars
386 ## @description only run the test if java changes.
388 ## @stability evolving
390 function shadedjars_filefilter
394 if [[ ${filename} =~ \.java$
]] ||
[[ ${filename} =~ pom.xml$
]]; then
399 ## @description test the shaded client artifacts
401 ## @stability evolving
403 function shadedjars_rebuild
406 local logfile
="${PATCH_DIR}/${repostatus}-shadedjars.txt"
408 if ! verify_needed_test shadedjars
; then
412 big_console_header
"Checking shaded client builds on ${repostatus}"
416 # disabled because "maven_executor" needs to return both command and args
417 # shellcheck disable=2046
418 echo_and_redirect
"${logfile}" \
419 $
(maven_executor
) clean verify
-fae --batch-mode \
420 -pl hbase-shaded
/hbase-shaded-check-invariants
-am \
421 -Dtest=NoUnitTests
-DHBasePatchProcess -Prelease \
422 -Dmaven.javadoc.skip
=true
-Dcheckstyle.skip
=true
-Dfindbugs.skip
=true
424 count
=$
(${GREP} -c '\[ERROR\]' "${logfile}")
425 if [[ ${count} -gt 0 ]]; then
426 add_vote_table
-1 shadedjars
"${repostatus} has ${count} errors when building our shaded downstream artifacts."
427 add_footer_table shadedjars
"@@BASE@@/${repostatus}-shadedjars.txt"
431 add_vote_table
+1 shadedjars
"${repostatus} has no errors when building our shaded downstream artifacts."
435 ###################################################
437 add_test_type hadoopcheck
439 ## @description hadoopcheck file filter
441 ## @stability evolving
443 function hadoopcheck_filefilter
447 if [[ ${filename} =~ \.java$
]] ||
[[ ${filename} =~ pom.xml$
]]; then
452 ## @description Parse args to detect if QUICK_HADOOPCHECK mode is enabled.
454 ## @stability evolving
455 function hadoopcheck_parse_args
462 QUICK_HADOOPCHECK
=true
468 ## @description Adds QUICK_HADOOPCHECK env variable to DOCKER_EXTRAARGS.
470 ## @stability evolving
471 function hadoopcheck_docker_support
473 DOCKER_EXTRAARGS
=("${DOCKER_EXTRAARGS[@]}" "--env=QUICK_HADOOPCHECK=${QUICK_HADOOPCHECK}")
476 ## @description hadoopcheck test
478 ## @stability evolving
480 function hadoopcheck_rebuild
487 local hbase_hadoop2_versions
488 local hbase_hadoop3_versions
490 if [[ "${repostatus}" = branch
]]; then
494 if ! verify_needed_test hadoopcheck
; then
498 big_console_header
"Compiling against various Hadoop versions"
502 # All supported Hadoop versions that we want to test the compilation with
503 # See the Hadoop section on prereqs in the HBase Reference Guide
504 hbase_common_hadoop2_versions
="2.7.1 2.7.2 2.7.3 2.7.4"
505 if [[ "${PATCH_BRANCH}" = branch-1.
* ]] && [[ "${PATCH_BRANCH#branch-1.}" -lt "5" ]]; then
506 yetus_info
"Setting Hadoop 2 versions to test based on before-branch-1.5 rules."
507 if [[ "${QUICK_HADOOPCHECK}" == "true" ]]; then
508 hbase_hadoop2_versions
="2.4.1 2.5.2 2.6.5 2.7.4"
510 hbase_hadoop2_versions
="2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 ${hbase_common_hadoop2_versions}"
512 elif [[ "${PATCH_BRANCH}" = branch-2.0
]]; then
513 yetus_info
"Setting Hadoop 2 versions to test based on branch-2.0 rules."
514 if [[ "${QUICK_HADOOPCHECK}" == "true" ]]; then
515 hbase_hadoop2_versions
="2.6.5 2.7.4"
517 hbase_hadoop2_versions
="2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 ${hbase_common_hadoop2_versions}"
520 yetus_info
"Setting Hadoop 2 versions to test based on branch-1.5+/branch-2.1+/master/feature branch rules."
521 if [[ "${QUICK_HADOOPCHECK}" == "true" ]]; then
522 hbase_hadoop2_versions
="2.7.4"
524 hbase_hadoop2_versions
="${hbase_common_hadoop2_versions}"
527 hbase_hadoop3_versions
="3.0.0"
528 if [[ "${PATCH_BRANCH}" = branch-1
* ]]; then
529 hbase_hadoop3_versions
=""
532 export MAVEN_OPTS
="${MAVEN_OPTS}"
533 for hadoopver
in ${hbase_hadoop2_versions}; do
534 logfile
="${PATCH_DIR}/patch-javac-${hadoopver}.txt"
535 # disabled because "maven_executor" needs to return both command and args
536 # shellcheck disable=2046
537 echo_and_redirect
"${logfile}" \
538 $
(maven_executor
) clean
install \
539 -DskipTests -DHBasePatchProcess \
540 -Dhadoop-two.version
="${hadoopver}"
541 count
=$
(${GREP} -c '\[ERROR\]' "${logfile}")
542 if [[ ${count} -gt 0 ]]; then
543 add_vote_table
-1 hadoopcheck
"${BUILDMODEMSG} causes ${count} errors with Hadoop v${hadoopver}."
544 add_footer_table hadoopcheck
"@@BASE@@/patch-javac-${hadoopver}.txt"
549 for hadoopver
in ${hbase_hadoop3_versions}; do
550 logfile
="${PATCH_DIR}/patch-javac-${hadoopver}.txt"
551 # disabled because "maven_executor" needs to return both command and args
552 # shellcheck disable=2046
553 echo_and_redirect
"${logfile}" \
554 $
(maven_executor
) clean
install \
555 -DskipTests -DHBasePatchProcess \
556 -Dhadoop-three.version
="${hadoopver}" \
558 count
=$
(${GREP} -c '\[ERROR\]' "${logfile}")
559 if [[ ${count} -gt 0 ]]; then
560 add_vote_table
-1 hadoopcheck
"${BUILDMODEMSG} causes ${count} errors with Hadoop v${hadoopver}."
561 add_footer_table hadoopcheck
"@@BASE@@/patch-javac-${hadoopver}.txt"
566 if [[ ${result} -gt 0 ]]; then
570 if [[ -n "${hbase_hadoop3_versions}" ]]; then
571 add_vote_table
+1 hadoopcheck
"Patch does not cause any errors with Hadoop ${hbase_hadoop2_versions} or ${hbase_hadoop3_versions}."
573 add_vote_table
+1 hadoopcheck
"Patch does not cause any errors with Hadoop ${hbase_hadoop2_versions}."
578 ######################################
580 # TODO if we need the protoc check, we probably need to check building all the modules that rely on hbase-protocol
581 add_test_type hbaseprotoc
583 ## @description hbaseprotoc file filter
585 ## @stability evolving
587 function hbaseprotoc_filefilter
591 if [[ ${filename} =~ \.proto$
]]; then
596 ## @description check hbase proto compilation
598 ## @stability evolving
600 function hbaseprotoc_rebuild
602 declare repostatus
=$1
610 if [[ "${repostatus}" = branch
]]; then
614 if ! verify_needed_test hbaseprotoc
; then
618 big_console_header
"HBase protoc plugin: ${BUILDMODE}"
622 personality_modules
patch hbaseprotoc
623 # Need to run 'install' instead of 'compile' because shading plugin
624 # is hooked-up to 'install'; else hbase-protocol-shaded is left with
625 # half of its process done.
626 modules_workers
patch hbaseprotoc
install -DskipTests -X -DHBasePatchProcess
628 # shellcheck disable=SC2153
629 until [[ $i -eq "${#MODULE[@]}" ]]; do
630 if [[ ${MODULE_STATUS[${i}]} == -1 ]]; then
636 fn
=$
(module_file_fragment
"${module}")
637 logfile
="${PATCH_DIR}/patch-hbaseprotoc-${fn}.txt"
639 count
=$
(${GREP} -c '\[ERROR\]' "${logfile}")
641 if [[ ${count} -gt 0 ]]; then
642 module_status
${i} -1 "patch-hbaseprotoc-${fn}.txt" "Patch generated "\
643 "${count} new protoc errors in ${module}."
649 modules_messages
patch hbaseprotoc true
650 if [[ ${result} -gt 0 ]]; then
656 ######################################
658 add_test_type hbaseanti
660 ## @description hbaseanti file filter
662 ## @stability evolving
664 function hbaseanti_filefilter
668 if [[ ${filename} =~ \.java$
]]; then
673 ## @description hbaseanti patch file check
675 ## @stability evolving
677 function hbaseanti_patchfile
683 if [[ "${BUILDMODE}" = full
]]; then
687 if ! verify_needed_test hbaseanti
; then
691 big_console_header
"Checking for known anti-patterns"
695 warnings
=$
(${GREP} -c 'new TreeMap<byte.*()' "${patchfile}")
696 if [[ ${warnings} -gt 0 ]]; then
697 add_vote_table
-1 hbaseanti
"" "The patch appears to have anti-pattern where BYTES_COMPARATOR was omitted."
701 if [[ ${result} -gt 0 ]]; then
705 add_vote_table
+1 hbaseanti
"" "Patch does not have any anti-patterns."
709 ## This is named so that yetus will check us right after running tests.
710 ## Essentially, we check for normal failures and then we look for zombies.
711 #function hbase_unit_logfilter
713 # declare testtype="unit"
717 # declare process_output
719 # declare zombie_count=0
720 # declare zombie_process
722 # yetus_debug "in hbase-specific unit logfilter."
724 # # pass-through to whatever is counting actual failures
725 # if declare -f ${BUILDTOOL}_${testtype}_logfilter >/dev/null; then
726 # "${BUILDTOOL}_${testtype}_logfilter" "${input}" "${output}"
727 # elif declare -f ${testtype}_logfilter >/dev/null; then
728 # "${testtype}_logfilter" "${input}" "${output}"
732 # if [ -n "${BUILD_ID}" ]; then
733 # yetus_debug "Checking for zombie test processes."
734 # processes=$(jps -v | "${GREP}" surefirebooter | "${GREP}" -e "hbase.build.id=${BUILD_ID}")
735 # if [ -n "${processes}" ] && [ "$(echo "${processes}" | wc -l)" -gt 0 ]; then
736 # yetus_warn "Found some suspicious process(es). Waiting a bit to see if they're just slow to stop."
737 # yetus_debug "${processes}"
739 # #shellcheck disable=SC2016
740 # for pid in $(echo "${processes}"| ${AWK} '{print $1}'); do
741 # # Test our zombie still running (and that it still an hbase build item)
742 # process_output=$(ps -p "${pid}" | tail +2 | "${GREP}" -e "hbase.build.id=${BUILD_ID}")
743 # if [[ -n "${process_output}" ]]; then
744 # yetus_error "Zombie: ${process_output}"
745 # ((zombie_count = zombie_count + 1))
746 # zombie_process=$(jstack "${pid}" | "${GREP}" -e "\.Test" | "${GREP}" -e "\.java"| head -3)
747 # zombies="${zombies} ${zombie_process}"
751 # if [ "${zombie_count}" -ne 0 ]; then
752 # add_vote_table -1 zombies "There are ${zombie_count} zombie test(s)"
753 # populate_test_table "zombie unit tests" "${zombies}"
755 # yetus_info "Zombie check complete. All test runs exited normally."
759 # add_vote_table -0 zombies "There is no BUILD_ID env variable; can't check for zombies."