RetryOption.java

1
package com.github.dakusui.actionunit.actions;
2
3
import com.github.dakusui.actionunit.core.Action;
4
5
import java.util.concurrent.TimeUnit;
6
7
import static com.github.dakusui.actionunit.core.ActionSupport.retry;
8
import static com.github.dakusui.actionunit.core.ActionSupport.timeout;
9
import static java.util.Objects.requireNonNull;
10
import static java.util.concurrent.TimeUnit.SECONDS;
11
12
public class RetryOption {
13
  public static class Builder {
14
    long                       timeoutDuration       = -1;
15
    TimeUnit                   timeoutTimeUnit       = SECONDS;
16
    Class<? extends Throwable> retryOn               = Throwable.class;
17
    long                       retryInterval         = -1;
18
    TimeUnit                   retryIntervalTimeUnit = SECONDS;
19
    int                        retries               = -1;
20
21
    public Builder timeoutIn(long timeoutDuration, TimeUnit timeoutTimeUnit) {
22
      this.timeoutDuration = timeoutDuration;
23
      this.timeoutTimeUnit = timeoutTimeUnit;
24 1 1. timeoutIn : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::timeoutIn → KILLED
      return this;
25
    }
26
27
    public Builder retryOn(Class<? extends Throwable> retryOn) {
28
      this.retryOn = requireNonNull(retryOn);
29 1 1. retryOn : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retryOn → KILLED
      return this;
30
    }
31
32
    public Builder retries(int retries) {
33
      this.retries = retries;
34 1 1. retries : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retries → KILLED
      return this;
35
    }
36
37
    public Builder retryInterval(long retryInterval, TimeUnit retryIntervalTimeUnit) {
38
      this.retryInterval = retryInterval;
39
      this.retryIntervalTimeUnit = retryIntervalTimeUnit;
40 1 1. retryInterval : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retryInterval → KILLED
      return this;
41
    }
42
43
    public RetryOption build() {
44 1 1. build : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::build → KILLED
      return new RetryOption(
45
          timeoutDuration,
46
          timeoutTimeUnit,
47
          retryOn,
48
          retryInterval,
49
          retryIntervalTimeUnit,
50
          retries);
51
    }
52
  }
53
54
  public static RetryOption.Builder builder() {
55 1 1. builder : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::builder → KILLED
    return new RetryOption.Builder();
56
  }
57
58
  public static RetryOption timeoutInSeconds(long timeoutInSeconds) {
59 1 1. timeoutInSeconds : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::timeoutInSeconds → KILLED
    return new RetryOption.Builder()
60
        .timeoutIn(timeoutInSeconds, SECONDS)
61
        .retries(0)
62
        .retryOn(Throwable.class)
63
        .retryInterval(0, SECONDS)
64
        .build();
65
  }
66
67
  public static RetryOption none() {
68 1 1. none : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::none → KILLED
    return new Builder()
69
        .timeoutIn(-1, SECONDS)
70
        .retryOn(Throwable.class)
71
        .timeoutIn(-1, SECONDS)
72
        .retries(-1).build();
73
  }
74
75
  public final long                       timeoutDuration;
76
  public final TimeUnit                   timeoutTimeUnit;
77
  public final Class<? extends Throwable> retryOn;
78
  public final long                       retryInterval;
79
  public final TimeUnit                   retryIntervalTimeUnit;
80
  public final int                        retries;
81
82
83
  private RetryOption(
84
      long timeoutDuration,
85
      TimeUnit timeoutTimeUnit,
86
      Class<? extends Throwable> retryOn,
87
      long retryInterval,
88
      TimeUnit retryIntervalTimeUnit,
89
      int retries) {
90
    this.timeoutDuration = timeoutDuration;
91
    this.timeoutTimeUnit = requireNonNull(timeoutTimeUnit);
92
    this.retryOn = requireNonNull(retryOn);
93
    this.retryInterval = retryInterval;
94
    this.retryIntervalTimeUnit = requireNonNull(retryIntervalTimeUnit);
95
    this.retries = retries;
96
  }
97
98
  public static Action retryAndTimeOut(Action action, RetryOption retryOption) {
99 2 1. retryAndTimeOut : changed conditional boundary → KILLED
2. retryAndTimeOut : negated conditional → KILLED
    if (retryOption.retries > 0)
100
      action = retry(action)
101
          .on(retryOption.retryOn)
102
          .times(retryOption.retries)
103
          .withIntervalOf(retryOption.retryInterval, retryOption.retryIntervalTimeUnit)
104
          .$();
105 2 1. retryAndTimeOut : changed conditional boundary → SURVIVED
2. retryAndTimeOut : negated conditional → KILLED
    if (retryOption.timeoutDuration >= 0)
106
      action = timeout(action).in(retryOption.timeoutDuration, retryOption.timeoutTimeUnit);
107 1 1. retryAndTimeOut : replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::retryAndTimeOut → KILLED
    return action;
108
  }
109
}

Mutations

24

1.1
Location : timeoutIn
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2.composeLocalEchoCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::timeoutIn → KILLED

29

1.1
Location : retryOn
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2.composeLocalEchoCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retryOn → KILLED

34

1.1
Location : retries
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2.composeLocalEchoCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retries → KILLED

40

1.1
Location : retryInterval
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenEchoHelloWithTimeoutInOneSecond$whenPerformAsAction$thenPrinted(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::retryInterval → KILLED

44

1.1
Location : build
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2.composeLocalEchoCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption$Builder::build → KILLED

55

1.1
Location : builder
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenEchoHelloWithTimeoutInOneMinutesAndRetryingTwice$whenPerformAsAction$thenPrinted(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::builder → KILLED

59

1.1
Location : timeoutInSeconds
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenEchoHelloWithTimeoutInOneSecond$whenPerformAsAction$thenPrinted(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::timeoutInSeconds → KILLED

68

1.1
Location : none
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2.composeLocalEchoCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithCustomSshOptions2)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::none → KILLED

99

1.1
Location : retryAndTimeOut
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenEchoHelloWithTimeoutInOneSecond$whenPerformAsAction$thenPrinted(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
changed conditional boundary → KILLED

2.2
Location : retryAndTimeOut
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction.givenEchoHello$whenPerformAction$thenFinishNormally(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction)
negated conditional → KILLED

105

1.1
Location : retryAndTimeOut
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : retryAndTimeOut
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction.givenEchoHello$whenPerformAction$thenFinishNormally(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction)
negated conditional → KILLED

107

1.1
Location : retryAndTimeOut
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction.givenEchoHello$whenPerformAction$thenFinishNormally(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsAction)
replaced return value with null for com/github/dakusui/actionunit/actions/RetryOption::retryAndTimeOut → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3