Skip to content

Commit

Permalink
provide retry configuration for child elements (fixes #74))
Browse files Browse the repository at this point in the history
  • Loading branch information
eroshenkoam committed Feb 14, 2020
1 parent f7151ba commit 8cc58ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private Object invokeWithRetry(final MethodInvoker invoker,
final Object proxy,
final MethodInfo methodInfo) throws Throwable {
final Retryer retryer = Optional.ofNullable(methodInfo.getMethod().getAnnotation(Retry.class))
.map(retry -> (Retryer) new DefaultRetryer(retry.timeout(), retry.polling(),
Arrays.asList(retry.ignoring())))
.map(DefaultRetryer::new)
.map(Retryer.class::cast)
.orElseGet(() -> configuration.getContext(RetryerContext.class)
.orElseGet(() -> new RetryerContext(new EmptyRetryer())).getValue());
methodInfo.getParameter(Integer.class, Timeout.class).ifPresent(retryer::timeoutInSeconds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.qameta.atlas.core.internal;

import io.qameta.atlas.core.api.Retry;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand All @@ -16,6 +19,10 @@ public class DefaultRetryer implements Retryer {

private Long polling;

public DefaultRetryer(final Retry annotation) {
this(annotation.timeout(), annotation.polling(), Arrays.asList(annotation.ignoring()));
}

public DefaultRetryer(final Long timeout, final Long polling, final List<Class<? extends Throwable>> ignoring) {
this.ignoring = new ArrayList<>(ignoring);
this.timeout = timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import io.qameta.atlas.core.Atlas;
import io.qameta.atlas.core.api.MethodExtension;
import io.qameta.atlas.core.api.Retry;
import io.qameta.atlas.core.api.Target;
import io.qameta.atlas.core.context.RetryerContext;
import io.qameta.atlas.core.internal.Configuration;
import io.qameta.atlas.core.internal.DefaultRetryer;
import io.qameta.atlas.core.internal.Retryer;
import io.qameta.atlas.core.target.HardcodedTarget;
import io.qameta.atlas.core.target.LazyTarget;
import io.qameta.atlas.core.util.MethodInfo;
Expand Down Expand Up @@ -70,7 +74,13 @@ public Object invoke(final Object proxy,
.collect(toList());
});

return new Atlas(configuration.child())
final Configuration childConfiguration = configuration.child();
Optional.ofNullable(methodInfo.getMethod().getAnnotation(Retry.class)).ifPresent(retry -> {
final Retryer retryer = new DefaultRetryer(retry);
childConfiguration.registerContext(new RetryerContext(retryer));
});

return new Atlas(childConfiguration)
.create(elementsTarget, method.getReturnType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import io.qameta.atlas.core.Atlas;
import io.qameta.atlas.core.api.MethodExtension;
import io.qameta.atlas.core.api.Retry;
import io.qameta.atlas.core.api.Target;
import io.qameta.atlas.core.context.RetryerContext;
import io.qameta.atlas.core.internal.Configuration;
import io.qameta.atlas.core.internal.DefaultRetryer;
import io.qameta.atlas.core.internal.Retryer;
import io.qameta.atlas.core.target.LazyTarget;
import io.qameta.atlas.core.util.MethodInfo;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -48,6 +52,11 @@ public Object invoke(final Object proxy,
.orElse(method.getName());

final Configuration childConfiguration = configuration.child();
Optional.ofNullable(methodInfo.getMethod().getAnnotation(Retry.class)).ifPresent(retry -> {
final Retryer retryer = new DefaultRetryer(retry);
childConfiguration.registerContext(new RetryerContext(retryer));
});

final Target elementTarget = new LazyTarget(name, () -> searchContext.findElement(by));
return new Atlas(childConfiguration)
.create(elementTarget, method.getReturnType());
Expand Down

0 comments on commit 8cc58ed

Please sign in to comment.