Skip to content

Commit 3a840a7

Browse files
committed
comments on integration tests
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 4b80885 commit 3a840a7

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/triggerallevent/onlyreconcile/TriggerReconcilerOnAllEventIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ void eventsPresent() {
5151
() -> {
5252
var r = getResource();
5353
assertThat(r).isNull();
54+
// check if reconciler also triggered when delete event received
5455
assertThat(reconciler.isDeleteEventPresent()).isTrue();
56+
// also when it was marked for deletion
5557
assertThat(reconciler.isEventOnMarkedForDeletion()).isTrue();
5658
});
5759
}
@@ -96,6 +98,10 @@ void retriesExceptionOnDeleteEvent() {
9698
});
9799
}
98100

101+
/**
102+
* Checks if we receive event even after our finalizer is removed but there is an additional
103+
* finalizer
104+
*/
99105
@Test
100106
void additionalFinalizer() {
101107
var reconciler = extension.getReconcilerOfType(TriggerReconcilerOnAllEventReconciler.class);
@@ -129,6 +135,10 @@ void additionalFinalizer() {
129135
});
130136
}
131137

138+
// tests the situation where we received a delete event, but there is an exception during
139+
// reconiliation
140+
// what is retried, but during retry we receive an additional event, that should instantly
141+
// trigger the reconciliation again when current finished.
132142
@Test
133143
void additionalEventDuringRetryOnDeleteEvent() {
134144

@@ -154,9 +164,11 @@ void additionalEventDuringRetryOnDeleteEvent() {
154164
assertThat(reconciler.isWaiting());
155165
});
156166

167+
// trigger reconciliation while waiting in reconciler
157168
res = getResource();
158169
res.getMetadata().getAnnotations().put("my-annotation", "true");
159170
extension.update(res);
171+
// continue reconciliation
160172
reconciler.setContinuerOnRetryWait(true);
161173

162174
await()
@@ -188,7 +200,6 @@ void additionalEventDuringRetryOnDeleteEvent() {
188200

189201
@Test
190202
void additionalEventAfterExhaustedRetry() {
191-
192203
var reconciler = extension.getReconcilerOfType(TriggerReconcilerOnAllEventReconciler.class);
193204
reconciler.setThrowExceptionIfNoAnnotation(true);
194205
var res = testResource();
@@ -203,6 +214,7 @@ void additionalEventAfterExhaustedRetry() {
203214
assertThat(reconciler.getEventCount()).isEqualTo(MAX_RETRY_ATTEMPTS + 1);
204215
});
205216

217+
// this also triggers the reconciliation
206218
addNoMoreExceptionAnnotation();
207219

208220
await()

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/triggerallevent/onlyreconcile/TriggerReconcilerOnAllEventReconciler.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,34 @@
1515
public class TriggerReconcilerOnAllEventReconciler
1616
implements Reconciler<TriggerReconcilerOnAllEventCustomResource> {
1717

18+
public static final String FINALIZER = "all.event.mode/finalizer";
19+
public static final String ADDITIONAL_FINALIZER = "all.event.mode/finalizer2";
20+
public static final String NO_MORE_EXCEPTION_ANNOTATION_KEY = "no.more.exception";
21+
1822
private static final Logger log =
1923
LoggerFactory.getLogger(TriggerReconcilerOnAllEventReconciler.class);
2024

25+
// control flags to throw exceptions in certain situations
2126
private volatile boolean throwExceptionOnFirstDeleteEvent = false;
2227
private volatile boolean throwExceptionIfNoAnnotation = false;
2328

29+
// flags for managing wait within reconciliation,
30+
// so we can send an update while reconciliation is in progress
2431
private volatile boolean waitAfterFirstRetry = false;
2532
private volatile boolean continuerOnRetryWait = false;
2633
private volatile boolean waiting = false;
2734

35+
// control flag to throw an exception on first delete event
2836
private volatile boolean isFirstDeleteEvent = true;
37+
// control if the reconciler should add / remove the finalizer
38+
private volatile boolean useFinalizer = true;
2939

30-
public static final String FINALIZER = "all.event.mode/finalizer";
31-
public static final String ADDITIONAL_FINALIZER = "all.event.mode/finalizer2";
32-
public static final String NO_MORE_EXCEPTION_ANNOTATION_KEY = "no.more.exception";
33-
34-
protected volatile boolean useFinalizer = true;
35-
36-
private final AtomicInteger eventCounter = new AtomicInteger(0);
37-
40+
// flags to flip if reconciled primary resource in certain state
3841
private boolean deleteEventPresent = false;
3942
private boolean eventOnMarkedForDeletion = false;
4043
private boolean resourceEventPresent = false;
44+
// counter for how many times the reconciler has been called
45+
private final AtomicInteger reconciliationCounter = new AtomicInteger(0);
4146

4247
@Override
4348
public UpdateControl<TriggerReconcilerOnAllEventCustomResource> reconcile(
@@ -143,11 +148,11 @@ public void setWaiting(boolean waiting) {
143148
}
144149

145150
public int getEventCount() {
146-
return eventCounter.get();
151+
return reconciliationCounter.get();
147152
}
148153

149154
public void increaseEventCount() {
150-
eventCounter.incrementAndGet();
155+
reconciliationCounter.incrementAndGet();
151156
}
152157

153158
public boolean getUseFinalizer() {

0 commit comments

Comments
 (0)