-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAssertRetry.java
More file actions
43 lines (36 loc) · 1.26 KB
/
AssertRetry.java
File metadata and controls
43 lines (36 loc) · 1.26 KB
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
package io.pinecone.helpers;
import io.pinecone.exceptions.PineconeException;
public class AssertRetry {
private static final int maxRetry = 4;
private static final int delay = 1500;
public static void assertWithRetry(AssertionRunnable assertionRunnable) throws Exception {
assertWithRetry(assertionRunnable, 2);
}
public static void assertWithRetry(AssertionRunnable assertionRunnable, int backOff) throws Exception {
int retryCount = 0;
int delayCount = delay;
boolean success = false;
String errorMessage = null;
while (retryCount < maxRetry && !success) {
try {
assertionRunnable.run();
success = true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
} catch (AssertionError | Exception e) {
errorMessage = e.getLocalizedMessage();
retryCount++;
delayCount*=backOff;
Thread.sleep(delayCount);
}
}
if (!success) {
throw new AssertionError(errorMessage);
}
}
@FunctionalInterface
public interface AssertionRunnable {
void run() throws Exception;
}
}