-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathhbasetests.sh
executable file
·428 lines (362 loc) · 13 KB
/
hbasetests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/usr/bin/env 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.
##
#
# This script:
# - analyse the content of the .java test file to split them between
# small/medium/large
# - launch the small tests in a single maven, with surefire
# parallelisation activated
# - launch the medium & large in two maven, parallelized
# - the flaky tests are run at the end, not parallelized
# - present a small report of the global results
# - copy the failed test reports with prefix 'fail_' and a timestamp
# to protect them from a later deletion by maven
# - if configured for, relaunch the tests in errors
#
#
# Caveats:
# - multiple maven are launch, hence there can be recompilation
# between the tests if a file is modified. For non flaky tests and
# parallelization, the frame is the time to execute the small tests,
# so it's around 4 minutes.
# - Note that surefire is buggy, and the results presented while
# running may be wrong. For example, it can says that a class tests
# have 5 errors. When you look at the file it wrote, it says that the
# 2 tests are ok, and in the class there are actually two tests
# methods, not five. If you generate the report at the end with
# surefire-report it's fine however.
#
######################################### parameters
#mvn test -Dtest=org.apache.hadoop.hbase.regionserver.TestScanWithBloomError $*
#exit
#set to 0 to run only developpers tests (small & medium categories)
runAllTests=0
#set to 1 to replay the failed tests. Previous reports are kept in
# fail_ files
replayFailed=0
#set to 0 to run all medium & large tests in a single maven operation
# instead of two
parallelMaven=1
#harcoded list of tests that often fail. We don't want to add any
# complexity around then so there are not run in parallel but after
# the others
#The ',' at the end is mandatory
flakyTests=
#org.apache.hadoop.hbase.mapreduce.TestTableInputFormatScan,org.apache.hadoop.hbase.catalog.TestMetaTableAccessorNoCluster,org.apache.hadoop.hbase.catalog.TestMetaTableAccessor,org.apache.hadoop.hbase.mapreduce.TestHFileOutputFormat,org.apache.hadoop.hbase.mapred.TestTableMapReduce,org.apache.hadoop.hbase.coprocessor.TestMasterCoprocessorExceptionWithAbort,org.apache.hadoop.hbase.coprocessor.TestMasterCoprocessorExceptionWithRemove,org.apache.hadoop.hbase.client.TestAdmin,org.apache.hadoop.hbase.master.TestMasterFailover,org.apache.hadoop.hbase.regionserver.wal.TestLogRolling,org.apache.hadoop.hbase.master.TestDistributedLogSplitting,org.apache.hadoop.hbase.master.TestMasterRestartAfterDisablingTable,org.apache.hadoop.hbase.TestGlobalMemStoreSize,
######################################### Internal parameters
#directory used for surefire & the source code.
#They should not need to be modified
#The final / is mandatory
rootTestClassDirectory="./src/test/java/"
surefireReportDirectory="./target/surefire-reports/"
#variable to use to debug the script without launching the tests
mvnCommand="mvn "
#mvnCommand="echo $mvnCommand"
######################################### Functions
#get the list of the process considered as dead
# i.e.: in the same group as the script and with a ppid of 1
# We do this because surefire can leave some dead process, so
# we will jstack them and kill them
function createListDeadProcess {
id=$$
listDeadProcess=""
#list of the process with a ppid of 1
sonProcess=`ps -o pid= --ppid 1`
#then the process with a pgid of the script
for pId in $sonProcess
do
pgid=`ps -o pgid= --pid $pId | sed 's/ //g'`
if [ "$pgid" == "$id" ]
then
listDeadProcess="$pId $listDeadProcess"
fi
done
}
#kill the java sub process, if any, with a kill and a kill -9
#When maven/surefire fails, it lefts some process with a ppid==1
#we're going to find them with the pgid, print the stack and kill them.
function cleanProcess {
id=$$
createListDeadProcess
for pId in $listDeadProcess
do
echo "$pId survived, I will kill if it's a java process. 'ps' says:"
ps -fj --pid $pId
name=`ps -o comm= --pid $pId`
if [ "$name" == "java" ]
then
echo "$pId, java sub process of $id, is still running, killing it with a standard kill"
echo "Stack for $pId before kill:"
jstack -F -l $pId
kill $pId
echo "kill sent, waiting for 30 seconds"
sleep 30
son=`ps -o pid= --pid $pId | wc -l`
if (test $son -gt 0)
then
echo "$pId, java sub process of $id, is still running after a standard kill, using kill -9 now"
echo "Stack for $pId before kill -9:"
jstack -F -l $pId
kill -9 $pId
echo "kill sent, waiting for 2 seconds"
sleep 2
echo "Process $pId killed by kill -9"
else
echo "Process $pId killed by standard kill -15"
fi
else
echo "$pId is not a java process (it's $name), I don't kill it."
fi
done
createListDeadProcess
if (test ${#listDeadProcess} -gt 0)
then
echo "There are still $sonProcess for process $id left."
else
echo "Process $id clean, no son process left"
fi
}
#count the number of ',' in a string
# used to calculate the number of class
#write $count
function countClasses {
cars=`echo $1 | sed 's/[^,]//g' | wc -c `
count=$((cars - 1))
}
######################################### script
echo "Starting Script. Possible parameters are: runAllTests, replayFailed, nonParallelMaven"
echo "Other parameters are sent to maven"
#We will use this value at the end to calculate the execution time
startTime=`date +%s`
#look in the arguments if we override default values
for arg in "$@"
do
if [ $arg == "runAllTests" ]
then
runAllTests=1
else
if [ $arg == "replayFailed" ]
then
replayFailed=1
else
if [ $arg == "nonParallelMaven" ]
then
parallelMaven=0
else
args=$args" $arg"
fi
fi
fi
done
testsList=$(find $rootTestClassDirectory -name "Test*.java")
#for all java test files, let see if they contain the pattern
# to recognize the category
for testFile in $testsList
do
lenPath=$((${#rootTestClassDirectory}))
len=$((${#testFile} - $lenPath - 5)) # len(".java") == 5
shortTestFile=${testFile:lenPath:$len}
testName=$(echo $shortTestFile | sed 's/\//\./g')
#The ',' is used in the grep pattern as we don't want to catch
# partial name
isFlaky=$((`echo $flakyTests | grep "$testName," | wc -l`))
if (test $isFlaky -eq 0)
then
isSmall=0
isMedium=0
isLarge=0
# determine the category of the test by greping into the source code
isMedium=`grep "@Category" $testFile | grep "MediumTests.class" | wc -l`
if (test $isMedium -eq 0)
then
isLarge=`grep "@Category" $testFile | grep "LargeTests.class" | wc -l`
if (test $isLarge -eq 0)
then
isSmall=`grep "@Category" $testFile | grep "SmallTests.class" | wc -l`
if (test $isSmall -eq 0)
then
echo "$testName is not categorized, so it won't be tested"
else
#sanity check on small tests
isStrange=`grep "\.startMini" $testFile | wc -l`
if (test $isStrange -gt 0)
then
echo "$testFile is categorized as 'small' but contains a .startMini string. Keep it as small anyway, but it's strange."
fi
fi
fi
fi
#put the test in the right list
if (test $isSmall -gt 0)
then
smallList="$smallList,$testName"
fi
if (test $isMedium -gt 0)
then
mediumList="$mediumList,$testName"
fi
if (test $isLarge -gt 0)
then
largeList="$largeList,$testName"
fi
fi
done
#remove the ',' at the beginning
smallList=${smallList:1:${#smallList}}
mediumList=${mediumList:1:${#mediumList}}
largeList=${largeList:1:${#largeList}}
countClasses $smallList
echo "There are $count small tests"
countClasses $mediumList
echo "There are $count medium tests"
countClasses $largeList
echo "There are $count large tests"
#do we launch only dev or all tests?
if (test $runAllTests -eq 1)
then
echo "Running all tests, small, medium and large"
longList="$mediumList,$largeList"
else
echo "Running developper tests only, small and medium categories"
longList=$mediumList
fi
#medium and large test can be run in //, so we're
#going to create two lists
nextList=1
for testClass in `echo $longList | sed 's/,/ /g'`
do
if (test $nextList -eq 1)
then
nextList=2
runList1=$runList1,$testClass
else
nextList=1
runList2=$runList2,$testClass
fi
done
#remove the ',' at the beginning
runList1=${runList1:1:${#runList1}}
runList2=${runList2:1:${#runList2}}
#now we can run the tests, at last!
echo "Running small tests with one maven instance, in parallel"
#echo Small tests are $smallList
$mvnCommand -P singleJVMTests test -Dtest=$smallList $args
cleanProcess
exeTime=$(((`date +%s` - $startTime)/60))
echo "Small tests executed after $exeTime minutes"
if (test $parallelMaven -gt 0)
then
echo "Running tests with two maven instances in parallel"
$mvnCommand -P localTests test -Dtest=$runList1 $args &
#give some time to the fist process if there is anything to compile
sleep 30
$mvnCommand -P localTests test -Dtest=$runList2 $args
#wait for forked process to finish
wait
cleanProcess
exeTime=$(((`date +%s` - $startTime)/60))
echo "Medium and large (if selected) tests executed after $exeTime minutes"
#now the flaky tests, alone, if the list is not empty
# we test on size greater then 5 to remove any "," effect
if (test $runAllTests -eq 1 && test ${#flakyTests} -gt 5)
then
echo "Running flaky tests"
$mvnCommand -P localTests test -Dtest=$flakyTests $args
cleanProcess
exeTime=$(((`date +%s` - $startTime)/60))
echo "Flaky tests executed after $exeTime minutes"
fi
else
echo "Running tests with a single maven instance, no parallelization"
$mvnCommand -P localTests test -Dtest=$runList1,$runList2,$flakyTests $args
cleanProcess
exeTime=$(((`date +%s` - $startTime)/60))
echo "Single maven instance tests executed after $exeTime minutes"
fi
#let's analyze the results
fullRunList="$smallList,$longList"
if (test $runAllTests -eq 1)
then
fullRunList="$fullRunList,$flakyTests"
fi
#single timestamp to ensure files uniquess.
timestamp=`date +%s`
#some counters, initialized because they may not be touched
# in the loop
errorCounter=0
sucessCounter=0
notFinishedCounter=0
for testClass in `echo $fullRunList | sed 's/,/ /g'`
do
reportFile=$surefireReportDirectory/$testClass.txt
outputReportFile=$surefireReportDirectory/$testClass-output.txt
if [ -s $reportFile ];
then
isError=`grep FAILURE $reportFile | wc -l`
if (test $isError -gt 0)
then
errorList="$errorList,$testClass"
errorCounter=$(($errorCounter + 1))
#let's copy the files if we want to use it later
cp $reportFile "$surefireReportDirectory/fail_$timestamp.$testClass.txt"
if [ -s $reportFile ];
then
cp $outputReportFile "$surefireReportDirectory/fail_$timestamp.$testClass"-output.txt""
fi
else
sucessCounter=$(($sucessCounter +1))
fi
else
#report file does not exist or is empty => the test didn't finish
notFinishedCounter=$(($notFinishedCounter + 1))
notFinishedList="$notFinishedList,$testClass"
fi
done
#list of all tests that failed
replayList="$notFinishedList""$errorList"
#remove the ',' at the beginning
notFinishedList=${notFinishedList:1:${#notFinishedList}}
errorList=${errorList:1:${#errorList}}
replayList=${replayList:1:${#replayList}}
#make it simpler to read by removing the org.* stuff from the name
notFinishedPresList=`echo $notFinishedList | sed 's/org.apache.hadoop.hbase.//g' | sed 's/,/, /g'`
errorPresList=`echo $errorList | sed 's/org.apache.hadoop.hbase.//g' | sed 's/,/, /g'`
#calculate the execution time
curTime=`date +%s`
exeTime=$((($curTime - $startTime)/60))
echo "##########################"
echo "$sucessCounter tests executed successfully"
echo "$errorCounter tests are in error"
echo "$notFinishedCounter tests didn't finish"
echo
echo "Tests in error are: $errorPresList"
echo "Tests that didn't finish are: $notFinishedPresList"
echo
echo "Execution time in minutes: $exeTime"
echo "##########################"
if (test ${#replayList} -gt 0)
then
if (test $replayFailed -gt 0)
then
echo "Replaying all tests that failed"
$mvnCommand -P localTests test -Dtest=$replayList $args
echo "Replaying done"
fi
fi
exit