use of org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy in project flink by apache.
the class RetryTestExecutionExtension method evaluateExecutionCondition.
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
RetryStrategy retryStrategy = getRetryStrategyInStore(context);
String method = getTestMethodKey(context);
if (!retryStrategy.hasNextAttempt()) {
return ConditionEvaluationResult.disabled(method + "has already passed or failed.");
}
return ConditionEvaluationResult.enabled(String.format("Test %s[%d/%d]", method, retryIndex, totalTimes));
}
use of org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy in project flink by apache.
the class RetryTestExecutionExtension method handleTestExecutionException.
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
RetryStrategy retryStrategy = getRetryStrategyInStore(context);
String method = getTestMethodKey(context);
retryStrategy.handleException(method, retryIndex, throwable);
}
use of org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy in project flink by apache.
the class RetryExtension method provideTestTemplateInvocationContexts.
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
RetryOnFailure retryOnFailure = getRetryAnnotation(context, RetryOnFailure.class);
RetryOnException retryOnException = getRetryAnnotation(context, RetryOnException.class);
// sanity check that we don't use both annotations
if (retryOnFailure != null && retryOnException != null) {
throw new IllegalArgumentException("You cannot combine the RetryOnFailure and RetryOnException annotations.");
}
Map<String, RetryStrategy> testLog = (Map<String, RetryStrategy>) context.getStore(RETRY_NAMESPACE).getOrComputeIfAbsent(RETRY_KEY, key -> new HashMap<>());
int totalTimes;
if (retryOnException != null) {
totalTimes = retryOnException.times() + 1;
testLog.put(getTestMethodKey(context), new RetryOnExceptionStrategy(totalTimes, retryOnException.exception()));
} else if (retryOnFailure != null) {
totalTimes = retryOnFailure.times() + 1;
testLog.put(getTestMethodKey(context), new RetryOnFailureStrategy(totalTimes));
} else {
throw new IllegalArgumentException("Unsupported retry strategy.");
}
return IntStream.rangeClosed(1, totalTimes).mapToObj(i -> new RetryContext(i, totalTimes));
}
use of org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy in project flink by apache.
the class RetryTestExecutionExtension method afterEach.
@Override
public void afterEach(ExtensionContext context) throws Exception {
Throwable exception = context.getExecutionException().orElse(null);
if (exception == null) {
RetryStrategy retryStrategy = getRetryStrategyInStore(context);
String method = getTestMethodKey(context);
retryStrategy.stopFollowingAttempts();
LOG.trace(String.format("Retry test %s[%d/%d] passed, stop retrying.", method, retryIndex, totalTimes));
}
}
Aggregations