1
1
package io .javaoperatorsdk .operator ;
2
2
3
+ import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
4
+ import io .fabric8 .kubernetes .client .CustomResource ;
5
+ import io .fabric8 .kubernetes .client .Watcher ;
3
6
import io .javaoperatorsdk .operator .processing .CustomResourceEvent ;
4
7
import io .javaoperatorsdk .operator .processing .EventDispatcher ;
5
8
import io .javaoperatorsdk .operator .processing .EventScheduler ;
6
9
import io .javaoperatorsdk .operator .processing .retry .GenericRetry ;
7
10
import 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 ;
11
11
import org .assertj .core .api .Condition ;
12
12
import org .junit .jupiter .api .Test ;
13
- import org .mockito .ArgumentMatcher ;
14
13
import org .mockito .ArgumentMatchers ;
15
14
import org .mockito .invocation .InvocationOnMock ;
16
15
import org .slf4j .Logger ;
@@ -31,12 +30,10 @@ class EventSchedulerTest {
31
30
32
31
public static final int INVOCATION_DURATION = 80 ;
33
32
public static final int MAX_RETRY_ATTEMPTS = 3 ;
34
- @ SuppressWarnings ("unchecked" )
35
- private EventDispatcher eventDispatcher = mock (EventDispatcher .class );
36
-
37
- private EventScheduler eventScheduler = initScheduler ();
38
33
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 <>());
40
37
41
38
42
39
@ Test
@@ -54,7 +51,7 @@ public void schedulesEvent() {
54
51
}
55
52
56
53
@ Test
57
- public void eventsAreNotExecutedConcurrentlyForSameResource () throws InterruptedException {
54
+ public void eventsAreNotExecutedConcurrentlyForSameResource () {
58
55
normalDispatcherExecution ();
59
56
CustomResource resource1 = sampleResource ();
60
57
CustomResource resource2 = sampleResource ();
@@ -141,18 +138,8 @@ public void processesNewEventIfItIsReceivedAfterExecutionInError() {
141
138
CustomResource resource2 = sampleResource ();
142
139
resource2 .getMetadata ().setResourceVersion ("2" );
143
140
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 )));
156
143
157
144
eventScheduler .eventReceived (Watcher .Action .MODIFIED , resource1 );
158
145
eventScheduler .eventReceived (Watcher .Action .MODIFIED , resource2 );
@@ -203,9 +190,6 @@ private Object normalExecution(InvocationOnMock invocation) {
203
190
}
204
191
205
192
206
-
207
-
208
-
209
193
private EventScheduler initScheduler () {
210
194
return new EventScheduler (eventDispatcher , new GenericRetry ().setMaxAttempts (MAX_RETRY_ATTEMPTS ).withLinearRetry ());
211
195
}
@@ -262,11 +246,11 @@ CustomResource sampleResource() {
262
246
}
263
247
264
248
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 ;
270
254
271
255
public EventProcessingDetail (Watcher .Action action , LocalDateTime startTime , LocalDateTime endTime , CustomResource customResource , Exception exception ) {
272
256
this .action = action ;
@@ -281,42 +265,14 @@ public EventProcessingDetail(Watcher.Action action, LocalDateTime startTime, Loc
281
265
this (action , startTime , endTime , customResource , null );
282
266
}
283
267
284
- public LocalDateTime getStartTime () {
285
- return startTime ;
286
- }
287
-
288
- public EventProcessingDetail setStartTime (LocalDateTime startTime ) {
289
- this .startTime = startTime ;
290
- return this ;
291
- }
292
-
293
268
public LocalDateTime getEndTime () {
294
269
return endTime ;
295
270
}
296
271
297
- public EventProcessingDetail setEndTime (LocalDateTime endTime ) {
298
- this .endTime = endTime ;
299
- return this ;
300
- }
301
-
302
272
public CustomResource getCustomResource () {
303
273
return customResource ;
304
274
}
305
275
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
-
320
276
public Exception getException () {
321
277
return exception ;
322
278
}
0 commit comments