@@ -99,6 +99,25 @@ public void deleteNamespacedPodReturningStatus() {
9999 verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
100100 }
101101
102+ @ Test
103+ public void deleteNamespacedPodAsyncReturningStatus () throws InterruptedException {
104+ V1Status status = new V1Status ().kind ("Status" ).code (200 ).message ("good!" );
105+ stubFor (
106+ delete (urlEqualTo ("/api/v1/namespaces/default/pods/foo1" ))
107+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (status ))));
108+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
109+
110+ Future <KubernetesApiResponse <V1Pod >> deletePodFuture = podClient .deleteAsync ("default" , "foo1" , null , callback );
111+ KubernetesApiResponse <V1Pod > deletePodResp = callback .waitForAndGetResponse ();
112+ assertTrue (deletePodResp .isSuccess ());
113+ assertEquals (status , deletePodResp .getStatus ());
114+ assertNull (deletePodResp .getObject ());
115+ assertTrue (deletePodFuture .isDone ());
116+ assertFalse (deletePodFuture .isCancelled ());
117+
118+ verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
119+ }
120+
102121 @ Test
103122 public void deleteNamespacedPodReturningDeletedObject () {
104123 V1Pod foo1 =
@@ -115,6 +134,26 @@ public void deleteNamespacedPodReturningDeletedObject() {
115134 verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
116135 }
117136
137+ @ Test
138+ public void deleteNamespacedPodAsyncReturningDeletedObject () throws InterruptedException {
139+ V1Pod foo1 =
140+ new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
141+
142+ stubFor (
143+ delete (urlEqualTo ("/api/v1/namespaces/default/pods/foo1" ))
144+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (foo1 ))));
145+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
146+
147+ Future <KubernetesApiResponse <V1Pod >> deletePodFuture = podClient .deleteAsync ("default" , "foo1" , callback );
148+ KubernetesApiResponse <V1Pod > deletePodResp = callback .waitForAndGetResponse ();
149+ assertTrue (deletePodResp .isSuccess ());
150+ assertEquals (foo1 , deletePodResp .getObject ());
151+ assertNull (deletePodResp .getStatus ());
152+ assertTrue (deletePodFuture .isDone ());
153+ assertFalse (deletePodFuture .isCancelled ());
154+ verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
155+ }
156+
118157 @ Test
119158 public void deleteNamespacedPodReturningForbiddenStatus () {
120159 V1Status status = new V1Status ().kind ("Status" ).code (403 ).message ("good!" );
@@ -130,6 +169,25 @@ public void deleteNamespacedPodReturningForbiddenStatus() {
130169 verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
131170 }
132171
172+ @ Test
173+ public void deleteNamespacedPodAsyncReturningForbiddenStatus () throws InterruptedException {
174+ V1Status status = new V1Status ().kind ("Status" ).code (403 ).message ("good!" );
175+
176+ stubFor (
177+ delete (urlEqualTo ("/api/v1/namespaces/default/pods/foo1" ))
178+ .willReturn (aResponse ().withStatus (403 ).withBody (json .serialize (status ))));
179+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
180+
181+ Future <KubernetesApiResponse <V1Pod >> deletePodFuture = podClient .deleteAsync ("default" , "foo1" , callback );
182+ KubernetesApiResponse <V1Pod > deletePodResp = callback .waitForAndGetResponse ();
183+ assertFalse (deletePodResp .isSuccess ());
184+ assertEquals (status , deletePodResp .getStatus ());
185+ assertNull (deletePodResp .getObject ());
186+ assertTrue (deletePodFuture .isDone ());
187+ assertFalse (deletePodFuture .isCancelled ());
188+ verify (1 , deleteRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
189+ }
190+
133191 @ Test
134192 public void listNamespacedPodReturningObject () {
135193 V1PodList podList = new V1PodList ().kind ("PodList" ).metadata (new V1ListMeta ());
@@ -144,6 +202,25 @@ public void listNamespacedPodReturningObject() {
144202 verify (1 , getRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods" )));
145203 }
146204
205+ @ Test
206+ public void listNamespacedPodAsyncReturningObject () throws InterruptedException {
207+ V1PodList podList = new V1PodList ().kind ("PodList" ).metadata (new V1ListMeta ());
208+
209+ stubFor (
210+ get (urlPathEqualTo ("/api/v1/namespaces/default/pods" ))
211+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (podList ))));
212+ TestCallback <V1PodList > callback = new TestCallback <>(podClient .getApiClient ());
213+
214+ Future <KubernetesApiResponse <V1PodList >> podListFuture = podClient .listAsync ("default" , callback );
215+ KubernetesApiResponse <V1PodList > podListResp = callback .waitForAndGetResponse ();
216+ assertTrue (podListResp .isSuccess ());
217+ assertEquals (podList , podListResp .getObject ());
218+ assertNull (podListResp .getStatus ());
219+ assertTrue (podListFuture .isDone ());
220+ assertFalse (podListFuture .isCancelled ());
221+ verify (1 , getRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods" )));
222+ }
223+
147224 @ Test
148225 public void listClusterPodReturningObject () {
149226 V1PodList podList = new V1PodList ().kind ("PodList" ).metadata (new V1ListMeta ());
@@ -244,6 +321,26 @@ public void createNamespacedPodReturningObject() {
244321 verify (1 , postRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods" )));
245322 }
246323
324+ @ Test
325+ public void createNamespacedPodAsyncReturningObject () throws InterruptedException {
326+ V1Pod foo1 =
327+ new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
328+
329+ stubFor (
330+ post (urlEqualTo ("/api/v1/namespaces/default/pods" ))
331+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (foo1 ))));
332+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
333+
334+ Future <KubernetesApiResponse <V1Pod >> podListFuture = podClient .createAsync (foo1 , callback );
335+ KubernetesApiResponse <V1Pod > podListResp = callback .waitForAndGetResponse ();
336+ assertTrue (podListResp .isSuccess ());
337+ assertEquals (foo1 , podListResp .getObject ());
338+ assertNull (podListResp .getStatus ());
339+ assertTrue (podListFuture .isDone ());
340+ assertFalse (podListFuture .isCancelled ());
341+ verify (1 , postRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods" )));
342+ }
343+
247344 @ Test
248345 public void updateNamespacedPodReturningObject () {
249346 V1Pod foo1 =
@@ -259,6 +356,26 @@ public void updateNamespacedPodReturningObject() {
259356 verify (1 , putRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
260357 }
261358
359+ @ Test
360+ public void updateNamespacedPodAsyncReturningObject () throws InterruptedException {
361+ V1Pod foo1 =
362+ new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
363+
364+ stubFor (
365+ put (urlEqualTo ("/api/v1/namespaces/default/pods/foo1" ))
366+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (foo1 ))));
367+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
368+
369+ Future <KubernetesApiResponse <V1Pod >> podListFuture = podClient .updateAsync (foo1 , callback );
370+ KubernetesApiResponse <V1Pod > podListResp = callback .waitForAndGetResponse ();
371+ assertTrue (podListResp .isSuccess ());
372+ assertEquals (foo1 , podListResp .getObject ());
373+ assertNull (podListResp .getStatus ());
374+ assertTrue (podListFuture .isDone ());
375+ assertFalse (podListFuture .isCancelled ());
376+ verify (1 , putRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
377+ }
378+
262379 @ Test
263380 public void patchNamespacedPodReturningObject () {
264381 V1Patch v1Patch = new V1Patch ("{}" );
@@ -277,6 +394,29 @@ public void patchNamespacedPodReturningObject() {
277394 verify (1 , patchRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
278395 }
279396
397+ @ Test
398+ public void patchNamespacedPodAsyncReturningObject () throws InterruptedException {
399+ V1Patch v1Patch = new V1Patch ("{}" );
400+ V1Pod foo1 =
401+ new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
402+ stubFor (
403+ patch (urlEqualTo ("/api/v1/namespaces/default/pods/foo1" ))
404+ .withHeader ("Content-Type" , containing (V1Patch .PATCH_FORMAT_STRATEGIC_MERGE_PATCH ))
405+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (foo1 ))));
406+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
407+
408+ Future <KubernetesApiResponse <V1Pod >> podPatchFuture =
409+ podClient .patchAsync ("default" , "foo1" , V1Patch .PATCH_FORMAT_STRATEGIC_MERGE_PATCH , v1Patch , callback );
410+ KubernetesApiResponse <V1Pod > podPatchResp = callback .waitForAndGetResponse ();
411+
412+ assertTrue (podPatchResp .isSuccess ());
413+ assertEquals (foo1 , podPatchResp .getObject ());
414+ assertNull (podPatchResp .getStatus ());
415+ assertTrue (podPatchFuture .isDone ());
416+ assertFalse (podPatchFuture .isCancelled ());
417+ verify (1 , patchRequestedFor (urlPathEqualTo ("/api/v1/namespaces/default/pods/foo1" )));
418+ }
419+
280420 @ Test
281421 public void patchNamespacedPodWithApiPrefix () {
282422 V1Patch v1Patch = new V1Patch ("{}" );
@@ -307,6 +447,40 @@ public void patchNamespacedPodWithApiPrefix() {
307447 verify (1 , patchRequestedFor (urlPathEqualTo (prefix + "/api/v1/namespaces/default/pods/foo1" )));
308448 }
309449
450+ @ Test
451+ public void patchNamespacedPodAsyncWithApiPrefix () throws InterruptedException {
452+ V1Patch v1Patch = new V1Patch ("{}" );
453+ V1Pod foo1 =
454+ new V1Pod ().kind ("Pod" ).metadata (new V1ObjectMeta ().namespace ("default" ).name ("foo1" ));
455+ // add api prefix
456+ String prefix = "/k8s/clusters/c-7q988" ;
457+ stubFor (
458+ patch (urlEqualTo (prefix + "/api/v1/namespaces/default/pods/foo1" ))
459+ .withHeader ("Content-Type" , containing (V1Patch .PATCH_FORMAT_STRATEGIC_MERGE_PATCH ))
460+ .willReturn (aResponse ().withStatus (200 ).withBody (json .serialize (foo1 ))));
461+ TestCallback <V1Pod > callback = new TestCallback <>(podClient .getApiClient ());
462+
463+ GenericKubernetesApi <V1Pod , V1PodList > rancherPodClient =
464+ new GenericKubernetesApi <>(
465+ V1Pod .class ,
466+ V1PodList .class ,
467+ "" ,
468+ "v1" ,
469+ "pods" ,
470+ new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port () + prefix ).build ());
471+ Future <KubernetesApiResponse <V1Pod >> podPatchFuture =
472+ rancherPodClient .patchAsync (
473+ "default" , "foo1" , V1Patch .PATCH_FORMAT_STRATEGIC_MERGE_PATCH , v1Patch , callback );
474+ KubernetesApiResponse <V1Pod > podPatchResp = callback .waitForAndGetResponse ();
475+
476+ assertTrue (podPatchResp .isSuccess ());
477+ assertEquals (foo1 , podPatchResp .getObject ());
478+ assertNull (podPatchResp .getStatus ());
479+ assertTrue (podPatchFuture .isDone ());
480+ assertFalse (podPatchFuture .isCancelled ());
481+ verify (1 , patchRequestedFor (urlPathEqualTo (prefix + "/api/v1/namespaces/default/pods/foo1" )));
482+ }
483+
310484 @ Test
311485 public void testReadTimeoutShouldThrowException () {
312486 ApiClient apiClient = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
0 commit comments