|
19 | 19 |
|
20 | 20 | import com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider;
|
21 | 21 |
|
| 22 | +import static org.assertj.core.api.Assertions.assertThat; |
22 | 23 | import static org.junit.jupiter.api.Assertions.*;
|
23 | 24 | import static org.mockito.ArgumentMatchers.any;
|
24 | 25 | import static org.mockito.ArgumentMatchers.eq;
|
25 | 26 | import static org.mockito.Mockito.*;
|
26 | 27 |
|
27 | 28 | class PerResourcePollingEventSourceTest {
|
28 | 29 |
|
29 |
| - public static final int PERIOD = 50; |
| 30 | + public static final int PERIOD = 80; |
30 | 31 | private PerResourcePollingEventSource<SampleExternalResource, TestCustomResource> pollingEventSource;
|
31 | 32 | private PerResourcePollingEventSource.ResourceSupplier<SampleExternalResource, TestCustomResource> supplier =
|
32 | 33 | mock(PerResourcePollingEventSource.ResourceSupplier.class);
|
@@ -90,4 +91,23 @@ public void propagateEventOnDeletedResource() throws InterruptedException {
|
90 | 91 | verify(supplier, atLeast(2)).getResources(eq(testCustomResource));
|
91 | 92 | verify(eventHandler, times(2)).handleEvent(any());
|
92 | 93 | }
|
| 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 | + |
93 | 113 | }
|
0 commit comments