Skip to content

Commit

Permalink
revert sh files. Avoid to modify maven files, create gradle versions …
Browse files Browse the repository at this point in the history
…to faciltate migration
  • Loading branch information
nicoloboschi committed Oct 27, 2021
1 parent d1f95e4 commit 43230ba
Show file tree
Hide file tree
Showing 8 changed files with 689 additions and 29 deletions.
6 changes: 3 additions & 3 deletions bin/common_gradle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions tests/scripts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
36 changes: 13 additions & 23 deletions tests/scripts/src/test/bash/bk_test_bin_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -59,7 +49,7 @@ testDefaultVariables() {
}

testFindModuleJarAt() {
source ${BK_BINDIR}/${BK_COMMON_EXEC}
source ${BK_BINDIR}/common.sh

MODULE="test-module"

Expand Down Expand Up @@ -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"
Expand All @@ -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" ]
Expand Down Expand Up @@ -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}"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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 \
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/src/test/bash/bk_test_helpers
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
141 changes: 141 additions & 0 deletions tests/scripts/src/test/bash/gradle/bk_test.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
#------------------------------------------------------------------------------
# System data
#
# test run info
shells="${shells}"
tests="${tests}"
EOF
for key in ${env}; do
eval "echo \"${key}=\$${key}\""
done
echo

# output system data
echo "# system info"
echo "$ date"
date

echo "$ uname -mprsv"
uname -mprsv

#
# run tests
#

for shell in ${shells}; do
echo

# check for existance of shell
if [ ! -x ${shell} ]; then
bk_warn "unable to run tests with the ${shell} shell"
continue
fi

cat <<EOF
#------------------------------------------------------------------------------
# Running the test suite with ${shell}
#
EOF

shell_name=`basename ${shell}`
shell_version=`versions_shellVersion "${shell}"`

echo "shell name: ${shell_name}"
echo "shell version: ${shell_version}"

# execute the tests
for suite in ${tests}; do
suiteName=`expr "${suite}" : "${PREFIX}\(.*\).sh"`
echo
echo "--- Executing the '${suiteName}' test suite ---"
( exec ${shell} ./${suite} 2>&1; )
done
done
Loading

0 comments on commit 43230ba

Please sign in to comment.