verify-xml.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env bash
  2. ##
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ##
  19. # Script to run unit tests for xml <-> 1 or more Configuration file verification
  20. # usage: ./verify-xml.sh <mode>
  21. #
  22. # Utility functions
  23. function find_test_output_file() {
  24. echo "Found test output file(s) at"
  25. echo ""
  26. if [ -n "$1" ] && [ -e "$1" ] ; then
  27. echo " $1"
  28. fi
  29. if [ -n "$2" ] && [ -e "$2" ] ; then
  30. echo " $2"
  31. fi
  32. if [ -n "$3" ] && [ -e "$3" ] ; then
  33. echo " $3"
  34. fi
  35. if [ -n "$4" ] && [ -e "$4" ] ; then
  36. echo " $4"
  37. fi
  38. echo ""
  39. echo "Examine the file for specific information xml/Configuration mismatches."
  40. echo ""
  41. }
  42. function print_test_banner() {
  43. local banner_text=$1
  44. local banner_length=${#banner_text}
  45. local banner
  46. banner=$( printf "%${banner_length}s" ' ' )
  47. echo ""
  48. echo "${banner// /=}"
  49. echo "${banner_text}"
  50. echo "${banner// /=}"
  51. echo ""
  52. }
  53. # Wrapper functions for running unit tests
  54. function run_all_xml_test() {
  55. mvn test -Dtest=TestCommonConfigurationFields,TestHdfsConfigFields,TestMapreduceConfigFields,TestYarnConfigurationFields
  56. if [ $? -ne 0 ] ; then
  57. print_test_banner "All Test*ConfigFields FAIL"
  58. else
  59. print_test_banner "All Test*ConfigFields SUCCESS"
  60. fi
  61. }
  62. function run_common_xml_test() {
  63. mvn test -Dtest=TestCommonConfigFields
  64. if [ $? -ne 0 ] ; then
  65. print_test_banner "TestCommonConfigurationFields FAIL"
  66. else
  67. print_test_banner "TestCommonConfigurationFields SUCCESS"
  68. fi
  69. }
  70. function run_hdfs_xml_test() {
  71. mvn test -Dtest=TestHdfsConfigFields
  72. if [ $? -ne 0 ] ; then
  73. print_test_banner "TestHdfsConfigFields FAIL"
  74. else
  75. print_test_banner "TestHdfsConfigFields SUCCESS"
  76. fi
  77. }
  78. function run_mapreduce_xml_test() {
  79. mvn test -Dtest=TestMapreduceConfigFields
  80. if [ $? -ne 0 ] ; then
  81. print_test_banner "TestMapreduceConfigFields FAIL"
  82. else
  83. print_test_banner "TestMapreduceConfigFields SUCCESS"
  84. fi
  85. }
  86. function run_yarn_xml_test() {
  87. mvn test -Dtest=TestYarnConfigurationFields
  88. if [ $? -ne 0 ] ; then
  89. print_test_banner "TestYarnConfigurationFields FAIL"
  90. else
  91. print_test_banner "TestYarnConfigurationFields SUCCESS"
  92. fi
  93. }
  94. # Main body
  95. cd -P -- "$(dirname -- "${BASH_SOURCE-$0}")/.." || exit
  96. dir="$(pwd -P)"
  97. # - Create unit test file names
  98. export commonOutputFile
  99. commonOutputFile="$(find "${dir}" -name org.apache.hadoop.conf.TestCommonConfigurationFields-output.txt)"
  100. export hdfsOutputFile
  101. hdfsOutputFile="$(find "${dir}" -name org.apache.hadoop.tools.TestHdfsConfigFields-output.txt)"
  102. export mrOutputFile
  103. mrOutputFile="$(find "${dir}" -name org.apache.hadoop.mapreduce.TestMapreduceConfigFields-output.txt)"
  104. export yarnOutputFile
  105. yarnOutputFile="$(find "${dir}" -name org.apache.hadoop.yarn.conf.TestYarnConfigurationFields-output.txt)"
  106. # - Determine which tests to run
  107. case "$1" in
  108. all)
  109. run_all_xml_test
  110. find_test_output_file "${commonOutputFile}" "${hdfsOutputFile}" "${mrOutputFile}" "${yarnOutputFile}"
  111. ;;
  112. common)
  113. run_common_xml_test
  114. find_test_output_file "${commonOutputFile}"
  115. ;;
  116. hdfs)
  117. run_hdfs_xml_test
  118. find_test_output_file "${hdfsOutputFile}"
  119. ;;
  120. mr)
  121. run_mapreduce_xml_test
  122. find_test_output_file "${mrOutputFile}"
  123. ;;
  124. yarn)
  125. run_yarn_xml_test
  126. find_test_output_file "${yarnOutputFile}"
  127. ;;
  128. *)
  129. echo "Usage: $0 <mode>"
  130. echo " where <mode> is one of all, common, hdfs, mr, yarn"
  131. exit 1
  132. ;;
  133. esac