| 1 | package fr.sii.ogham.core.builder.retry; | |
| 2 | ||
| 3 | import fr.sii.ogham.core.builder.Builder; | |
| 4 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilder; | |
| 5 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper; | |
| 6 | import fr.sii.ogham.core.builder.configurer.Configurer; | |
| 7 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 8 | import fr.sii.ogham.core.builder.env.EnvironmentBuilder; | |
| 9 | import fr.sii.ogham.core.fluent.AbstractParent; | |
| 10 | import fr.sii.ogham.core.retry.FixedDelayRetry; | |
| 11 | import fr.sii.ogham.core.retry.RetryStrategy; | |
| 12 | ||
| 13 | /** | |
| 14 | * Configures retry handling based on a fixed delay. | |
| 15 | * | |
| 16 | * Retry several times with a fixed delay between each try until the maximum | |
| 17 | * attempts is reached. | |
| 18 | * | |
| 19 | * For example: | |
| 20 | * | |
| 21 | * <pre> | |
| 22 | * .delay(500) | |
| 23 | * .maxRetries(5) | |
| 24 | * </pre> | |
| 25 | * | |
| 26 | * Means that a retry will be attempted every 500ms until 5 attempts are reached | |
| 27 | * (inclusive). For example, you want to connect to an external system at t1=0 | |
| 28 | * and the connection timeout (100ms) is triggered at t2=100ms. Using this retry | |
| 29 | * will provide the following behavior: | |
| 30 | * | |
| 31 | * <ul> | |
| 32 | * <li>0: connect</li> | |
| 33 | * <li>100: timeout</li> | |
| 34 | * <li>600: connect</li> | |
| 35 | * <li>700: timeout</li> | |
| 36 | * <li>1200: connect</li> | |
| 37 | * <li>1300: timeout</li> | |
| 38 | * <li>1800: connect</li> | |
| 39 | * <li>1900: timeout</li> | |
| 40 | * <li>2400: connect</li> | |
| 41 | * <li>2500: timeout</li> | |
| 42 | * <li>3000: connect</li> | |
| 43 | * <li>3100: timeout</li> | |
| 44 | * <li>fail</li> | |
| 45 | * </ul> | |
| 46 | * | |
| 47 | * @author Aurélien Baudet | |
| 48 | * | |
| 49 | * @param <P> | |
| 50 | * the type of the parent builder (when calling {@link #and()} | |
| 51 | * method) | |
| 52 | */ | |
| 53 | public class FixedDelayBuilder<P> extends AbstractParent<P> implements Builder<RetryStrategy> { | |
| 54 | private final BuildContext buildContext; | |
| 55 | private final ConfigurationValueBuilderHelper<FixedDelayBuilder<P>, Integer> maxRetriesValueBuilder; | |
| 56 | private final ConfigurationValueBuilderHelper<FixedDelayBuilder<P>, Long> delayValueBuilder; | |
| 57 | ||
| 58 | /** | |
| 59 | * Initializes the builder with a parent builder. The parent builder is used | |
| 60 | * when calling {@link #and()} method. The {@link EnvironmentBuilder} is | |
| 61 | * used to evaluate properties when {@link #build()} method is called. | |
| 62 | * | |
| 63 | * @param parent | |
| 64 | * the parent builder | |
| 65 | * @param buildContext | |
| 66 | * for registering instances and property evaluation | |
| 67 | */ | |
| 68 | public FixedDelayBuilder(P parent, BuildContext buildContext) { | |
| 69 | super(parent); | |
| 70 | this.buildContext = buildContext; | |
| 71 | maxRetriesValueBuilder = buildContext.newConfigurationValueBuilder(this, Integer.class); | |
| 72 | delayValueBuilder = buildContext.newConfigurationValueBuilder(this, Long.class); | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Set the maximum number of attempts. | |
| 77 | * | |
| 78 | * <p> | |
| 79 | * The value set using this method takes precedence over any property and | |
| 80 | * default value configured using {@link #maxRetries()}. | |
| 81 | * | |
| 82 | * <pre> | |
| 83 | * .maxRetries(10) | |
| 84 | * .maxRetries() | |
| 85 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 86 | * .defaultValue(5) | |
| 87 | * </pre> | |
| 88 | * | |
| 89 | * <pre> | |
| 90 | * .maxRetries(10) | |
| 91 | * .maxRetries() | |
| 92 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 93 | * .defaultValue(5) | |
| 94 | * </pre> | |
| 95 | * | |
| 96 | * In both cases, {@code maxRetries(10)} is used. | |
| 97 | * | |
| 98 | * <p> | |
| 99 | * If this method is called several times, only the last value is used. | |
| 100 | * | |
| 101 | * <p> | |
| 102 | * If {@code null} value is set, it is like not setting a value at all. The | |
| 103 | * property/default value configuration is applied. | |
| 104 | * | |
| 105 | * @param maxRetries | |
| 106 | * the maximum number of attempts | |
| 107 | * @return this instance for fluent chaining | |
| 108 | */ | |
| 109 | public FixedDelayBuilder<P> maxRetries(Integer maxRetries) { | |
| 110 |
3
1. maxRetries : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE 2. maxRetries : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → TIMED_OUT 3. maxRetries : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED |
this.maxRetriesValueBuilder.setValue(maxRetries); |
| 111 |
3
1. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → NO_COVERAGE 2. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 3. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED |
return this; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Set the maximum number of attempts. | |
| 116 | * | |
| 117 | * <p> | |
| 118 | * This method is mainly used by {@link Configurer}s to register some | |
| 119 | * property keys and/or a default value. The aim is to let developer be able | |
| 120 | * to externalize its configuration (using system properties, configuration | |
| 121 | * file or anything else). If the developer doesn't configure any value for | |
| 122 | * the registered properties, the default value is used (if set). | |
| 123 | * | |
| 124 | * <pre> | |
| 125 | * .maxRetries() | |
| 126 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 127 | * .defaultValue(5) | |
| 128 | * </pre> | |
| 129 | * | |
| 130 | * <p> | |
| 131 | * Non-null value set using {@link #maxRetries(Integer)} takes precedence | |
| 132 | * over property values and default value. | |
| 133 | * | |
| 134 | * <pre> | |
| 135 | * .maxRetries(10) | |
| 136 | * .maxRetries() | |
| 137 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 138 | * .defaultValue(5) | |
| 139 | * </pre> | |
| 140 | * | |
| 141 | * The value {@code 10} is used regardless of the value of the properties | |
| 142 | * and default value. | |
| 143 | * | |
| 144 | * <p> | |
| 145 | * See {@link ConfigurationValueBuilder} for more information. | |
| 146 | * | |
| 147 | * | |
| 148 | * @return the builder to configure property keys/default value | |
| 149 | */ | |
| 150 | public ConfigurationValueBuilder<FixedDelayBuilder<P>, Integer> maxRetries() { | |
| 151 |
8
1. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → NO_COVERAGE 2. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 3. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 4. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 5. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 6. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 7. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED 8. maxRetries : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::maxRetries → KILLED |
return maxRetriesValueBuilder; |
| 152 | } | |
| 153 | ||
| 154 | /** | |
| 155 | * Set the delay between two executions (in milliseconds). | |
| 156 | * | |
| 157 | * <p> | |
| 158 | * The value set using this method takes precedence over any property and | |
| 159 | * default value configured using {@link #delay()}. | |
| 160 | * | |
| 161 | * <pre> | |
| 162 | * .delay(5000L) | |
| 163 | * .delay() | |
| 164 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 165 | * .defaultValue(10000L) | |
| 166 | * </pre> | |
| 167 | * | |
| 168 | * <pre> | |
| 169 | * .delay(5000L) | |
| 170 | * .delay() | |
| 171 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 172 | * .defaultValue(10000L) | |
| 173 | * </pre> | |
| 174 | * | |
| 175 | * In both cases, {@code delay(5000L)} is used. | |
| 176 | * | |
| 177 | * <p> | |
| 178 | * If this method is called several times, only the last value is used. | |
| 179 | * | |
| 180 | * <p> | |
| 181 | * If {@code null} value is set, it is like not setting a value at all. The | |
| 182 | * property/default value configuration is applied. | |
| 183 | * | |
| 184 | * @param delay | |
| 185 | * the time between two attempts | |
| 186 | * @return this instance for fluent chaining | |
| 187 | */ | |
| 188 | public FixedDelayBuilder<P> delay(Long delay) { | |
| 189 |
3
1. delay : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE 2. delay : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED 3. delay : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED |
delayValueBuilder.setValue(delay); |
| 190 |
3
1. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → NO_COVERAGE 2. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 3. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED |
return this; |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * Set the delay between two executions (in milliseconds). | |
| 195 | * | |
| 196 | * <p> | |
| 197 | * This method is mainly used by {@link Configurer}s to register some | |
| 198 | * property keys and/or a default value. The aim is to let developer be able | |
| 199 | * to externalize its configuration (using system properties, configuration | |
| 200 | * file or anything else). If the developer doesn't configure any value for | |
| 201 | * the registered properties, the default value is used (if set). | |
| 202 | * | |
| 203 | * <pre> | |
| 204 | * .delay() | |
| 205 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 206 | * .defaultValue(10000L) | |
| 207 | * </pre> | |
| 208 | * | |
| 209 | * <p> | |
| 210 | * Non-null value set using {@link #delay(Long)} takes precedence over | |
| 211 | * property values and default value. | |
| 212 | * | |
| 213 | * <pre> | |
| 214 | * .delay(5000L) | |
| 215 | * .delay() | |
| 216 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 217 | * .defaultValue(10000L) | |
| 218 | * </pre> | |
| 219 | * | |
| 220 | * The value {@code 5000L} is used regardless of the value of the properties | |
| 221 | * and default value. | |
| 222 | * | |
| 223 | * <p> | |
| 224 | * See {@link ConfigurationValueBuilder} for more information. | |
| 225 | * | |
| 226 | * | |
| 227 | * @return the builder to configure property keys/default value | |
| 228 | */ | |
| 229 | public ConfigurationValueBuilder<FixedDelayBuilder<P>, Long> delay() { | |
| 230 |
8
1. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → NO_COVERAGE 2. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 3. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 4. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 5. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 6. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 7. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED 8. delay : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::delay → KILLED |
return delayValueBuilder; |
| 231 | } | |
| 232 | ||
| 233 | @Override | |
| 234 | public RetryStrategy build() { | |
| 235 | int evaluatedMaxRetries = buildMaxRetries(); | |
| 236 | long evaluatedDelay = buildDelay(); | |
| 237 |
12
1. build : negated conditional → NO_COVERAGE 2. build : negated conditional → SURVIVED 3. build : negated conditional → NO_COVERAGE 4. build : negated conditional → SURVIVED 5. build : negated conditional → TIMED_OUT 6. build : negated conditional → TIMED_OUT 7. build : negated conditional → KILLED 8. build : negated conditional → KILLED 9. build : negated conditional → KILLED 10. build : negated conditional → KILLED 11. build : negated conditional → KILLED 12. build : negated conditional → KILLED |
if (evaluatedMaxRetries == 0 || evaluatedDelay == 0) { |
| 238 | return null; | |
| 239 | } | |
| 240 |
6
1. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → SURVIVED 2. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → NO_COVERAGE 3. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → TIMED_OUT 4. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → KILLED 5. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → KILLED 6. build : replaced return value with null for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::build → KILLED |
return buildContext.register(new FixedDelayRetry(evaluatedMaxRetries, evaluatedDelay)); |
| 241 | } | |
| 242 | ||
| 243 | private int buildMaxRetries() { | |
| 244 |
6
1. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → NO_COVERAGE 2. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → SURVIVED 3. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → TIMED_OUT 4. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → KILLED 5. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → KILLED 6. buildMaxRetries : replaced int return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildMaxRetries → KILLED |
return maxRetriesValueBuilder.getValue(0); |
| 245 | } | |
| 246 | ||
| 247 | private long buildDelay() { | |
| 248 |
6
1. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → SURVIVED 2. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → NO_COVERAGE 3. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → TIMED_OUT 4. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → KILLED 5. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → KILLED 6. buildDelay : replaced long return with 0 for fr/sii/ogham/core/builder/retry/FixedDelayBuilder::buildDelay → KILLED |
return delayValueBuilder.getValue(0L); |
| 249 | } | |
| 250 | } | |
Mutations | ||
| 110 |
1.1 2.2 3.3 |
|
| 111 |
1.1 2.2 3.3 |
|
| 151 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 189 |
1.1 2.2 3.3 |
|
| 190 |
1.1 2.2 3.3 |
|
| 230 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 237 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
| 240 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 244 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 248 |
1.1 2.2 3.3 4.4 5.5 6.6 |