Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: remove deprecated RetryConfiguration #2211

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading