use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class DeploymentHelperTest method testGetAllReplicaSetsShouldWork.
@Test
public void testGetAllReplicaSetsShouldWork() throws IOException, ApiException {
wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))))));
AppsV1Api api = new AppsV1Api(this.apiClient);
V1Deployment deployment = new JSON().deserialize(new String(Files.readAllBytes(Paths.get(DEPLOYMENT))), V1Deployment.class);
List<V1ReplicaSet> oldRSes = new ArrayList<>();
List<V1ReplicaSet> allOldRSes = new ArrayList<>();
V1ReplicaSet newRs = DeploymentHelper.getAllReplicaSets(deployment, api, oldRSes, allOldRSes);
wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets"))).withQueryParam("labelSelector", new EqualToPattern("app = bar")));
Assert.assertNotNull(newRs);
Assert.assertEquals(1, oldRSes.size());
Assert.assertEquals(2, allOldRSes.size());
}
use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class DeploymentHelperTest method testRevisionShouldWork.
@Test
public void testRevisionShouldWork() throws IOException {
V1ReplicaSetList replicaSetList = new JSON().deserialize(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))), V1ReplicaSetList.class);
List<Long> revisions = new ArrayList<>();
for (V1ReplicaSet rs : replicaSetList.getItems()) {
revisions.add(DeploymentHelper.revision(rs.getMetadata()));
}
revisions.sort(Long::compareTo);
List<Long> exceptRevisions = Arrays.asList(1L, 2L, 2L, 3L, 4L);
Assert.assertEquals(exceptRevisions, revisions);
}
use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class KubernetesInformerCreatorTest method testInformerInjection.
@Test
public void testInformerInjection() throws InterruptedException {
assertNotNull(podInformer);
assertNotNull(configMapInformer);
Semaphore getCount = new Semaphore(2);
Semaphore watchCount = new Semaphore(2);
Parameters getParams = new Parameters();
Parameters watchParams = new Parameters();
getParams.put("semaphore", getCount);
watchParams.put("semaphore", watchCount);
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
V1ConfigMap bar1 = new V1ConfigMap().kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1"));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(foo1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(bar1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
// These will be released for each web call above.
getCount.acquire(2);
watchCount.acquire(2);
informerFactory.startAllRegisteredInformers();
// Wait for the GETs to complete and the watches to start.
getCount.acquire(2);
watchCount.acquire(2);
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("true")));
assertEquals(1, new Lister<>(podInformer.getIndexer()).list().size());
assertEquals(1, new Lister<>(configMapInformer.getIndexer()).list().size());
}
use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class WatchTest method testWatchEnd.
@Test
public void testWatchEnd() throws IOException {
JSON json = new JSON();
Watch<V1ConfigMap> watch = new Watch<V1ConfigMap>(json, null, new TypeToken<Watch.Response<V1ConfigMap>>() {
}.getType(), null);
JsonObject metadata = new JsonObject();
metadata.addProperty("name", "foo");
metadata.addProperty("namespace", "bar");
JsonObject status = new JsonObject();
status.add("metadata", metadata);
status.addProperty("kind", "Status");
status.addProperty("apiVersion", "v1");
status.addProperty("status", "failure");
status.addProperty("message", "too old resource version");
status.addProperty("reason", "Gone");
status.addProperty("code", 410);
JsonObject obj = new JsonObject();
obj.addProperty("type", "ERROR");
obj.add("object", status);
String data = json.getGson().toJson(obj);
Watch.Response<V1ConfigMap> response = watch.parseLine(data);
assertEquals(null, response.object);
}
use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class GenericKubernetesApiTest method updateStatusNamespacedJobReturningObject.
@Test
public void updateStatusNamespacedJobReturningObject() {
V1Job foo1 = new V1Job().kind("Job").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
foo1.setStatus(new V1JobStatus().failed(1));
stubFor(patch(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1/status")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(foo1))));
KubernetesApiResponse<V1Job> jobListResp = jobClient.updateStatus(foo1, t -> t.getStatus());
assertTrue(jobListResp.isSuccess());
assertEquals(foo1, jobListResp.getObject());
assertNull(jobListResp.getStatus());
verify(1, patchRequestedFor(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1/status")));
}
Aggregations