forked from qameta/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now RetryerContext is mandatory and should be injected to atlas config Re-designed Retryer's, now we use global RetryerContext as default ISExtension (for momentary checking) now beforeMethod return configuration instance for alteration fixes: qameta#81 qameta#79 qameta#74
- Loading branch information
I301235
committed
Jul 4, 2019
1 parent
80f5b6a
commit 1340d7e
Showing
14 changed files
with
327 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 14 additions & 36 deletions
50
atlas-core/src/main/java/io/qameta/atlas/core/internal/DefaultRetryer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,27 @@ | ||
package io.qameta.atlas.core.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.Set; | ||
|
||
|
||
/** | ||
* Retryer. | ||
* @deprecated | ||
* class constructor will be removed in the next release. | ||
* Now the default implementation always used from the Atlas context | ||
* see reference | ||
*/ | ||
@SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName") | ||
public class DefaultRetryer implements Retryer { | ||
|
||
private final List<Class<? extends Throwable>> ignoring; | ||
|
||
private final Long start; | ||
|
||
private Long timeout; | ||
|
||
private Long polling; | ||
@Deprecated | ||
public class DefaultRetryer extends TimeBasedRetryer { | ||
|
||
public DefaultRetryer(final Long timeout, final Long polling, final List<Class<? extends Throwable>> ignoring) { | ||
this.ignoring = new ArrayList<>(ignoring); | ||
this.start = System.currentTimeMillis(); | ||
this.timeout = timeout; | ||
this.polling = polling; | ||
} | ||
|
||
public void ignore(final Class<? extends Throwable> throwable) { | ||
this.ignoring.add(throwable); | ||
} | ||
|
||
public void timeoutInMillis(final Long millis) { | ||
this.timeout = millis; | ||
this(timeout, polling, new HashSet<>(ignoring)); | ||
} | ||
|
||
@Override | ||
public void timeoutInSeconds(final int seconds) { | ||
this.timeout = TimeUnit.SECONDS.toMillis(seconds); | ||
private DefaultRetryer(final Long timeout, final Long polling, final Set<Class<? extends Throwable>> ignoring) { | ||
setTimeOut(timeout); | ||
setPolling(polling); | ||
addAllToIgnore(ignoring); | ||
} | ||
|
||
public void polling(final Long polling) { | ||
this.polling = polling; | ||
} | ||
|
||
@Override | ||
public boolean shouldRetry(final Throwable e) { | ||
return shouldRetry(start, timeout, polling, ignoring, e); | ||
} | ||
} |
30 changes: 6 additions & 24 deletions
30
atlas-core/src/main/java/io/qameta/atlas/core/internal/EmptyRetryer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,17 @@ | ||
package io.qameta.atlas.core.internal; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Retryer with default values. | ||
*/ | ||
public class EmptyRetryer implements Retryer { | ||
|
||
private final Long start; | ||
private final Long polling; | ||
private final List<Class<? extends Throwable>> ignoring; | ||
private Long timeout; | ||
public class EmptyRetryer extends TimeBasedRetryer { | ||
|
||
public EmptyRetryer() { | ||
this.start = System.currentTimeMillis(); | ||
this.timeout = 5000L; | ||
this.polling = 1000L; | ||
this.ignoring = Collections.singletonList(Throwable.class); | ||
} | ||
|
||
@Override | ||
public boolean shouldRetry(final Throwable e) { | ||
return shouldRetry(start, timeout, polling, ignoring, e); | ||
|
||
} | ||
|
||
@Override | ||
public void timeoutInSeconds(final int seconds) { | ||
this.timeout = TimeUnit.SECONDS.toMillis(seconds); | ||
setTimeOutInSeconds(5); | ||
setPolling(1000); | ||
addAllToIgnore(Stream.of(Throwable.class).collect(Collectors.toSet())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 2 additions & 18 deletions
20
atlas-core/src/main/java/io/qameta/atlas/core/internal/Retryer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
package io.qameta.atlas.core.internal; | ||
|
||
import java.util.List; | ||
import io.qameta.atlas.core.util.MethodInfo; | ||
|
||
/** | ||
* Retryer. | ||
*/ | ||
public interface Retryer { | ||
|
||
boolean shouldRetry(Throwable e) throws Throwable; | ||
|
||
default boolean shouldRetry(final Long start, final Long timeout, final Long polling, | ||
final List<Class<? extends Throwable>> ignoring, final Throwable e) { | ||
final long current = System.currentTimeMillis(); | ||
if (!(ignoring.stream().anyMatch(clazz -> clazz.isInstance(e)) && start + timeout < current)) { | ||
try { | ||
Thread.sleep(polling); | ||
return true; | ||
} catch (InterruptedException i) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
void timeoutInSeconds(int seconds); | ||
boolean shouldRetry(Throwable e, MethodInfo methodInfo) throws Throwable; | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
atlas-core/src/main/java/io/qameta/atlas/core/internal/TimeBasedRetryer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.qameta.atlas.core.internal; | ||
|
||
import io.qameta.atlas.core.util.MethodInfo; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Default Retryer based on timeout. | ||
*/ | ||
public abstract class TimeBasedRetryer implements Retryer { | ||
|
||
private final Set<Class<? extends Throwable>> ignoring = new HashSet<>(); | ||
private final Long start = System.currentTimeMillis(); | ||
private Long timeout = 0L; | ||
private Long polling = 0L; | ||
|
||
@Override | ||
public boolean shouldRetry(final Throwable e, final MethodInfo methodInfo) { | ||
return shouldRetry(start, e); | ||
} | ||
|
||
public boolean shouldRetry(final Long start, final Throwable e) { | ||
return shouldRetry(start, getTimeout(), getPolling(), getIgnoring(), e); | ||
} | ||
|
||
public boolean shouldRetry(final Long start, final Long timeout, final Long polling, | ||
final Set<Class<? extends Throwable>> ignoring, final Throwable e) { | ||
final long current = System.currentTimeMillis(); | ||
if (!(ignoring.stream().anyMatch(clazz -> clazz.isInstance(e)) && start + timeout < current)) { | ||
try { | ||
Thread.sleep(polling); | ||
return true; | ||
} catch (InterruptedException i) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void setTimeOutInSeconds(final int seconds) { | ||
setTimeOut(TimeUnit.SECONDS.toMillis(seconds)); | ||
} | ||
|
||
public void setTimeOut(final long ms) { | ||
this.timeout = ms; | ||
} | ||
|
||
public long getTimeout() { | ||
return this.timeout; | ||
} | ||
|
||
public long getPolling() { | ||
return polling; | ||
} | ||
|
||
public void setPolling(final long ms) { | ||
this.polling = ms; | ||
} | ||
|
||
public Set<Class<? extends Throwable>> getIgnoring() { | ||
return ignoring; | ||
} | ||
|
||
public void addAllToIgnore(final Set<Class<? extends Throwable>> toIgnoring) { | ||
ignoring.addAll(toIgnoring); | ||
} | ||
|
||
} |
Oops, something went wrong.