use of io.kubernetes.client.openapi.models.V1ListMeta 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.models.V1ListMeta in project java by kubernetes-client.
the class ReflectorRunnableTest method testReflectorRelistShouldHonorLastSyncResourceVersion.
@Test
public void testReflectorRelistShouldHonorLastSyncResourceVersion() {
String expectedResourceVersion = "999";
AtomicReference<String> requestedResourceVersion = new AtomicReference<>();
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, new ListerWatcher<V1Pod, V1PodList>() {
@Override
public V1PodList list(CallGeneratorParams params) throws ApiException {
requestedResourceVersion.set(params.resourceVersion);
return new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion));
}
@Override
public Watchable<V1Pod> watch(CallGeneratorParams params) throws ApiException {
throw new ApiException("HTTP GONE");
}
}, deltaFIFO);
// first run
try {
Thread thread = new Thread(reflectorRunnable::run);
thread.setDaemon(true);
thread.start();
Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
} finally {
reflectorRunnable.stop();
}
// second run
try {
Thread thread = new Thread(reflectorRunnable::run);
thread.setDaemon(true);
thread.start();
Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).untilAtomic(requestedResourceVersion, new IsEqual<>(expectedResourceVersion));
} finally {
reflectorRunnable.stop();
}
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class ReflectorRunnableTest method testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler.
@Test
public void testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler() throws ApiException {
String expectedResourceVersion = "100";
when(listerWatcher.list(any())).thenReturn(new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));
V1Status v1Status = new V1Status();
v1Status.setMessage("dummy-error-message");
v1Status.setCode(410);
when(listerWatcher.watch(any())).thenReturn(new MockWatch<>(new Watch.Response("Error", v1Status)));
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
try {
Thread thread = new Thread(reflectorRunnable::run);
thread.setDaemon(true);
thread.start();
Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
assertTrue(reflectorRunnable.isLastSyncResourceVersionUnavailable());
} finally {
reflectorRunnable.stop();
}
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class ReflectorRunnableTest method testReflectorRunOnce.
@Test
public void testReflectorRunOnce() throws ApiException {
String mockResourceVersion = "1000";
when(listerWatcher.list(any())).thenReturn(new V1PodList().metadata(new V1ListMeta().resourceVersion(mockResourceVersion)));
when(listerWatcher.watch(any())).then((v) -> {
// block forever
Awaitility.await().forever();
return null;
});
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<V1Pod, V1PodList>(V1Pod.class, listerWatcher, deltaFIFO);
try {
Thread thread = new Thread(reflectorRunnable::run);
thread.setDaemon(true);
thread.start();
Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> mockResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
} finally {
reflectorRunnable.stop();
}
verify(deltaFIFO, times(1)).replace(any(), any());
verify(deltaFIFO, never()).add(any());
verify(listerWatcher, times(1)).list(any());
verify(listerWatcher, times(1)).watch(any());
}
use of io.kubernetes.client.openapi.models.V1ListMeta in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method listNamespacedPodReturningObject.
@Test
public void listNamespacedPodReturningObject() {
V1PodList podList = new V1PodList().kind("PodList").metadata(new V1ListMeta());
stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods")).willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
KubernetesApiResponse<V1PodList> podListResp = podClient.list("default");
assertTrue(podListResp.isSuccess());
assertEquals(podList, podListResp.getObject());
assertNull(podListResp.getStatus());
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods")));
}
Aggregations