Search in sources :

Example 11 with JSON

use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.

the class DefaultSharedIndexInformerWireMockTest method testInformerReListingOnListForbidden.

@Test
public void testInformerReListingOnListForbidden() throws InterruptedException {
    CoreV1Api coreV1Api = new CoreV1Api(client);
    stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(403).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(new V1Status().apiVersion("v1").kind("Status").code(403).reason("RBAC forbidden")))));
    SharedInformerFactory factory = new SharedInformerFactory();
    SharedIndexInformer<V1Pod> podInformer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
        try {
            return coreV1Api.listNamespacedPodCall(namespace, null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
        } catch (ApiException e) {
            throw new RuntimeException(e);
        }
    }, V1Pod.class, V1PodList.class);
    factory.startAllRegisteredInformers();
    // Sleep mroe than 1s so that informer can perform multiple rounds of list-watch
    Thread.sleep(3000);
    verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")));
    factory.stopAllRegisteredInformers();
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) SharedInformerFactory(io.kubernetes.client.informer.SharedInformerFactory) V1Pod(io.kubernetes.client.openapi.models.V1Pod) JSON(io.kubernetes.client.openapi.JSON) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Aggregations

JSON (io.kubernetes.client.openapi.JSON)11 Test (org.junit.Test)11 V1Pod (io.kubernetes.client.openapi.models.V1Pod)7 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)6 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)6 V1PodList (io.kubernetes.client.openapi.models.V1PodList)6 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)6 ApiException (io.kubernetes.client.openapi.ApiException)5 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)4 Watch (io.kubernetes.client.util.Watch)4 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)2 V1ReplicaSet (io.kubernetes.client.openapi.models.V1ReplicaSet)2 V1Status (io.kubernetes.client.openapi.models.V1Status)2 Semaphore (java.util.concurrent.Semaphore)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1