Search in sources :

Example 1 with RetryOnFailureStrategy

use of org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnFailureStrategy 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)

Aggregations

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