11package io .javaoperatorsdk .operator ;
22
3+ import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
4+ import io .fabric8 .kubernetes .client .CustomResource ;
5+ import io .fabric8 .kubernetes .client .Watcher ;
36import io .javaoperatorsdk .operator .processing .CustomResourceEvent ;
47import io .javaoperatorsdk .operator .processing .EventDispatcher ;
58import io .javaoperatorsdk .operator .processing .EventScheduler ;
69import io .javaoperatorsdk .operator .processing .retry .GenericRetry ;
710import io .javaoperatorsdk .operator .sample .TestCustomResource ;
8- import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
9- import io .fabric8 .kubernetes .client .CustomResource ;
10- import io .fabric8 .kubernetes .client .Watcher ;
1111import org .assertj .core .api .Condition ;
1212import org .junit .jupiter .api .Test ;
13- import org .mockito .ArgumentMatcher ;
1413import org .mockito .ArgumentMatchers ;
1514import org .mockito .invocation .InvocationOnMock ;
1615import org .slf4j .Logger ;
@@ -31,12 +30,10 @@ class EventSchedulerTest {
3130
3231 public static final int INVOCATION_DURATION = 80 ;
3332 public static final int MAX_RETRY_ATTEMPTS = 3 ;
34- @ SuppressWarnings ("unchecked" )
35- private EventDispatcher eventDispatcher = mock (EventDispatcher .class );
36-
37- private EventScheduler eventScheduler = initScheduler ();
3833
39- private List <EventProcessingDetail > eventProcessingList = Collections .synchronizedList (new ArrayList <>());
34+ private final EventDispatcher eventDispatcher = mock (EventDispatcher .class );
35+ private final EventScheduler eventScheduler = initScheduler ();
36+ private final List <EventProcessingDetail > eventProcessingList = Collections .synchronizedList (new ArrayList <>());
4037
4138
4239 @ Test
@@ -54,7 +51,7 @@ public void schedulesEvent() {
5451 }
5552
5653 @ Test
57- public void eventsAreNotExecutedConcurrentlyForSameResource () throws InterruptedException {
54+ public void eventsAreNotExecutedConcurrentlyForSameResource () {
5855 normalDispatcherExecution ();
5956 CustomResource resource1 = sampleResource ();
6057 CustomResource resource2 = sampleResource ();
@@ -141,18 +138,8 @@ public void processesNewEventIfItIsReceivedAfterExecutionInError() {
141138 CustomResource resource2 = sampleResource ();
142139 resource2 .getMetadata ().setResourceVersion ("2" );
143140
144- doAnswer (this ::exceptionInExecution ).when (eventDispatcher ).handleEvent (ArgumentMatchers .argThat (new ArgumentMatcher <CustomResourceEvent >() {
145- @ Override
146- public boolean matches (CustomResourceEvent event ) {
147- return event .getResource ().equals (resource1 );
148- }
149- }));
150- doAnswer (this ::normalExecution ).when (eventDispatcher ).handleEvent (ArgumentMatchers .argThat (new ArgumentMatcher <CustomResourceEvent >() {
151- @ Override
152- public boolean matches (CustomResourceEvent event ) {
153- return event .getResource ().equals (resource2 );
154- }
155- }));
141+ doAnswer (this ::exceptionInExecution ).when (eventDispatcher ).handleEvent (ArgumentMatchers .argThat (event -> event .getResource ().equals (resource1 )));
142+ doAnswer (this ::normalExecution ).when (eventDispatcher ).handleEvent (ArgumentMatchers .argThat (event -> event .getResource ().equals (resource2 )));
156143
157144 eventScheduler .eventReceived (Watcher .Action .MODIFIED , resource1 );
158145 eventScheduler .eventReceived (Watcher .Action .MODIFIED , resource2 );
@@ -203,9 +190,6 @@ private Object normalExecution(InvocationOnMock invocation) {
203190 }
204191
205192
206-
207-
208-
209193 private EventScheduler initScheduler () {
210194 return new EventScheduler (eventDispatcher , new GenericRetry ().setMaxAttempts (MAX_RETRY_ATTEMPTS ).withLinearRetry ());
211195 }
@@ -262,11 +246,11 @@ CustomResource sampleResource() {
262246 }
263247
264248 private static class EventProcessingDetail {
265- private Watcher .Action action ;
266- private LocalDateTime startTime ;
267- private LocalDateTime endTime ;
268- private CustomResource customResource ;
269- private Exception exception ;
249+ private final Watcher .Action action ;
250+ private final LocalDateTime startTime ;
251+ private final LocalDateTime endTime ;
252+ private final CustomResource customResource ;
253+ private final Exception exception ;
270254
271255 public EventProcessingDetail (Watcher .Action action , LocalDateTime startTime , LocalDateTime endTime , CustomResource customResource , Exception exception ) {
272256 this .action = action ;
@@ -281,42 +265,14 @@ public EventProcessingDetail(Watcher.Action action, LocalDateTime startTime, Loc
281265 this (action , startTime , endTime , customResource , null );
282266 }
283267
284- public LocalDateTime getStartTime () {
285- return startTime ;
286- }
287-
288- public EventProcessingDetail setStartTime (LocalDateTime startTime ) {
289- this .startTime = startTime ;
290- return this ;
291- }
292-
293268 public LocalDateTime getEndTime () {
294269 return endTime ;
295270 }
296271
297- public EventProcessingDetail setEndTime (LocalDateTime endTime ) {
298- this .endTime = endTime ;
299- return this ;
300- }
301-
302272 public CustomResource getCustomResource () {
303273 return customResource ;
304274 }
305275
306- public EventProcessingDetail setCustomResource (CustomResource customResource ) {
307- this .customResource = customResource ;
308- return this ;
309- }
310-
311- public Watcher .Action getAction () {
312- return action ;
313- }
314-
315- public EventProcessingDetail setAction (Watcher .Action action ) {
316- this .action = action ;
317- return this ;
318- }
319-
320276 public Exception getException () {
321277 return exception ;
322278 }
0 commit comments