diff --git a/bin/common_gradle.sh b/bin/common_gradle.sh index 2c873fe319d..f009ac9259d 100755 --- a/bin/common_gradle.sh +++ b/bin/common_gradle.sh @@ -155,7 +155,7 @@ is_released_binary() { find_module_jar_at() { DIR=$1 MODULE=$2 - REGEX="^${MODULE}-[0-9\\.]*((-[a-zA-Z]*(-[0-9]*)?)|(-SNAPSHOT))?.jar$" + REGEX="^${MODULE}.jar$" if [ -d ${DIR} ]; then cd ${DIR} for f in *.jar; do @@ -222,7 +222,7 @@ add_maven_deps_to_classpath() { # Need to generate classpath from maven pom. This is costly so generate it # and cache it. Save the file into our target dir so a mvn clean will get # clean it up and force us create a new one. - f="${BK_HOME}/${MODULE_PATH}/build/cached_classpath.txt" + f="${BK_HOME}/${MODULE_PATH}/build/classpath.txt" if [ ! -f ${f} ]; then echo "the classpath of module '${MODULE_PATH}' is not found, generating it ..." >&2 ${BK_HOME}/gradlew ${MODULE_PATH}:jar @@ -240,7 +240,7 @@ set_module_classpath() { echo ${BK_CLASSPATH} else add_maven_deps_to_classpath ${MODULE_PATH} >&2 - cat ${BK_HOME}/${MODULE_PATH}/build/cached_classpath.txt + cat ${BK_HOME}/${MODULE_PATH}/build/classpath.txt fi return } diff --git a/tests/scripts/build.gradle b/tests/scripts/build.gradle index bffbc2df9ad..d15c9411cc1 100644 --- a/tests/scripts/build.gradle +++ b/tests/scripts/build.gradle @@ -31,9 +31,8 @@ task extractShunit2(dependsOn: downloadShunit2, type: Copy) { } task executeShTests(dependsOn: extractShunit2, type: Exec) { - workingDir "src/test/bash" + workingDir "src/test/bash/gradle" commandLine "./bk_test.sh" - args "-e PROJECT_BUILD_SYSTEM=gradle" } tasks.test.dependsOn("executeShTests") diff --git a/tests/scripts/src/test/bash/bk_test_bin_common.sh b/tests/scripts/src/test/bash/bk_test_bin_common.sh index c0fc934e7c7..e41455cbf26 100644 --- a/tests/scripts/src/test/bash/bk_test_bin_common.sh +++ b/tests/scripts/src/test/bash/bk_test_bin_common.sh @@ -19,16 +19,6 @@ # * See the License for the specific language governing permissions and # * limitations under the License. # */ -PROJECT_BUILD_SYSTEM=${PROJECT_BUILD_SYSTEM:-maven} -if [[ $PROJECT_BUILD_SYSTEM == "gradle" ]]; then - PROJECT_TARGET_DIR=build/libs - TEST_CLASSPATH_DIR=build - BK_COMMON_EXEC=common_gradle.sh -else - PROJECT_TARGET_DIR=target - TEST_CLASSPATH_DIR=target - BK_COMMON_EXEC=common.sh -fi # load test helpers . ./bk_test_helpers @@ -38,7 +28,7 @@ fi # testDefaultVariables() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh assertEquals "BINDIR is not set correctly" "${BK_BINDIR}" "${BINDIR}" assertEquals "BK_HOME is not set correctly" "${BK_HOMEDIR}" "${BK_HOME}" assertEquals "DEFAULT_LOG_CONF is not set correctly" "${BK_CONFDIR}/log4j.properties" "${DEFAULT_LOG_CONF}" @@ -59,7 +49,7 @@ testDefaultVariables() { } testFindModuleJarAt() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh MODULE="test-module" @@ -124,7 +114,7 @@ testFindModuleJar() { echo "" > ${BK_HOME}/conf/bkenv.sh echo "" > ${BK_HOME}/conf/bk_cli_env.sh - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh MODULE="test-module" MODULE_PATH="testmodule" @@ -133,7 +123,7 @@ testFindModuleJar() { TEST_FILES=( "${MODULE}-${VERSION}.jar" "lib/${MODULE}-${VERSION}.jar" - "${MODULE_PATH}/${PROJECT_TARGET_DIR}/${MODULE}-${VERSION}.jar" + "${MODULE_PATH}/target/${MODULE}-${VERSION}.jar" ) count=0 while [ "x${TEST_FILES[count]}" != "x" ] @@ -169,8 +159,8 @@ testLoadEnvfiles() { echo "BOOKIE_MAX_HEAP_MEMORY=2048M" > ${BK_HOME}/conf/bkenv.sh echo "CLI_MAX_HEAP_MEMORY=2048M" > ${BK_HOME}/conf/bk_cli_env.sh - # load the ${BK_COMMON_EXEC} - source ${BK_BINDIR}/${BK_COMMON_EXEC} + # load the common.sh + source ${BK_BINDIR}/common.sh assertEquals "NETTY_LEAK_DETECTION_LEVEL is not set correctly" "enabled" "${NETTY_LEAK_DETECTION_LEVEL}" assertEquals "BOOKIE_MAX_HEAP_MEMORY is not set correctly" "2048M" "${BOOKIE_MAX_HEAP_MEMORY}" @@ -193,19 +183,19 @@ testSetModuleClasspath() { echo "" > ${BK_HOME}/conf/bkenv.sh echo "" > ${BK_HOME}/conf/bk_cli_env.sh - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh MODULE_PATH="testmodule" - mkdir -p ${BK_HOME}/${MODULE_PATH}/${TEST_CLASSPATH_DIR} - echo "test-classpath" > ${BK_HOME}/${MODULE_PATH}/${TEST_CLASSPATH_DIR}/cached_classpath.txt + mkdir -p ${BK_HOME}/${MODULE_PATH}/target + echo "test-classpath" > ${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt local result=$(set_module_classpath ${MODULE_PATH}) assertEquals "test-classpath" ${result} } testBuildBookieJVMOpts() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh TEST_LOG_DIR=${BK_TMPDIR}/logdir TEST_GC_LOG_FILENAME="test-gc.log" @@ -220,7 +210,7 @@ testBuildBookieJVMOpts() { } testBuildCLIJVMOpts() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh TEST_LOG_DIR=${BK_TMPDIR}/logdir TEST_GC_LOG_FILENAME="test-gc.log" @@ -235,7 +225,7 @@ testBuildCLIJVMOpts() { } testBuildNettyOpts() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh ACTUAL_NETTY_OPTS=$(build_netty_opts) EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled \ @@ -246,7 +236,7 @@ testBuildNettyOpts() { } testBuildBookieOpts() { - source ${BK_BINDIR}/${BK_COMMON_EXEC} + source ${BK_BINDIR}/common.sh ACTUAL_OPTS=$(build_bookie_opts) EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true" diff --git a/tests/scripts/src/test/bash/bk_test_helpers b/tests/scripts/src/test/bash/bk_test_helpers index 8620c876d5a..6f43e79d1ac 100644 --- a/tests/scripts/src/test/bash/bk_test_helpers +++ b/tests/scripts/src/test/bash/bk_test_helpers @@ -24,7 +24,7 @@ BK_ARGV0=`basename "$0"` # path to shUnit2 library. can be overridden by setting BK_SHUNIT_INC. -BK_SHUNIT=${BK_SHUNIT_INC:-../../../${PROJECT_TARGET_DIR}/lib/shunit2-2.1.7/shunit2} +BK_SHUNIT=${BK_SHUNIT_INC:-../../../target/lib/shunit2-2.1.7/shunit2} # path to bk bin directory. TESTDIR=`dirname "$0"` diff --git a/tests/scripts/src/test/bash/gradle/bk_test.sh b/tests/scripts/src/test/bash/gradle/bk_test.sh new file mode 100755 index 00000000000..3c7b02e6fe1 --- /dev/null +++ b/tests/scripts/src/test/bash/gradle/bk_test.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +# +# vim:et:ft=sh:sts=2:sw=2 +# +#/** +# * Licensed to the Apache Software Foundation (ASF) under one +# * or more contributor license agreements. See the NOTICE file +# * distributed with this work for additional information +# * regarding copyright ownership. The ASF licenses this file +# * to you under the Apache License, Version 2.0 (the +# * "License"); you may not use this file except in compliance +# * with the License. You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# */ + +ARGV0=`basename "$0"` +PREFIX="bk_test_" +SHELLS="/bin/sh /bin/bash" + +find_tests_at() { + DIR=$1 + PREF=$2 + REGEX="^${PREF}[a-z_]*.sh$" + RESULTS="" + if [ -d ${DIR} ]; then + cd ${DIR} + for f in *.sh; do + if [[ ${f} =~ ${REGEX} ]]; then + RESULTS="${RESULTS} ${f}" + fi + done + fi + echo ${RESULTS} +} + +TESTS=$(find_tests_at "." ${PREFIX}) + +# load common unit test functions +source ./versions +source ./bk_test_helpers + +usage() { + echo "usage: ${ARGV0} [-e key=val ...] [-s shell(s)] [-t test(s)]" +} + +env='' + +# process command line flags +while getopts 'e:hs:t:' opt; do + case ${opt} in + e) # set an environment variable + key=`expr "${OPTARG}" : '\([^=]*\)='` + val=`expr "${OPTARG}" : '[^=]*=\(.*\)'` + if [ -z "${key}" -o -z "${val}" ]; then + usage + exit 1 + fi + eval "${key}='${val}'" + export ${key} + env="${env:+${env} }${key}" + ;; + h) usage; exit 0 ;; # output help + s) shells=${OPTARG} ;; # list of shells to run + t) tests=${OPTARG} ;; # list of tests to run + *) usage; exit 1 ;; + esac +done +shift `expr ${OPTIND} - 1` + +# fill shells and/or tests +shells=${shells:-${SHELLS}} +tests=${tests:-${TESTS}} + +# error checking +if [ -z "${tests}" ]; then + bk_info 'no tests found to run; exiting' + exit 0 +fi + +# print run info +cat <&1; ) + done +done diff --git a/tests/scripts/src/test/bash/gradle/bk_test_bin_common.sh b/tests/scripts/src/test/bash/gradle/bk_test_bin_common.sh new file mode 100644 index 00000000000..4a70df9771e --- /dev/null +++ b/tests/scripts/src/test/bash/gradle/bk_test_bin_common.sh @@ -0,0 +1,263 @@ +#!/usr/bin/env bash +# +# vim:et:ft=sh:sts=2:sw=2 +# +#/** +# * Licensed to the Apache Software Foundation (ASF) under one +# * or more contributor license agreements. See the NOTICE file +# * distributed with this work for additional information +# * regarding copyright ownership. The ASF licenses this file +# * to you under the Apache License, Version 2.0 (the +# * "License"); you may not use this file except in compliance +# * with the License. You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# */ +# load test helpers +. ./bk_test_helpers_gradle + +#------------------------------------------------------------------------------ +# suite tests +# + +testDefaultVariables() { + source ${BK_BINDIR}/common_gradle.sh + assertEquals "BINDIR is not set correctly" "${BK_BINDIR}" "${BINDIR}" + assertEquals "BK_HOME is not set correctly" "${BK_HOMEDIR}" "${BK_HOME}" + assertEquals "DEFAULT_LOG_CONF is not set correctly" "${BK_CONFDIR}/log4j.properties" "${DEFAULT_LOG_CONF}" + assertEquals "NETTY_LEAK_DETECTION_LEVEL is not set correctly" "disabled" "${NETTY_LEAK_DETECTION_LEVEL}" + assertEquals "NETTY_RECYCLER_MAXCAPACITY is not set correctly" "1000" "${NETTY_RECYCLER_MAXCAPACITY}" + assertEquals "NETTY_RECYCLER_LINKCAPACITY is not set correctly" "1024" "${NETTY_RECYCLER_LINKCAPACITY}" + assertEquals "BOOKIE_MAX_HEAP_MEMORY is not set correctly" "1g" "${BOOKIE_MAX_HEAP_MEMORY}" + assertEquals "BOOKIE_MIN_HEAP_MEMORY is not set correctly" "1g" "${BOOKIE_MIN_HEAP_MEMORY}" + assertEquals "BOOKIE_MAX_DIRECT_MEMORY is not set correctly" "2g" "${BOOKIE_MAX_DIRECT_MEMORY}" + assertEquals "BOOKIE_MEM_OPTS is not set correctly" "-Xms1g -Xmx1g -XX:MaxDirectMemorySize=2g" "${BOOKIE_MEM_OPTS}" + assertEquals "BOOKIE_GC_OPTS is not set correctly" "${DEFAULT_BOOKIE_GC_OPTS}" "${BOOKIE_GC_OPTS}" + assertEquals "BOOKIE_GC_LOGGING_OPTS is not set correctly" "${DEFAULT_BOOKIE_GC_LOGGING_OPTS}" "${BOOKIE_GC_LOGGING_OPTS}" + assertEquals "CLI_MAX_HEAP_MEMORY is not set correctly" "512M" "${CLI_MAX_HEAP_MEMORY}" + assertEquals "CLI_MIN_HEAP_MEMORY is not set correctly" "256M" "${CLI_MIN_HEAP_MEMORY}" + assertEquals "CLI_MEM_OPTS is not set correctly" "-Xms256M -Xmx512M" "${CLI_MEM_OPTS}" + assertEquals "CLI_GC_OPTS is not set correctly" "${DEFAULT_CLI_GC_OPTS}" "${CLI_GC_OPTS}" + assertEquals "CLI_GC_LOGGING_OPTS is not set correctly" "${DEFAULT_CLI_GC_LOGGING_OPTS}" "${CLI_GC_LOGGING_OPTS}" +} + +testFindModuleJarAt() { + source ${BK_BINDIR}/common_gradle.sh + + MODULE="test-module" + + # case 1: empty dir + TEST_DIR1=${BK_TMPDIR}/testdir1 + mkdir -p ${TEST_DIR1} + MODULE_JAR1=$(find_module_jar_at ${TEST_DIR1} ${MODULE}) + assertEquals "No module jar should be found at empty dir" "" "${MODULE_JAR1}" + + # case 2: SNAPSHOT jar + TEST_FILES=( + "invalid-${MODULE}.jar" + "invalid-${MODULE}-4.8.0.jar" + "invalid-${MODULE}-4.8.0-SNAPSHOT.jar" + "${MODULE}.jar.invalid" + "${MODULE}-4.8.0.jar.invalid" + "${MODULE}-4.8.0-SNAPSHOT.jar.invalid" + "${MODULE}.jar" + "${MODULE}-4.8.0-SNAPSHOT.jar" + ) + + TEST_DIR2=${BK_TMPDIR}/testdir2 + mkdir -p ${TEST_DIR2} + count=0 + while [ "x${TEST_FILES[count]}" != "x" ] + do + touch ${TEST_DIR2}/${TEST_FILES[count]} + count=$(( $count + 1 )) + done + MODULE_JAR2=$(find_module_jar_at ${TEST_DIR2} ${MODULE}) + assertEquals "${MODULE}-4.8.0-SNAPSHOT.jar is not found" "${TEST_DIR2}/${MODULE}-4.8.0-SNAPSHOT.jar" "${MODULE_JAR2}" + + # case 3: release jar + TEST_FILES=( + "invalid-${MODULE}.jar" + "invalid-${MODULE}-4.8.0.jar" + "invalid-${MODULE}-4.8.0-SNAPSHOT.jar" + "${MODULE}.jar.invalid" + "${MODULE}-4.8.0.jar.invalid" + "${MODULE}-4.8.0-SNAPSHOT.jar.invalid" + "${MODULE}.jar" + "${MODULE}-4.8.0.jar" + ) + + TEST_DIR3=${BK_TMPDIR}/testdir3 + mkdir -p ${TEST_DIR3} + count=0 + while [ "x${TEST_FILES[count]}" != "x" ] + do + touch ${TEST_DIR3}/${TEST_FILES[count]} + count=$(( $count + 1 )) + done + MODULE_JAR3=$(find_module_jar_at ${TEST_DIR3} ${MODULE}) + assertEquals "${MODULE}-4.8.0.jar is not found" "${TEST_DIR3}/${MODULE}-4.8.0.jar" "${MODULE_JAR3}" +} + +testFindModuleJar() { + BK_HOME=${BK_TMPDIR} + # prepare the env files + mkdir -p ${BK_HOME}/conf + echo "" > ${BK_HOME}/conf/nettyenv.sh + echo "" > ${BK_HOME}/conf/bkenv.sh + echo "" > ${BK_HOME}/conf/bk_cli_env.sh + + source ${BK_BINDIR}/common_gradle.sh + + MODULE="test-module" + MODULE_PATH="testmodule" + VERSION="4.8.0" + + TEST_FILES=( + "${MODULE}-${VERSION}.jar" + "lib/${MODULE}-${VERSION}.jar" + "${MODULE_PATH}/build/libs/${MODULE}-${VERSION}.jar" + ) + count=0 + while [ "x${TEST_FILES[count]}" != "x" ] + do + DIR=`dirname ${BK_TMPDIR}/${TEST_FILES[count]}` + mkdir -p ${DIR} + touch ${BK_TMPDIR}/${TEST_FILES[count]} + count=$(( $count + 1 )) + done + + count=0 + while [ "x${TEST_FILES[count]}" != "x" ] + do + FILE="${BK_TMPDIR}/${TEST_FILES[count]}" + ACTUAL_FILE=$(find_module_jar ${MODULE_PATH} ${MODULE}) + + assertEquals "Module file is not found" "${FILE}" "${ACTUAL_FILE}" + + # delete the file + rm ${FILE} + count=$(( $count + 1 )) + done + + unset BK_HOME +} + +testLoadEnvfiles() { + BK_HOME=${BK_TMPDIR} + + # prepare the env files + mkdir -p ${BK_HOME}/conf + echo "NETTY_LEAK_DETECTION_LEVEL=enabled" > ${BK_HOME}/conf/nettyenv.sh + echo "BOOKIE_MAX_HEAP_MEMORY=2048M" > ${BK_HOME}/conf/bkenv.sh + echo "CLI_MAX_HEAP_MEMORY=2048M" > ${BK_HOME}/conf/bk_cli_env.sh + + # load the common_gradle.sh + source ${BK_BINDIR}/common_gradle.sh + + assertEquals "NETTY_LEAK_DETECTION_LEVEL is not set correctly" "enabled" "${NETTY_LEAK_DETECTION_LEVEL}" + assertEquals "BOOKIE_MAX_HEAP_MEMORY is not set correctly" "2048M" "${BOOKIE_MAX_HEAP_MEMORY}" + assertEquals "CLI_MAX_HEAP_MEMORY is not set correctly" "2048M" "${CLI_MAX_HEAP_MEMORY}" + + unset NETTY_LEAK_DETECTION_LEVEL + unset BOOKIE_MAX_HEAP_MEMORY + unset CLI_MAX_HEAP_MEMORY + unset BK_HOME +} + +testBuildBookieJVMOpts() { + source ${BK_BINDIR}/common_gradle.sh + + TEST_LOG_DIR=${BK_TMPDIR}/logdir + TEST_GC_LOG_FILENAME="test-gc.log" + ACTUAL_JVM_OPTS=$(build_bookie_jvm_opts ${TEST_LOG_DIR} ${TEST_GC_LOG_FILENAME}) + USEJDK8=$(detect_jdk8) + if [ "$USING_JDK8" -ne "1" ]; then + EXPECTED_JVM_OPTS="-Xms1g -Xmx1g -XX:MaxDirectMemorySize=2g ${DEFAULT_BOOKIE_GC_OPTS} ${DEFAULT_BOOKIE_GC_LOGGING_OPTS} -Xlog:gc=info:file=${TEST_LOG_DIR}/${TEST_GC_LOG_FILENAME}::filecount=5,filesize=64m" + else + EXPECTED_JVM_OPTS="-Xms1g -Xmx1g -XX:MaxDirectMemorySize=2g ${DEFAULT_BOOKIE_GC_OPTS} ${DEFAULT_BOOKIE_GC_LOGGING_OPTS} -Xloggc:${TEST_LOG_DIR}/${TEST_GC_LOG_FILENAME}" + fi + assertEquals "JVM OPTS is not set correctly" "${EXPECTED_JVM_OPTS}" "${ACTUAL_JVM_OPTS}" +} + +testBuildCLIJVMOpts() { + source ${BK_BINDIR}/common_gradle.sh + + TEST_LOG_DIR=${BK_TMPDIR}/logdir + TEST_GC_LOG_FILENAME="test-gc.log" + ACTUAL_JVM_OPTS=$(build_cli_jvm_opts ${TEST_LOG_DIR} ${TEST_GC_LOG_FILENAME}) + USEJDK8=$(detect_jdk8) + if [ "$USING_JDK8" -ne "1" ]; then + EXPECTED_JVM_OPTS="-Xms256M -Xmx512M ${DEFAULT_CLI_GC_OPTS} ${DEFAULT_CLI_GC_LOGGING_OPTS} -Xlog:gc=info:file=${TEST_LOG_DIR}/${TEST_GC_LOG_FILENAME}::filecount=5,filesize=64m" + else + EXPECTED_JVM_OPTS="-Xms256M -Xmx512M ${DEFAULT_CLI_GC_OPTS} ${DEFAULT_CLI_GC_LOGGING_OPTS} -Xloggc:${TEST_LOG_DIR}/${TEST_GC_LOG_FILENAME}" + fi + assertEquals "JVM OPTS is not set correctly" "${EXPECTED_JVM_OPTS}" "${ACTUAL_JVM_OPTS}" +} + +testBuildNettyOpts() { + source ${BK_BINDIR}/common_gradle.sh + + ACTUAL_NETTY_OPTS=$(build_netty_opts) + EXPECTED_NETTY_OPTS="-Dio.netty.leakDetectionLevel=disabled \ + -Dio.netty.recycler.maxCapacity.default=1000 \ + -Dio.netty.recycler.linkCapacity=1024" + + assertEquals "Netty OPTS is not set correctly" "${EXPECTED_NETTY_OPTS}" "${ACTUAL_NETTY_OPTS}" +} + +testBuildBookieOpts() { + source ${BK_BINDIR}/common_gradle.sh + + ACTUAL_OPTS=$(build_bookie_opts) + EXPECTED_OPTS="-Djava.net.preferIPv4Stack=true" + + assertEquals "Bookie OPTS is not set correctly" "${EXPECTED_OPTS}" "${ACTUAL_OPTS}" +} + +testBuildLoggingOpts() { + TEST_CONF_FILE="test.conf" + TEST_LOG_DIR="test_log_dir" + TEST_LOG_FILE="test_log_file" + TEST_LOGGER="INFO,TEST" + + EXPECTED_OPTS="-Dlog4j.configuration=${TEST_CONF_FILE} \ + -Dbookkeeper.root.logger=${TEST_LOGGER} \ + -Dbookkeeper.log.dir=${TEST_LOG_DIR} \ + -Dbookkeeper.log.file=${TEST_LOG_FILE}" + ACTUAL_OPTS=$(build_logging_opts ${TEST_CONF_FILE} ${TEST_LOG_DIR} ${TEST_LOG_FILE} ${TEST_LOGGER}) + + assertEquals "Logging OPTS is not set correctly" "${EXPECTED_OPTS}" "${ACTUAL_OPTS}" +} + +testBuildCLILoggingOpts() { + TEST_CONF_FILE="test.conf" + TEST_LOG_DIR="test_log_dir" + TEST_LOG_FILE="test_log_file" + TEST_LOGGER="INFO,TEST" + + EXPECTED_OPTS="-Dlog4j.configuration=${TEST_CONF_FILE} \ + -Dbookkeeper.cli.root.logger=${TEST_LOGGER} \ + -Dbookkeeper.cli.log.dir=${TEST_LOG_DIR} \ + -Dbookkeeper.cli.log.file=${TEST_LOG_FILE}" + ACTUAL_OPTS=$(build_cli_logging_opts ${TEST_CONF_FILE} ${TEST_LOG_DIR} ${TEST_LOG_FILE} ${TEST_LOGGER}) + + assertEquals "Logging OPTS is not set correctly" "${EXPECTED_OPTS}" "${ACTUAL_OPTS}" +} + +#------------------------------------------------------------------------------ +# suite functions +# + +oneTimeSetUp() { + bk_oneTimeSetUp +} + +# load and run shUnit2 +. ${BK_SHUNIT} diff --git a/tests/scripts/src/test/bash/gradle/bk_test_helpers b/tests/scripts/src/test/bash/gradle/bk_test_helpers new file mode 100644 index 00000000000..33ae13c08fa --- /dev/null +++ b/tests/scripts/src/test/bash/gradle/bk_test_helpers @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# +# vim:et:ft=sh:sts=2:sw=2 +# +#/** +# * Licensed to the Apache Software Foundation (ASF) under one +# * or more contributor license agreements. See the NOTICE file +# * distributed with this work for additional information +# * regarding copyright ownership. The ASF licenses this file +# * to you under the Apache License, Version 2.0 (the +# * "License"); you may not use this file except in compliance +# * with the License. You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# */ + +# name of script +BK_ARGV0=`basename "$0"` + +# path to shUnit2 library. can be overridden by setting BK_SHUNIT_INC. +BK_SHUNIT=${BK_SHUNIT_INC:-../../../build/libs/lib/shunit2-2.1.7/shunit2} + +# path to bk bin directory. +TESTDIR=`dirname "$0"` +BK_BINDIR=`cd ${TESTDIR}/../../../../../bin;pwd` +BK_HOMEDIR=`cd ${TESTDIR}/../../../../..;pwd` +BK_CONFDIR=`cd ${TESTDIR}/../../../../../conf;pwd` + +# +# test helper functions +# + +# message functions +bk_trace() { echo "bk_test:TRACE $@" >&2; } +bk_debug() { echo "bk_test:DEBUG $@" >&2; } +bk_info() { echo "bk_test:INFO $@" >&2; } +bk_warn() { echo "bk_test:WARN $@" >&2; } +bk_error() { echo "bk_test:ERROR $@" >&2; } +bk_fatal() { echo "bk_test:FATAL $@" >&2; } + +bk_oneTimeSetUp() { + # these will be cleaned up automatically by shunit2 + BK_TMPDIR=${SHUNIT_TMPDIR} + stdoutF="${BK_TMPDIR}/stdout" + stderrF="${BK_TMPDIR}/stderr" + expectedF="${BK_TMPDIR}/expected" +} + +# Assert the success of an operation. +# +# If an operation is not successful (i.e. it returns a non-zero return code) +# dump the output of the stderrF to the screen. +# +# Args: +# message: string: message to output [optional] +# result: integer: operation result +assertSuccess() { + if [ $# -eq 2 ]; then + bk_message_=$1 + shift + else + bk_message_='' + fi + bk_result_=$1 + + assertEquals "${bk_message_}" ${SHUNIT_TRUE} ${bk_result_} + [ ${bk_result_} -eq ${SHUNIT_TRUE} ] || cat "${stderrF}" + + unset bk_message_ bk_result_ +} + +assertError() { + if [ $# -eq 2 ]; then + bk_message_="$1: " + shift + else + bk_message_='' + fi + bk_error_=$1 + + bk_file_=${stderrF} + grep "^bk_test:ERROR.*${bk_error_}" "${bk_file_}" >/dev/null + bk_result_=$? + assertTrue "${bk_message_}missing '${bk_error_}' error" ${bk_result_} + [ ${bk_result_} -eq 0 ] || cat "${bk_file_}" + + unset bk_file_ bk_error_ bk_message_ bk_result_ +} diff --git a/tests/scripts/src/test/bash/gradle/versions b/tests/scripts/src/test/bash/gradle/versions new file mode 100644 index 00000000000..9b868f509df --- /dev/null +++ b/tests/scripts/src/test/bash/gradle/versions @@ -0,0 +1,173 @@ +#!/usr/bin/env bash +# +# vim:et:ft=sh:sts=2:sw=2 +# +#/** +# * Licensed to the Apache Software Foundation (ASF) under one +# * or more contributor license agreements. See the NOTICE file +# * distributed with this work for additional information +# * regarding copyright ownership. The ASF licenses this file +# * to you under the Apache License, Version 2.0 (the +# * "License"); you may not use this file except in compliance +# * with the License. You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# */ + +ARGV0=`basename "$0"` +LSB_RELEASE="/etc/lsb-release" +VERSIONS_SHELLS="/bin/bash /bin/sh" + +true; TRUE=$? +false; FALSE=$? +ERROR=2 + +UNAME_R=`uname -r` +UNAME_S=`uname -s` + +__versions_haveStrings=${ERROR} + +versions_osName() { + os_name_='unrecognized' + os_system_=${UNAME_S} + os_release_=${UNAME_R} + case ${os_system_} in + CYGWIN_NT-*) os_name_='Cygwin' ;; + Darwin) + os_name_=`/usr/bin/sw_vers -productName` + os_version_=`versions_osVersion` + case ${os_version_} in + 10.4|10.4.[0-9]*) os_name_='Mac OS X Tiger' ;; + 10.5|10.5.[0-9]*) os_name_='Mac OS X Leopard' ;; + 10.6|10.6.[0-9]*) os_name_='Mac OS X Snow Leopard' ;; + 10.7|10.7.[0-9]*) os_name_='Mac OS X Lion' ;; + 10.8|10.8.[0-9]*) os_name_='Mac OS X Mountain Lion' ;; + 10.9|10.9.[0-9]*) os_name_='Mac OS X Mavericks' ;; + 10.10|10.10.[0-9]*) os_name_='Mac OS X Yosemite' ;; + 10.11|10.11.[0-9]*) os_name_='Mac OS X El Capitan' ;; + 10.12|10.12.[0-9]*) os_name_='macOS Sierra' ;; + 10.13|10.13.[0-9]*) os_name_='macOS High Sierra' ;; + *) os_name_='macOS' ;; + esac + ;; + FreeBSD) os_name_='FreeBSD' ;; + Linux) os_name_='Linux' ;; + SunOS) + os_name_='SunOS' + if [ -r '/etc/release' ]; then + if grep 'OpenSolaris' /etc/release >/dev/null; then + os_name_='OpenSolaris' + else + os_name_='Solaris' + fi + fi + ;; + esac + + echo ${os_name_} + unset os_name_ os_system_ os_release_ os_version_ +} + +versions_osVersion() { + os_version_='unrecognized' + os_system_=${UNAME_S} + os_release_=${UNAME_R} + case ${os_system_} in + CYGWIN_NT-*) + os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]\.[0-9]*\).*'` + ;; + Darwin) + os_version_=`/usr/bin/sw_vers -productVersion` + ;; + FreeBSD) + os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]*\)-.*'` + ;; + Linux) + if [ -r '/etc/os-release' ]; then + os_version_=`awk -F= '$1~/PRETTY_NAME/{print $2}' /etc/os-release \ + |sed 's/"//g'` + elif [ -r '/etc/redhat-release' ]; then + os_version_=`cat /etc/redhat-release` + elif [ -r '/etc/SuSE-release' ]; then + os_version_=`head -n 1 /etc/SuSE-release` + elif [ -r "${LSB_RELEASE}" ]; then + if grep -q 'DISTRIB_ID=Ubuntu' "${LSB_RELEASE}"; then + # shellcheck disable=SC2002 + os_version_=`cat "${LSB_RELEASE}" \ + |awk -F= '$1~/DISTRIB_DESCRIPTION/{print $2}' \ + |sed 's/"//g;s/ /-/g'` + fi + fi + ;; + SunOS) + if [ -r '/etc/release' ]; then + if grep 'OpenSolaris' /etc/release >/dev/null; then # OpenSolaris + os_version_=`grep 'OpenSolaris' /etc/release |awk '{print $2"("$3")"}'` + else # Solaris + major_=`echo "${os_release_}" |sed 's/[0-9]*\.\([0-9]*\)/\1/'` + minor_=`grep Solaris /etc/release |sed 's/[^u]*\(u[0-9]*\).*/\1/'` + os_version_="${major_}${minor_}" + fi + fi + ;; + esac + + echo "${os_version_}" + unset os_release_ os_system_ os_version_ major_ minor_ +} + +versions_shellVersion() { + shell_=$1 + + shell_present_=${FALSE} + case "${shell_}" in + ash) [ -x '/bin/busybox' ] && shell_present_=${TRUE} ;; + *) [ -x "${shell_}" ] && shell_present_=${TRUE} ;; + esac + if [ ${shell_present_} -eq ${FALSE} ]; then + echo 'not installed' + return ${FALSE} + fi + + version_='' + case ${shell_} in + */sh) + # This could be one of any number of shells. Try until one fits. + version_='' + [ -z "${version_}" ] && version_=`versions_shell_bash "${shell_}"` + ;; + */bash) version_=`versions_shell_bash "${shell_}"` ;; + *) version_='invalid' + esac + + echo "${version_:-unknown}" + unset shell_ version_ +} + +versions_shell_bash() { + $1 --version : 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/' +} + +versions_main() { + # Treat unset variables as an error. + set -u + + os_name=`versions_osName` + os_version=`versions_osVersion` + echo "os: ${os_name} version: ${os_version}" + + for shell in ${VERSIONS_SHELLS}; do + shell_version=`versions_shellVersion "${shell}"` + echo "shell: ${shell} version: ${shell_version}" + done +} + +if [ "${ARGV0}" = 'versions' ]; then + versions_main "$@" +fi