Removed maxTries option from Rebalancing
[voldemort/jeffpc.git] / bin / repeat-junit-test.sh
blobeb16319847b95262222951e7fdac06d755a71b73
1 #!/bin/bash -e
3 # Copyright 2012 LinkedIn, Inc
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 # use this file except in compliance with the License. You may obtain a copy of
7 # 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, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations under
15 # the License.
17 usage() {
18 echo
19 echo "Usage:"
20 echo "bin/repeat-junit-test.sh test_file num_times"
21 echo
22 cat <<EOF
23 Invoke bin/repeat-junit-test.sh from the root of a Voldemort
24 checkout. bin/repeat-junit-test.sh invokes 'ant junit-test' num_times
25 for test test_name.
27 The argument num_times must be an integer. The argument test_name must
28 be a class name suitable for 'ant junit-test'. I.e., a fully qualified
29 java class name. Remember, the class name does not include the .java
30 extension. An example test_name is voldemort.utils.ServerTestUtilsTest.
32 The pretty html junit output that ends up in dist/junit-single-report
33 on a single invocation of 'ant junit-test' is collected in a temp
34 directory. This circumvents the normal behavior of ant in which
35 dist/junit-single-report is overwritten with each invocation of 'ant
36 junit-test'.
38 bin/repeat-junit-test.sh is useful to run after adding a new test
39 case, or when trying to reproduce intermittent failures of a specific
40 test.
41 EOF
44 if [ $# != 2 ]; then
45 echo "ERROR: Incorrect number of arguments: $# provided, 2 needed." >&2
46 usage
47 exit 1
50 TESTNAME=$1
51 # Hackish test that makes sure some java file exists for given
52 # testname. No guarantee that junit-test can run the specified test,
53 # but at least protects against typos.
54 FILENAME=`echo $TESTNAME | sed 's/.*\.//g'`.java
55 FINDFILE=`find . -name "$FILENAME" | wc -l`
56 if [[ $FINDFILE == 0 ]]
57 then
58 echo "ERROR: Did not find an appropriate file (with name $FILENAME), given test name $TESTNAME." >&2
59 usage
60 exit 1
64 NUMTIMES=$2
65 if [[ ! $NUMTIMES == +([0-9]) ]]
66 then
67 echo "ERROR: argument num_times is not an integer: $NUMTIMES." >&2
68 usage
69 exit 1
72 TMPDIR=`mktemp -d -p '/tmp/'`
74 for ((i=1;i<=$NUMTIMES;i++)); do
75 echo
76 echo "STARTING ITERATION $i"
77 echo
79 # Run junit-test and capture stdout to .out and stderr to .err
80 junitiout="$TMPDIR/TEST-$TESTNAME-$i.out"
81 junitierr="$TMPDIR/TEST-$TESTNAME-$i.err"
82 ant junit-test -Dtest.name=$TESTNAME > >(tee $junitiout) 2> >(tee $junitierr >&2)
84 # Collect results
85 junitidir="$TMPDIR/junit-single-report-$TESTNAME-$i"
86 echo
87 echo "COLLECTING RESULTS OF ITERATION $i IN $junitidir"
88 cp -r dist/junit-single-reports $junitidir
89 mv $junitiout $junitidir
90 mv $junitierr $junitidir
91 done