Skip to content

Commit b1d9f1d

Browse files
committed
renaming from PR comments, test info message
1 parent 1affee4 commit b1d9f1d

File tree

7 files changed

+31
-41
lines changed

7 files changed

+31
-41
lines changed
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
package io.javaoperatorsdk.operator.api;
22

3-
public class RetryInfo {
3+
public interface RetryInfo {
44

5-
private int attemptIndex;
6-
private boolean lastAttempt;
5+
int getAttemptCount();
76

8-
public RetryInfo(int retryNumber, boolean lastAttempt) {
9-
this.attemptIndex = retryNumber;
10-
this.lastAttempt = lastAttempt;
11-
}
12-
13-
public int getAttemptIndex() {
14-
return attemptIndex;
15-
}
16-
17-
public boolean isLastAttempt() {
18-
return lastAttempt;
19-
}
20-
21-
@Override
22-
public String toString() {
23-
return "RetryInfo{" + "attemptIndex=" + attemptIndex + ", lastAttempt=" + lastAttempt + '}';
24-
}
7+
boolean isLastAttempt();
258
}

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ private void executeBufferedEvents(String customResourceUid) {
103103
}
104104

105105
private RetryInfo retryInfo(String customResourceUid) {
106-
RetryExecution retryExecution = retryState.get(customResourceUid);
107-
if (retryExecution != null) {
108-
return new RetryInfo(retryExecution.getCurrentAttemptIndex(), retryExecution.isLastAttempt());
109-
} else {
110-
return null;
111-
}
106+
return retryState.get(customResourceUid);
112107
}
113108

114109
void eventProcessingFinished(

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public boolean isLastAttempt() {
3434
}
3535

3636
@Override
37-
public int getCurrentAttemptIndex() {
37+
public int getAttemptCount() {
3838
return lastAttemptIndex;
3939
}
4040
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.javaoperatorsdk.operator.processing.retry;
22

3+
import io.javaoperatorsdk.operator.api.RetryInfo;
34
import java.util.Optional;
45

5-
public interface RetryExecution {
6+
public interface RetryExecution extends RetryInfo {
67

78
/**
89
* Calculates the delay for the next execution. This method should return 0, when called first
@@ -11,12 +12,4 @@ public interface RetryExecution {
1112
* @return
1213
*/
1314
Optional<Long> nextDelay();
14-
15-
/**
16-
* @return true, if the last returned delay is, the last returned values, thus there will be no
17-
* further retry
18-
*/
19-
boolean isLastAttempt();
20-
21-
int getCurrentAttemptIndex();
2215
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/EventDispatcherTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,27 @@ void executeControllerRegardlessGenerationInNonGenerationAwareMode() {
187187
@Test
188188
void propagatesRetryInfoToContext() {
189189
eventDispatcher.handleExecution(
190-
new ExecutionScope(Arrays.asList(), testCustomResource, new RetryInfo(2, true)));
190+
new ExecutionScope(
191+
Arrays.asList(),
192+
testCustomResource,
193+
new RetryInfo() {
194+
@Override
195+
public int getAttemptCount() {
196+
return 2;
197+
}
198+
199+
@Override
200+
public boolean isLastAttempt() {
201+
return true;
202+
}
203+
}));
191204

192205
ArgumentCaptor<Context<CustomResource>> contextArgumentCaptor =
193206
ArgumentCaptor.forClass(Context.class);
194207
verify(controller, times(1))
195208
.createOrUpdateResource(eq(testCustomResource), contextArgumentCaptor.capture());
196209
Context<CustomResource> context = contextArgumentCaptor.getValue();
197-
assertThat(context.getRetryInfo().get().getAttemptIndex()).isEqualTo(2);
210+
assertThat(context.getRetryInfo().get().getAttemptCount()).isEqualTo(2);
198211
assertThat(context.getRetryInfo().get().isLastAttempt()).isEqualTo(true);
199212
}
200213

operator-framework/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
import org.junit.jupiter.api.Test;
2727
import org.mockito.ArgumentCaptor;
2828
import org.mockito.stubbing.Answer;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931

3032
class DefaultEventHandlerTest {
3133

34+
private static final Logger log = LoggerFactory.getLogger(DefaultEventHandlerTest.class);
35+
3236
public static final int FAKE_CONTROLLER_EXECUTION_DURATION = 250;
3337
public static final int SEPARATE_EXECUTION_TIMEOUT = 450;
3438
private EventDispatcher eventDispatcherMock = mock(EventDispatcher.class);
@@ -160,6 +164,8 @@ public void executesTheControllerInstantlyAfterErrorIfEventsBuffered() {
160164

161165
@Test
162166
public void successfulExecutionResetsTheRetry() {
167+
log.info("Starting successfulExecutionResetsTheRetry");
168+
163169
Event event = prepareCREvent();
164170
TestCustomResource customResource = testCustomResource();
165171
customResource.getMetadata().setUid(event.getRelatedCustomResourceUid());
@@ -187,7 +193,7 @@ public void successfulExecutionResetsTheRetry() {
187193
assertThat(executionScopes).hasSize(3);
188194
assertThat(executionScopes.get(0).getRetryInfo()).isNull();
189195
assertThat(executionScopes.get(2).getRetryInfo()).isNull();
190-
assertThat(executionScopes.get(1).getRetryInfo().getAttemptIndex()).isEqualTo(1);
196+
assertThat(executionScopes.get(1).getRetryInfo().getAttemptCount()).isEqualTo(1);
191197
assertThat(executionScopes.get(1).getRetryInfo().isLastAttempt()).isEqualTo(false);
192198
}
193199

operator-framework/src/test/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecutionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public void supportsIsLastExecution() {
7878
public void returnAttemptIndex() {
7979
RetryExecution retryExecution = GenericRetry.defaultLimitedExponentialRetry().initExecution();
8080

81-
assertThat(retryExecution.getCurrentAttemptIndex()).isEqualTo(0);
81+
assertThat(retryExecution.getAttemptCount()).isEqualTo(0);
8282
retryExecution.nextDelay();
83-
assertThat(retryExecution.getCurrentAttemptIndex()).isEqualTo(1);
83+
assertThat(retryExecution.getAttemptCount()).isEqualTo(1);
8484
}
8585

8686
private RetryExecution getDefaultRetryExecution() {

0 commit comments

Comments
 (0)