/
Retry.java
39 lines (32 loc) · 1.15 KB
/
Retry.java
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
package com.evolveum.midpoint.tools.testng;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 0;
private String maxRetryCountEnv = System.getProperty("testsRetryCount");
private boolean initMaxRetry() {
if (maxRetryCountEnv == null)
return false;
try {
maxRetryCount = Integer.parseInt(maxRetryCountEnv);
} catch (NumberFormatException e) {
System.out.println("Test retry FAILED, cannot parse retry count: "+e.getMessage());
return false;
}
return true;
}
public boolean retry(ITestResult result) {
if (isOneMoreRetryAvailable()) {
retryCount++;
System.out.println("Retry #" + retryCount + " for test: " + result.getMethod().getMethodName() + ", on thread: " + Thread.currentThread().getName());
return true;
}
return false;
}
public boolean isOneMoreRetryAvailable() {
if (!initMaxRetry())
return false;
return retryCount < maxRetryCount;
}
}