1 | package com.github.dakusui.actionunit.actions; | |
2 | ||
3 | import com.github.dakusui.actionunit.core.Action; | |
4 | ||
5 | import java.util.Formatter; | |
6 | import java.util.concurrent.TimeUnit; | |
7 | ||
8 | import static com.github.dakusui.actionunit.utils.Checks.requireArgument; | |
9 | import static com.github.dakusui.actionunit.utils.InternalUtils.formatDuration; | |
10 | import static com.github.dakusui.actionunit.utils.InternalUtils.formatNumberOfTimes; | |
11 | import static java.util.Objects.requireNonNull; | |
12 | import static java.util.concurrent.TimeUnit.SECONDS; | |
13 | ||
14 | public interface Retry extends Action { | |
15 | ||
16 | Action perform(); | |
17 | ||
18 | int times(); | |
19 | ||
20 | Class<? extends Throwable> targetExceptionClass(); | |
21 | ||
22 | long intervalInNanoseconds(); | |
23 | ||
24 | default void accept(Visitor visitor) { | |
25 |
1
1. accept : removed call to com/github/dakusui/actionunit/core/Action$Visitor::visit → KILLED |
visitor.visit(this); |
26 | } | |
27 | ||
28 | @Override | |
29 | default void formatTo(Formatter formatter, int flags, int width, int precision) { | |
30 | formatter.format("retry %s in %s on %s", | |
31 | formatNumberOfTimes(times()), | |
32 | formatDuration(intervalInNanoseconds()), | |
33 | targetExceptionClass().getSimpleName() | |
34 | ); | |
35 | } | |
36 | ||
37 | class Builder extends Action.Builder<Retry> { | |
38 | ||
39 | private final Action perform; | |
40 | private int times = 2; | |
41 | private Class<? extends Throwable> targetExceptionClass = Exception.class; | |
42 | private long interval = 10; | |
43 | private TimeUnit timeUnit = SECONDS; | |
44 | ||
45 | public Builder(Action perform) { | |
46 | this.perform = requireNonNull(perform); | |
47 | } | |
48 | ||
49 | public Builder times(int times) { | |
50 |
3
1. lambda$times$0 : changed conditional boundary → KILLED 2. lambda$times$0 : negated conditional → KILLED 3. lambda$times$0 : replaced boolean return with true for com/github/dakusui/actionunit/actions/Retry$Builder::lambda$times$0 → KILLED |
requireArgument(v -> v >= 0, times); |
51 | this.times = times; | |
52 |
1
1. times : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder::times → KILLED |
return this; |
53 | } | |
54 | ||
55 | public Builder on(Class<? extends Throwable> targetExceptionClass) { | |
56 | this.targetExceptionClass = requireNonNull(targetExceptionClass); | |
57 |
1
1. on : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder::on → KILLED |
return this; |
58 | } | |
59 | ||
60 | public Builder withIntervalOf(long interval, TimeUnit timeUnit) { | |
61 |
3
1. lambda$withIntervalOf$1 : changed conditional boundary → SURVIVED 2. lambda$withIntervalOf$1 : negated conditional → KILLED 3. lambda$withIntervalOf$1 : replaced boolean return with true for com/github/dakusui/actionunit/actions/Retry$Builder::lambda$withIntervalOf$1 → KILLED |
this.interval = requireArgument(v -> v > 0, interval); |
62 | this.timeUnit = requireNonNull(timeUnit); | |
63 |
1
1. withIntervalOf : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder::withIntervalOf → KILLED |
return this; |
64 | } | |
65 | ||
66 | @Override | |
67 | public Retry build() { | |
68 |
1
1. build : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder::build → KILLED |
return new Retry() { |
69 | @Override | |
70 | public Action perform() { | |
71 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder$1::perform → KILLED |
return Builder.this.perform; |
72 | } | |
73 | ||
74 | @Override | |
75 | public int times() { | |
76 |
1
1. times : replaced int return with 0 for com/github/dakusui/actionunit/actions/Retry$Builder$1::times → KILLED |
return Builder.this.times; |
77 | } | |
78 | ||
79 | @Override | |
80 | public Class<? extends Throwable> targetExceptionClass() { | |
81 |
1
1. targetExceptionClass : replaced return value with null for com/github/dakusui/actionunit/actions/Retry$Builder$1::targetExceptionClass → KILLED |
return Builder.this.targetExceptionClass; |
82 | } | |
83 | ||
84 | @Override | |
85 | public long intervalInNanoseconds() { | |
86 |
1
1. intervalInNanoseconds : replaced long return with 0 for com/github/dakusui/actionunit/actions/Retry$Builder$1::intervalInNanoseconds → KILLED |
return timeUnit.toNanos(Builder.this.interval); |
87 | } | |
88 | ||
89 | @Override | |
90 | public String toString() { | |
91 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/Retry$Builder$1::toString → SURVIVED |
return String.format("retry(%sx%dtimes)", |
92 | formatDuration(intervalInNanoseconds()), | |
93 | times | |
94 | ); | |
95 | } | |
96 | }; | |
97 | } | |
98 | } | |
99 | } | |
Mutations | ||
25 |
1.1 |
|
50 |
1.1 2.2 3.3 |
|
52 |
1.1 |
|
57 |
1.1 |
|
61 |
1.1 2.2 3.3 |
|
63 |
1.1 |
|
68 |
1.1 |
|
71 |
1.1 |
|
76 |
1.1 |
|
81 |
1.1 |
|
86 |
1.1 |
|
91 |
1.1 |