Skip to content

Commit 5b444d7

Browse files
fix: added BOOKMARK as a type in Watcher enum (#3488)
* fix: added BOOKMARK as a type in Watcher enum * fix: modified test from WatchTest * fix: modified test from WatchTest
1 parent 842f823 commit 5b444d7

File tree

2 files changed

+38
-1
lines changed
  • kubernetes-client/src/main/java/io/fabric8/kubernetes/client
  • kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock

2 files changed

+38
-1
lines changed

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/Watcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ default void onClose() {
4444
void onClose(WatcherException cause);
4545

4646
enum Action {
47-
ADDED, MODIFIED, DELETED, ERROR
47+
ADDED, MODIFIED, DELETED, ERROR, BOOKMARK
4848
}
4949

5050
}

kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/WatchTest.java

+37
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.TimeUnit;
4141

4242
import static io.fabric8.kubernetes.client.Watcher.Action.DELETED;
43+
import static io.fabric8.kubernetes.client.Watcher.Action.BOOKMARK;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertNotNull;
4546
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -276,4 +277,40 @@ private static WatchEvent outdatedEvent() {
276277
"410: The event in requested index is outdated and cleared (the requested history has been cleared [3/1]) [2]")
277278
.build()).build();
278279
}
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+
}
279316
}

0 commit comments

Comments
 (0)