blob: 45c1a26e1ee00564759ac6cb4686c981ffefce93 [file] [log] [blame]
#!/bin/bash
#
# 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.
#
# Convenience script to clean, build, install and run unit and/or integration tests.
# Recommend you run this prior to pushing to Github to reduce the chances of breaking
# the continuous integration (unit tests) or overnight builds (integration tests.)
#
# Also very useful when using "git bisect" to find out which commit was responsible
# for breaking the overnight build - invoke as "git bisect run ./buildAndRun"
#
# Run "./buildAndRun --help" to see the usage.
#
# Has an integration test left a Java process running? See if there is any running
# Java processes and offer to kill them/
cleanup(){
PROCS=$(ps ax | grep '[j]ava' | grep -v set_tab_title)
if [ ! -z "${PROCS}" ]; then
echo "These Java processes are running:"
echo ${PROCS}
echo -n "Kill them? y=yes, n=no, x=abort: "
read $RESPONSE
[ "${RESPONSE}" = "y" ] && killall java && sleep 1s
[ "${RESPONSE}" = "x" ] && exit 50
fi
}
# Check a return value, and bail if its non-zero - invoke as "assert $? 'Unit tests'"
assert(){
[ $1 -eq 0 ] && return
echo '*** Command returned '$1' on '$2
exit $1
}
# The defaults
unit=1
integration=1
if [ ! -z "$1" ]; then
case "$1" in
u)
unit=1
integration=0
;;
i)
unit=0
integration=1
;;
ui)
unit=1
integration=1
;;
b)
unit=0
integration=0
;;
*)
echo >&2 Usage: buildAndTest [action]
echo >&2 where action is:
echo >&2 u - build from clean and run unit tests
echo >&2 i - build from clean and run integration tests
echo >&2 ui - build from clean and run unit and integration tests \(default\)
echo >&2 b - build from clean and do not run any tests
exit 1
;;
esac
fi
echo '*** BUILD'
mvn clean install -DskipTests -PConsole
assert $? 'BUILD'
cleanup
if [ $unit -eq 1 ]; then
echo '*** UNIT TEST'
mvn integration-test -PConsole
assert $? 'UNIT TEST'
cleanup
fi
if [ $integration -eq 1 ]; then
echo '*** INTEGRATION TEST'
mvn integration-test -PConsole,Integration
assert $? 'INTEGRATION TEST'
cleanup
fi
exit 0