Search in sources :

Example 1 with RetryStrategy

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));
}
Also used : RetryStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy)

Example 2 with RetryStrategy

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);
}
Also used : RetryStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy)

Example 3 with RetryStrategy

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));
}
Also used : RetryOnException(org.apache.flink.testutils.junit.RetryOnException) IntStream(java.util.stream.IntStream) RetryOnExceptionStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnExceptionStrategy) Arrays(java.util.Arrays) RetryStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Extension(org.junit.jupiter.api.extension.Extension) List(java.util.List) Stream(java.util.stream.Stream) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider) RetryOnFailureStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnFailureStrategy) RetryOnFailure(org.apache.flink.testutils.junit.RetryOnFailure) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) RetryOnExceptionStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnExceptionStrategy) RetryOnException(org.apache.flink.testutils.junit.RetryOnException) RetryStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy) HashMap(java.util.HashMap) Map(java.util.Map) RetryOnFailureStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnFailureStrategy) RetryOnFailure(org.apache.flink.testutils.junit.RetryOnFailure)

Example 4 with RetryStrategy

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));
    }
}
Also used : RetryStrategy(org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy)

Aggregations

RetryStrategy (org.apache.flink.testutils.junit.extensions.retry.strategy.RetryStrategy)4 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 RetryOnException (org.apache.flink.testutils.junit.RetryOnException)1 RetryOnFailure (org.apache.flink.testutils.junit.RetryOnFailure)1 RetryOnExceptionStrategy (org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnExceptionStrategy)1 RetryOnFailureStrategy (org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnFailureStrategy)1 AfterAllCallback (org.junit.jupiter.api.extension.AfterAllCallback)1 Extension (org.junit.jupiter.api.extension.Extension)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 TestTemplateInvocationContext (org.junit.jupiter.api.extension.TestTemplateInvocationContext)1 TestTemplateInvocationContextProvider (org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider)1