|
13 | 13 | package io.kubernetes.client.informer.cache;
|
14 | 14 |
|
15 | 15 | import static org.junit.Assert.assertFalse;
|
| 16 | +import static org.junit.Assert.assertTrue; |
16 | 17 | import static org.mockito.Mockito.any;
|
17 | 18 | import static org.mockito.Mockito.mock;
|
18 | 19 | import static org.mockito.Mockito.never;
|
@@ -312,4 +313,34 @@ public void testReflectorWatchShouldRelistUponExpiredWatchItem() throws ApiExcep
|
312 | 313 | .until(() -> future.isDone());
|
313 | 314 | assertFalse(future.isCompletedExceptionally());
|
314 | 315 | }
|
| 316 | + |
| 317 | + @Test |
| 318 | + public void testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler() |
| 319 | + throws ApiException { |
| 320 | + String expectedResourceVersion = "100"; |
| 321 | + when(listerWatcher.list(any())) |
| 322 | + .thenReturn( |
| 323 | + new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion))); |
| 324 | + |
| 325 | + V1Status v1Status = new V1Status(); |
| 326 | + v1Status.setMessage("dummy-error-message"); |
| 327 | + v1Status.setCode(410); |
| 328 | + when(listerWatcher.watch(any())) |
| 329 | + .thenReturn(new MockWatch<>(new Watch.Response("Error", v1Status))); |
| 330 | + ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = |
| 331 | + new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO); |
| 332 | + try { |
| 333 | + Thread thread = new Thread(reflectorRunnable::run); |
| 334 | + thread.setDaemon(true); |
| 335 | + thread.start(); |
| 336 | + Awaitility.await() |
| 337 | + .atMost(Duration.ofSeconds(1)) |
| 338 | + .pollInterval(Duration.ofMillis(100)) |
| 339 | + .until( |
| 340 | + () -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion())); |
| 341 | + assertTrue(reflectorRunnable.isLastSyncResourceVersionUnavailable()); |
| 342 | + } finally { |
| 343 | + reflectorRunnable.stop(); |
| 344 | + } |
| 345 | + } |
315 | 346 | }
|
0 commit comments