Skip to content

Commit bc53528

Browse files
metacosmcsviri
authored andcommitted
fix: restore backwards compatibility
1 parent aee5d59 commit bc53528

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TimerEventSource<R extends HasMetadata>
2424
private final AtomicBoolean running = new AtomicBoolean();
2525
private final Map<ResourceID, EventProducerTimeTask> onceTasks = new ConcurrentHashMap<>();
2626

27+
public void scheduleOnce(R resource, long delay) {
28+
scheduleOnce(ResourceID.fromResource(resource), delay);
29+
}
2730

2831
public void scheduleOnce(ResourceID resourceID, long delay) {
2932
if (!running.get()) {

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@
3232
import static org.awaitility.Awaitility.await;
3333
import static org.mockito.ArgumentMatchers.eq;
3434
import static org.mockito.ArgumentMatchers.isNull;
35-
import static org.mockito.Mockito.*;
36-
35+
import static org.mockito.Mockito.after;
36+
import static org.mockito.Mockito.any;
37+
import static org.mockito.Mockito.anyLong;
38+
import static org.mockito.Mockito.doAnswer;
39+
import static org.mockito.Mockito.mock;
40+
import static org.mockito.Mockito.never;
41+
import static org.mockito.Mockito.spy;
42+
import static org.mockito.Mockito.timeout;
43+
import static org.mockito.Mockito.times;
44+
import static org.mockito.Mockito.verify;
45+
import static org.mockito.Mockito.when;
46+
47+
@SuppressWarnings({"rawtypes", "unchecked"})
3748
class EventProcessorTest {
3849

3950
private static final Logger log = LoggerFactory.getLogger(EventProcessorTest.class);
@@ -42,16 +53,16 @@ class EventProcessorTest {
4253
public static final int SEPARATE_EXECUTION_TIMEOUT = 450;
4354
public static final String TEST_NAMESPACE = "default-event-handler-test";
4455

45-
private ReconciliationDispatcher reconciliationDispatcherMock =
56+
private final ReconciliationDispatcher reconciliationDispatcherMock =
4657
mock(ReconciliationDispatcher.class);
47-
private EventSourceManager eventSourceManagerMock = mock(EventSourceManager.class);
48-
private TimerEventSource retryTimerEventSourceMock = mock(TimerEventSource.class);
49-
private ControllerResourceEventSource controllerResourceEventSourceMock =
58+
private final EventSourceManager eventSourceManagerMock = mock(EventSourceManager.class);
59+
private final TimerEventSource retryTimerEventSourceMock = mock(TimerEventSource.class);
60+
private final ControllerResourceEventSource controllerResourceEventSourceMock =
5061
mock(ControllerResourceEventSource.class);
51-
private Metrics metricsMock = mock(Metrics.class);
62+
private final Metrics metricsMock = mock(Metrics.class);
5263
private EventProcessor eventProcessor;
5364
private EventProcessor eventProcessorWithRetry;
54-
private RateLimiter rateLimiterMock = mock(RateLimiter.class);
65+
private final RateLimiter rateLimiterMock = mock(RateLimiter.class);
5566

5667
@BeforeEach
5768
void setup() {
@@ -89,7 +100,7 @@ void skipProcessingIfLatestCustomResourceNotInCache() {
89100
}
90101

91102
@Test
92-
void ifExecutionInProgressWaitsUntilItsFinished() throws InterruptedException {
103+
void ifExecutionInProgressWaitsUntilItsFinished() {
93104
ResourceID resourceUid = eventAlreadyUnderProcessing();
94105

95106
eventProcessor.handleEvent(nonCREvent(resourceUid));
@@ -204,7 +215,7 @@ void scheduleTimedEventIfInstructedByPostExecutionControl() {
204215
eventProcessor.handleEvent(prepareCREvent());
205216

206217
verify(retryTimerEventSourceMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(1))
207-
.scheduleOnce(any(), eq(testDelay));
218+
.scheduleOnce((HasMetadata) any(), eq(testDelay));
208219
}
209220

210221
@Test
@@ -220,7 +231,7 @@ void reScheduleOnlyIfNotExecutedEventsReceivedMeanwhile() throws InterruptedExce
220231

221232
verify(retryTimerEventSourceMock,
222233
after((long) (FAKE_CONTROLLER_EXECUTION_DURATION * 1.5)).times(0))
223-
.scheduleOnce(any(), eq(testDelay));
234+
.scheduleOnce((HasMetadata) any(), eq(testDelay));
224235
}
225236

226237
@Test
@@ -335,7 +346,7 @@ void newResourceAfterMissedDeleteEvent() {
335346
}
336347

337348
@Test
338-
void rateLimitsReconciliationSubmission() throws InterruptedException {
349+
void rateLimitsReconciliationSubmission() {
339350
// the refresh period value does not matter here
340351
var refreshPeriod = Duration.ofMillis(100);
341352
var event = prepareCREvent();
@@ -347,10 +358,10 @@ void rateLimitsReconciliationSubmission() throws InterruptedException {
347358
eventProcessor.handleEvent(event);
348359
verify(reconciliationDispatcherMock, after(FAKE_CONTROLLER_EXECUTION_DURATION).times(1))
349360
.handleExecution(any());
350-
verify(retryTimerEventSourceMock, times(0)).scheduleOnce(any(), anyLong());
361+
verify(retryTimerEventSourceMock, times(0)).scheduleOnce((HasMetadata) any(), anyLong());
351362

352363
eventProcessor.handleEvent(event);
353-
verify(retryTimerEventSourceMock, times(1)).scheduleOnce(any(), anyLong());
364+
verify(retryTimerEventSourceMock, times(1)).scheduleOnce((HasMetadata) any(), anyLong());
354365
}
355366

356367
private ResourceID eventAlreadyUnderProcessing() {

0 commit comments

Comments
 (0)