Skip to content

Commit c008dc0

Browse files
csvirimetacosm
authored andcommitted
fix: added unit test
1 parent 31224ee commit c008dc0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
import com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider;
2121

22+
import static org.assertj.core.api.Assertions.assertThat;
2223
import static org.junit.jupiter.api.Assertions.*;
2324
import static org.mockito.ArgumentMatchers.any;
2425
import static org.mockito.ArgumentMatchers.eq;
2526
import static org.mockito.Mockito.*;
2627

2728
class PerResourcePollingEventSourceTest {
2829

29-
public static final int PERIOD = 50;
30+
public static final int PERIOD = 80;
3031
private PerResourcePollingEventSource<SampleExternalResource, TestCustomResource> pollingEventSource;
3132
private PerResourcePollingEventSource.ResourceSupplier<SampleExternalResource, TestCustomResource> supplier =
3233
mock(PerResourcePollingEventSource.ResourceSupplier.class);
@@ -90,4 +91,23 @@ public void propagateEventOnDeletedResource() throws InterruptedException {
9091
verify(supplier, atLeast(2)).getResources(eq(testCustomResource));
9192
verify(eventHandler, times(2)).handleEvent(any());
9293
}
94+
95+
@Test
96+
public void getsValueFromCacheOrSupplier() throws InterruptedException {
97+
pollingEventSource.start();
98+
pollingEventSource.onResourceCreated(testCustomResource);
99+
when(supplier.getResources(any()))
100+
.thenReturn(Optional.empty())
101+
.thenReturn(Optional.of(SampleExternalResource.testResource1()));
102+
103+
Thread.sleep(PERIOD / 2);
104+
105+
var value = pollingEventSource.getValueFromCacheOrSupplier(ResourceID.fromResource(testCustomResource));
106+
107+
Thread.sleep(PERIOD * 2);
108+
109+
assertThat(value).isPresent();
110+
verify(eventHandler, never()).handleEvent(any());
111+
}
112+
93113
}

0 commit comments

Comments
 (0)