Skip to content

Commit 64c9212

Browse files
committed
improve and add unit test for event processor
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 3a840a7 commit 64c9212

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ void newResourceAfterMissedDeleteEvent() {
390390

391391
@Test
392392
void rateLimitsReconciliationSubmission() {
393+
when(reconciliationDispatcherMock.handleExecution(any()))
394+
.thenReturn(PostExecutionControl.defaultDispatch());
393395
// the refresh defaultPollingPeriod value does not matter here
394396
var refreshPeriod = Duration.ofMillis(100);
395397
var event = prepareCREvent();
@@ -403,10 +405,12 @@ void rateLimitsReconciliationSubmission() {
403405
eventProcessor.handleEvent(event);
404406
verify(reconciliationDispatcherMock, after(FAKE_CONTROLLER_EXECUTION_DURATION).times(1))
405407
.handleExecution(any());
406-
verify(retryTimerEventSourceMock, times(0)).scheduleOnce((ResourceID) any(), anyLong());
408+
verify(retryTimerEventSourceMock, times(0))
409+
.scheduleOnce((ResourceID) any(), eq(refreshPeriod.toMillis()));
407410

408411
eventProcessor.handleEvent(event);
409-
verify(retryTimerEventSourceMock, times(1)).scheduleOnce((ResourceID) any(), anyLong());
412+
verify(retryTimerEventSourceMock, times(1))
413+
.scheduleOnce((ResourceID) any(), eq(refreshPeriod.toMillis()));
410414
}
411415

412416
@Test
@@ -662,6 +666,45 @@ void afterRetryExhaustedAdditionalEventTriggerReconciliationWhenDeleteEventPrese
662666
verify(reconciliationDispatcherMock, times(4)).handleExecution(any());
663667
}
664668

669+
@Test
670+
void rateLimitsDeleteEventInAllEventMode() {
671+
when(eventSourceManagerMock.retryEventSource()).thenReturn(retryTimerEventSourceMock);
672+
when(reconciliationDispatcherMock.handleExecution(any()))
673+
.thenReturn(PostExecutionControl.defaultDispatch());
674+
eventProcessor =
675+
spy(
676+
new EventProcessor(
677+
controllerConfigTriggerAllEvent(
678+
GenericRetry.defaultLimitedExponentialRetry()
679+
.setInitialInterval(100)
680+
.setIntervalMultiplier(1)
681+
.setMaxAttempts(1),
682+
rateLimiterMock),
683+
reconciliationDispatcherMock,
684+
eventSourceManagerMock,
685+
null));
686+
eventProcessor.start();
687+
// the refresh defaultPollingPeriod value does not matter here
688+
var refreshPeriod = Duration.ofMillis(100);
689+
var event = prepareCREvent();
690+
691+
final var rateLimit = new RateLimitState() {};
692+
when(rateLimiterMock.initState()).thenReturn(rateLimit);
693+
when(rateLimiterMock.isLimited(rateLimit))
694+
.thenReturn(Optional.empty())
695+
.thenReturn(Optional.of(refreshPeriod));
696+
697+
eventProcessor.handleEvent(event);
698+
verify(reconciliationDispatcherMock, after(FAKE_CONTROLLER_EXECUTION_DURATION).times(1))
699+
.handleExecution(any());
700+
verify(retryTimerEventSourceMock, times(0))
701+
.scheduleOnce((ResourceID) any(), eq(refreshPeriod.toMillis()));
702+
703+
eventProcessor.handleEvent(event);
704+
verify(retryTimerEventSourceMock, times(1))
705+
.scheduleOnce((ResourceID) any(), eq(refreshPeriod.toMillis()));
706+
}
707+
665708
@Test
666709
void passesResourceFromStateToDispatcher() {
667710
eventProcessor =

0 commit comments

Comments
 (0)