Skip to content

Commit 074d420

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 8e3ad50 commit 074d420

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public R eventFilteringUpdateAndCacheResource(R resourceToUpdate, UnaryOperator<
108108
id,
109109
updatedResource == null ? null : updatedResource.getMetadata().getResourceVersion());
110110
var updatedForLambda = updatedResource;
111-
res.ifPresent(
111+
res.ifPresentOrElse(
112112
r -> {
113113
R latestResource = (R) r.getResource().orElseThrow();
114114

@@ -134,7 +134,8 @@ public R eventFilteringUpdateAndCacheResource(R resourceToUpdate, UnaryOperator<
134134
? ((ResourceDeleteEvent) r).isDeletedFinalStateUnknown()
135135
: null,
136136
false);
137-
});
137+
},
138+
() -> log.debug("No new event present after the filtering update; id: {}", id));
138139
}
139140
}
140141

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.TestInstance;
2728

2829
import io.fabric8.kubernetes.api.model.HasMetadata;
2930
import io.fabric8.kubernetes.api.model.ObjectMeta;
@@ -64,12 +65,13 @@
6465
import static org.mockito.Mockito.when;
6566

6667
@SuppressWarnings({"rawtypes", "unchecked"})
68+
@TestInstance(value = TestInstance.Lifecycle.PER_METHOD)
6769
class InformerEventSourceTest {
6870

6971
private static final String PREV_RESOURCE_VERSION = "0";
7072
private static final String DEFAULT_RESOURCE_VERSION = "1";
7173

72-
ExecutorService executorService = Executors.newSingleThreadExecutor();
74+
ExecutorService executorService = Executors.newCachedThreadPool();
7375

7476
private InformerEventSource<Deployment, TestCustomResource> informerEventSource;
7577
private final KubernetesClient clientMock = MockKubernetesClient.client(Deployment.class);
@@ -205,7 +207,7 @@ void filtersOnDeleteEvents() {
205207
}
206208

207209
@Test
208-
void handlesPrevResourceVersionForUpdate() {
210+
void handlesPrevResourceVersionForUpdate() throws InterruptedException {
209211
withRealTemporaryResourceCache();
210212
var deployment = testDeployment();
211213
CountDownLatch latch = new CountDownLatch(1);
@@ -224,7 +226,10 @@ void handlesPrevResourceVersionForUpdate() {
224226
}
225227
return resp;
226228
}));
227-
informerEventSource.onUpdate(deployment, incResourceVersion(testDeployment(), 2));
229+
Thread.sleep(50);
230+
informerEventSource.onUpdate(
231+
incResourceVersion(deployment, 1), incResourceVersion(testDeployment(), 2));
232+
228233
latch.countDown();
229234

230235
await()
@@ -251,7 +256,7 @@ void handlesPrevResourceVersionForUpdate() {
251256
}
252257

253258
@Test
254-
void handlesPrevResourceVersionForUpdateInCaseOfException() {
259+
void handlesPrevResourceVersionForUpdateInCaseOfException() throws InterruptedException {
255260
withRealTemporaryResourceCache();
256261

257262
withRealTemporaryResourceCache();
@@ -270,6 +275,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfException() {
270275
throw new RuntimeException(e);
271276
}
272277
}));
278+
Thread.sleep(50);
273279
informerEventSource.onUpdate(deployment, incResourceVersion(testDeployment(), 1));
274280
latch.countDown();
275281

@@ -297,7 +303,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfException() {
297303
}
298304

299305
@Test
300-
void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() {
306+
void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() throws InterruptedException {
301307
withRealTemporaryResourceCache();
302308

303309
withRealTemporaryResourceCache();
@@ -318,7 +324,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() {
318324
}
319325
return resp;
320326
}));
321-
327+
Thread.sleep(50);
322328
informerEventSource.onUpdate(
323329
incResourceVersion(testDeployment(), 1), incResourceVersion(testDeployment(), 2));
324330
informerEventSource.onUpdate(
@@ -349,7 +355,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() {
349355
}
350356

351357
@Test
352-
void doesNotPropagateEventIfReceivedBeforeUpdate() {
358+
void doesNotPropagateEventIfReceivedBeforeUpdate() throws InterruptedException {
353359
withRealTemporaryResourceCache();
354360
var deployment = testDeployment();
355361
CountDownLatch latch = new CountDownLatch(1);
@@ -368,6 +374,7 @@ void doesNotPropagateEventIfReceivedBeforeUpdate() {
368374
}
369375
return resp;
370376
}));
377+
Thread.sleep(50);
371378
informerEventSource.onUpdate(deployment, incResourceVersion(testDeployment(), 1));
372379
latch.countDown();
373380

0 commit comments

Comments
 (0)