10000 fix tests · rguillens/java-operator-sdk@46af13e · GitHub
[go: up one dir, main page]

Skip to content

Commit 46af13e

Browse files
author
Soroosh Sarabadani
committed
fix tests
1 parent 85c09bc commit 46af13e

File tree

2 files changed

+17
-62
lines changed

2 files changed

+17
-62
lines changed

operator-framework/src/test/java/io/javaoperatorsdk/operator/ControllerUtilsTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@
1010
import org.junit.jupiter.api.Assertions;
1111
import org.junit.jupiter.api.Test;
1212

13-
import static org.junit.jupiter.api.Assertions.assertEquals;
14-
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.*;
1514

1615
class ControllerUtilsTest {
1716

1817
public static final String CUSTOM_FINALIZER_NAME = "a.customer.finalizer";
1918

2019
@Test
2120
public void returnsValuesFromControllerAnnotationFinalizer() {
22-
Assertions.assertEquals(TestCustomResourceController.class.getCanonicalName(), ControllerUtils.getFinalizer(new TestCustomResourceController(null)));
21+
Assertions.assertEquals(TestCustomResourceController.CRD_NAME, ControllerUtils.getFinalizer(new TestCustomResourceController(null)));
2322
assertEquals(TestCustomResource.class, ControllerUtils.getCustomResourceClass(new TestCustomResourceController(null)));
2423
Assertions.assertEquals(TestCustomResourceController.CRD_NAME, ControllerUtils.getCrdName(new TestCustomResourceController(null)));
25-
assertEquals(false, ControllerUtils.getGenerationEventProcessing(new TestCustomResourceController(null)));
24+
assertFalse(ControllerUtils.getGenerationEventProcessing(new TestCustomResourceController(null)));
2625
assertTrue(CustomResourceDoneable.class.isAssignableFrom(ControllerUtils.getCustomResourceDoneableClass(new TestCustomResourceController(null))));
2726
}
2827

operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSchedulerTest.java

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package 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;
36
import io.javaoperatorsdk.operator.processing.CustomResourceEvent;
47
import io.javaoperatorsdk.operator.processing.EventDispatcher;
58
import io.javaoperatorsdk.operator.processing.EventScheduler;
69
import io.javaoperatorsdk.operator.processing.retry.GenericRetry;
710
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;
1111
import org.assertj.core.api.Condition;
1212
import org.junit.jupiter.api.Test;
13-
import org.mockito.ArgumentMatcher;
1413
import org.mockito.ArgumentMatchers;
1514
import org.mockito.invocation.InvocationOnMock;
1615
import 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

Comments
 (0)
0