use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class CacheTest method testCacheStore.
@Test
public void testCacheStore() {
if (this.obj == null) {
// skip null object storing test b/c it should be checked before invoking cache
return;
}
cache.replace(Arrays.asList(this.obj), "0");
cache.delete(this.obj);
V1Pod pod = ((V1Pod) this.obj);
List indexedObjectList = cache.byIndex(mockIndexName, this.index);
assertEquals(0, indexedObjectList.size());
assertEquals(null, pod.getMetadata().getClusterName());
cache.add(this.obj);
// replace cached object w/ null value
String newClusterName = "test_cluster";
pod.getMetadata().setClusterName(newClusterName);
cache.update(this.obj);
assertEquals(1, cache.list().size());
assertEquals(newClusterName, pod.getMetadata().getClusterName());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class ControllerTest method testControllerProcessDeltas.
@Test
public void testControllerProcessDeltas() {
AtomicInteger receivingDeltasCount = new AtomicInteger(0);
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
V1Pod foo2 = new V1Pod().metadata(new V1ObjectMeta().name("foo2").namespace("default"));
V1Pod foo3 = new V1Pod().metadata(new V1ObjectMeta().name("foo3").namespace("default").resourceVersion("rva"));
V1Pod foo3Updated = new V1Pod().metadata(new V1ObjectMeta().name("foo3").namespace("default").resourceVersion("rvb"));
V1PodList podList = new V1PodList().metadata(new V1ListMeta()).items(Arrays.asList(foo1, foo2, foo3));
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, new Cache());
ListerWatcher<V1Pod, V1PodList> listerWatcher = new MockRunOnceListerWatcher<V1Pod, V1PodList>(podList, new Watch.Response<V1Pod>(EventType.MODIFIED.name(), foo3Updated));
Controller<V1Pod, V1PodList> controller = new Controller<>(V1Pod.class, deltaFIFO, listerWatcher, (deltas) -> {
receivingDeltasCount.addAndGet(deltas.size());
});
Thread controllerThread = new Thread(controller::run);
controllerThread.setDaemon(true);
controllerThread.start();
try {
Awaitility.await().pollInterval(Duration.ofSeconds(1)).timeout(Duration.ofSeconds(5)).untilAtomic(receivingDeltasCount, IsEqual.equalTo(4));
assertEquals(4, receivingDeltasCount.get());
} catch (Throwable t) {
throw new RuntimeException(t);
} finally {
controller.stop();
}
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class ListerTest method testListerBasic.
@Test
public void testListerBasic() {
Cache<V1Pod> podCache = new Cache<>();
Lister<V1Pod> namespacedPodLister = new Lister<>(podCache, "default");
List<V1Pod> emptyPodList = namespacedPodLister.list();
assertEquals(0, emptyPodList.size());
podCache.replace(Arrays.asList(new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default")), new V1Pod().metadata(new V1ObjectMeta().name("foo2").namespace("default")), new V1Pod().metadata(new V1ObjectMeta().name("foo3").namespace("default"))), "0");
List<V1Pod> namespacedPodList = namespacedPodLister.list();
assertEquals(3, namespacedPodList.size());
Lister<V1Pod> allNamespacedPodLister = new Lister<>(podCache);
List<V1Pod> allPodList = allNamespacedPodLister.list();
assertEquals(3, allPodList.size());
namespacedPodList = allNamespacedPodLister.namespace("default").list();
assertEquals(3, namespacedPodList.size());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class PodLogsTest method testNotFound.
@Test
public void testNotFound() throws ApiException, IOException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace)).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name(container).image("nginx"))));
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "text/plain").withBody("Not Found")));
PodLogs logs = new PodLogs(client);
boolean thrown = false;
try {
logs.streamNamespacedPodLog(pod);
} catch (ApiException ex) {
assertEquals(404, ex.getCode());
thrown = true;
}
assertEquals(thrown, true);
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).withQueryParam("container", equalTo(container)).withQueryParam("follow", equalTo("true")).withQueryParam("pretty", equalTo("false")).withQueryParam("previous", equalTo("false")).withQueryParam("timestamps", equalTo("false")));
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class PodLogsTest method testStream.
@Test
public void testStream() throws ApiException, IOException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace)).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name(container).image("nginx"))));
String content = "this is some\n content for \n various logs \n done";
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody(content)));
PodLogs logs = new PodLogs(client);
InputStream is = logs.streamNamespacedPodLog(pod);
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).withQueryParam("container", equalTo(container)).withQueryParam("follow", equalTo("true")).withQueryParam("pretty", equalTo("false")).withQueryParam("previous", equalTo("false")).withQueryParam("timestamps", equalTo("false")));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Streams.copy(is, bos);
assertEquals(content, bos.toString());
}
Aggregations