|
40 | 40 | import java.util.concurrent.TimeUnit;
|
41 | 41 |
|
42 | 42 | import static io.fabric8.kubernetes.client.Watcher.Action.DELETED;
|
| 43 | +import static io.fabric8.kubernetes.client.Watcher.Action.BOOKMARK; |
43 | 44 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
44 | 45 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
45 | 46 | import static org.junit.jupiter.api.Assertions.assertNull;
|
@@ -276,4 +277,40 @@ private static WatchEvent outdatedEvent() {
|
276 | 277 | "410: The event in requested index is outdated and cleared (the requested history has been cleared [3/1]) [2]")
|
277 | 278 | .build()).build();
|
278 | 279 | }
|
| 280 | + |
| 281 | + |
| 282 | + @Test |
| 283 | + @DisplayName("TryWithResources, connects and receives event then receives GONE, should receive first event and then close") |
| 284 | + void testTryWithResourcesConnectsThenReceivesEventBookmark() throws InterruptedException { |
| 285 | + // Given |
| 286 | + server.expect() |
| 287 | + .withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1&resourceVersion=1&watch=true") |
| 288 | + .andUpgradeToWebSocket().open() |
| 289 | + .waitFor(EVENT_WAIT_PERIOD_MS).andEmit(new WatchEvent(pod1, "BOOKMARK")) |
| 290 | + .waitFor(EVENT_WAIT_PERIOD_MS).andEmit(outdatedEvent()).done().once(); |
| 291 | + final CountDownLatch bookmarkLatch = new CountDownLatch(1); |
| 292 | + final CountDownLatch closeLatch = new CountDownLatch(1); |
| 293 | + final Watcher<Pod> watcher = new Watcher<Pod>() { |
| 294 | + @Override |
| 295 | + public void eventReceived(Action action, Pod resource) { |
| 296 | + if (action != BOOKMARK) { |
| 297 | + fail(); |
| 298 | + } |
| 299 | + bookmarkLatch.countDown(); |
| 300 | + } |
| 301 | + |
| 302 | + @Override |
| 303 | + public void onClose(WatcherException cause) { |
| 304 | + assertTrue(cause.isHttpGone()); |
| 305 | + closeLatch.countDown(); |
| 306 | + } |
| 307 | + }; |
| 308 | + // When |
| 309 | + try (Watch watch = client.pods().withName("pod1").withResourceVersion("1").watch(watcher)) { |
| 310 | + // Then |
| 311 | + assertNotNull(watch); |
| 312 | + assertTrue(bookmarkLatch.await(10, TimeUnit.SECONDS)); |
| 313 | + assertTrue(closeLatch.await(10, TimeUnit.SECONDS)); |
| 314 | + } |
| 315 | + } |
279 | 316 | }
|
0 commit comments