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
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
20 echo "bin/repeat-junit-test.sh test_file num_times"
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
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
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
45 echo "ERROR: Incorrect number of arguments: $# provided, 2 needed." >&2
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 ]]
58 echo "ERROR: Did not find an appropriate file (with name $FILENAME), given test name $TESTNAME." >&2
65 if [[ ! $NUMTIMES == +([0-9]) ]]
67 echo "ERROR: argument num_times is not an integer: $NUMTIMES." >&2
72 TMPDIR
=`mktemp -d -p '/tmp/'`
74 for ((i
=1;i
<=$NUMTIMES;i
++)); do
76 echo "STARTING ITERATION $i"
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)
85 junitidir
="$TMPDIR/junit-single-report-$TESTNAME-$i"
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