Skip to content

Commit

Permalink
improve: remove deprecated RetryConfiguration (#2211)
Browse files Browse the repository at this point in the history

Signed-off-by: Attila Mészáros <csviri@gmail.com>
  • Loading branch information
csviri committed Feb 5, 2024
1 parent b9e55bd commit c85b9e0
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
import io.javaoperatorsdk.operator.processing.retry.GenericRetry;
import io.javaoperatorsdk.operator.processing.retry.GradualRetry;
import io.javaoperatorsdk.operator.processing.retry.Retry;

public interface ControllerConfiguration<P extends HasMetadata> extends ResourceConfiguration<P> {
Expand Down Expand Up @@ -58,22 +57,7 @@ default boolean isGenerationAware() {
String getAssociatedReconcilerClassName();

default Retry getRetry() {
final var configuration = getRetryConfiguration();
return !RetryConfiguration.DEFAULT.equals(configuration)
? GenericRetry.fromConfiguration(configuration)
: GenericRetry.DEFAULT; // NOSONAR
}

/**
* Use {@link #getRetry()} instead.
*
* @return configuration for retry.
* @deprecated provide your own {@link Retry} implementation or use the {@link GradualRetry}
* annotation instead
*/
@Deprecated(forRemoval = true)
default RetryConfiguration getRetryConfiguration() {
return RetryConfiguration.DEFAULT;
return GenericRetry.DEFAULT;
}

@SuppressWarnings("rawtypes")
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.javaoperatorsdk.operator.processing.retry;

import io.javaoperatorsdk.operator.api.config.AnnotationConfigurable;
import io.javaoperatorsdk.operator.api.config.RetryConfiguration;

public class GenericRetry implements Retry, AnnotationConfigurable<GradualRetry> {
private int maxAttempts = GradualRetry.DEFAULT_MAX_ATTEMPTS;
Expand All @@ -19,23 +18,6 @@ public static GenericRetry noRetry() {
return new GenericRetry().setMaxAttempts(0);
}

/**
* @deprecated Use the {@link GradualRetry} annotation instead
*
* @param configuration retry config
* @return Retry instance
*/
@Deprecated(forRemoval = true)
public static Retry fromConfiguration(RetryConfiguration configuration) {
return configuration == null ? defaultLimitedExponentialRetry()
: new GenericRetry()
.setInitialInterval(configuration.getInitialInterval())
.setMaxAttempts(configuration.getMaxAttempts())
.setIntervalMultiplier(configuration.getIntervalMultiplier())
.setMaxInterval(configuration.getMaxInterval());
}


public static GenericRetry every10second10TimesRetry() {
return new GenericRetry().withLinearRetry().setMaxAttempts(10).setInitialInterval(10000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.javaoperatorsdk.operator.api.config.BaseConfigurationService;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.RetryConfiguration;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
Expand All @@ -28,6 +27,7 @@
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEvent;
import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource;
import io.javaoperatorsdk.operator.processing.retry.GenericRetry;
import io.javaoperatorsdk.operator.processing.retry.GradualRetry;
import io.javaoperatorsdk.operator.processing.retry.Retry;
import io.javaoperatorsdk.operator.processing.retry.RetryExecution;
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
Expand Down Expand Up @@ -135,7 +135,7 @@ void schedulesAnEventRetryOnException() {

verify(retryTimerEventSourceMock, times(1))
.scheduleOnce(eq(ResourceID.fromResource(customResource)),
eq(RetryConfiguration.DEFAULT_INITIAL_INTERVAL));
eq(GradualRetry.DEFAULT_INITIAL_INTERVAL));
}

@Test
Expand Down Expand Up @@ -167,7 +167,7 @@ void executesTheControllerInstantlyAfterErrorIfNewEventsReceived() {
assertThat(allValues).hasSize(2);
verify(retryTimerEventSourceMock, never())
.scheduleOnce(eq(ResourceID.fromResource(customResource)),
eq(RetryConfiguration.DEFAULT_INITIAL_INTERVAL));
eq(GradualRetry.DEFAULT_INITIAL_INTERVAL));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,10 @@

import org.junit.jupiter.api.Test;

import io.javaoperatorsdk.operator.api.config.RetryConfiguration;

import static org.assertj.core.api.Assertions.assertThat;

public class GenericRetryExecutionTest {

@Test
public void forFirstBackOffAlwaysReturnsInitialInterval() {
assertThat(getDefaultRetryExecution().nextDelay().get())
.isEqualTo(RetryConfiguration.DEFAULT_INITIAL_INTERVAL);
}

@Test
public void delayIsMultipliedEveryNextDelayCall() {
RetryExecution retryExecution = getDefaultRetryExecution();

Optional<Long> res = callNextDelayNTimes(retryExecution, 1);
assertThat(res.get()).isEqualTo(RetryConfiguration.DEFAULT_INITIAL_INTERVAL);

res = retryExecution.nextDelay();
assertThat(res.get())
.isEqualTo((long) (RetryConfiguration.DEFAULT_INITIAL_INTERVAL
* RetryConfiguration.DEFAULT_MULTIPLIER));

res = retryExecution.nextDelay();
assertThat(res.get())
.isEqualTo(
(long) (RetryConfiguration.DEFAULT_INITIAL_INTERVAL
* RetryConfiguration.DEFAULT_MULTIPLIER
* RetryConfiguration.DEFAULT_MULTIPLIER));
}

@Test
public void noNextDelayIfMaxAttemptLimitReached() {
RetryExecution retryExecution =
Expand Down

0 comments on commit c85b9e0

Please sign in to comment.