use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class DeltaFIFOTest method testDeltaFIFODedup.
@Test
public void testDeltaFIFODedup() {
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default").resourceVersion("ver"));
Cache cache = new Cache();
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> deltas;
// add-delete dedup
deltaFIFO.add(foo1);
deltaFIFO.delete(foo1);
deltas = deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
assertEquals(DeltaFIFO.DeltaType.Deleted, deltas.peekLast().getLeft());
assertEquals(foo1, deltas.peekLast().getRight());
assertEquals(DeltaFIFO.DeltaType.Added, deltas.peekFirst().getLeft());
assertEquals(foo1, deltas.peekFirst().getRight());
assertEquals(2, deltas.size());
deltaFIFO.getItems().remove(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
// add-delete-delete dedup
deltaFIFO.add(foo1);
deltaFIFO.delete(foo1);
deltaFIFO.delete(foo1);
deltas = deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
assertEquals(DeltaFIFO.DeltaType.Deleted, deltas.peekLast().getLeft());
assertEquals(foo1, deltas.peekLast().getRight());
assertEquals(DeltaFIFO.DeltaType.Added, deltas.peekFirst().getLeft());
assertEquals(foo1, deltas.peekFirst().getRight());
assertEquals(2, deltas.size());
deltaFIFO.getItems().remove(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
// add-sync dedupe
deltaFIFO.add(foo1);
deltaFIFO.replace(Collections.singletonList(foo1), foo1.getMetadata().getResourceVersion());
deltas = deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
assertEquals(1, deltas.size());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class ProcessorListenerTest method testNotificationHandling.
@Test
public void testNotificationHandling() throws InterruptedException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name("foo").namespace("default"));
final CountDownLatch cLatch = new CountDownLatch(3);
ProcessorListener<V1Pod> listener = new ProcessorListener<>(new ResourceEventHandler<V1Pod>() {
@Override
public void onAdd(V1Pod obj) {
assertEquals(pod, obj);
addNotificationReceived = true;
cLatch.countDown();
}
@Override
public void onUpdate(V1Pod oldObj, V1Pod newObj) {
assertEquals(pod, newObj);
updateNotificationReceived = true;
cLatch.countDown();
}
@Override
public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
assertEquals(pod, obj);
deleteNotificationReceived = true;
cLatch.countDown();
}
}, 0);
listener.add(new ProcessorListener.AddNotification<>(pod));
listener.add(new ProcessorListener.UpdateNotification<>(null, pod));
listener.add(new ProcessorListener.DeleteNotification<>(pod));
Thread listenerThread = new Thread(listener::run);
listenerThread.setDaemon(true);
listenerThread.start();
// wait until consumption of notifications from queue
cLatch.await();
assertTrue(addNotificationReceived);
assertTrue(updateNotificationReceived);
assertTrue(deleteNotificationReceived);
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class ProcessorListenerTest method testMultipleNotificationsHandling.
@Test
public void testMultipleNotificationsHandling() throws InterruptedException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name("foo").namespace("default"));
final int[] count = { 0 };
int notificationCount = 2000;
final CountDownLatch cLatch = new CountDownLatch(notificationCount);
ProcessorListener<V1Pod> listener = new ProcessorListener<>(new ResourceEventHandler<V1Pod>() {
@Override
public void onAdd(V1Pod obj) {
assertEquals(pod, obj);
count[0]++;
cLatch.countDown();
}
@Override
public void onUpdate(V1Pod oldObj, V1Pod newObj) {
}
@Override
public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
}
}, 0);
for (int i = 0; i < notificationCount; i++) {
listener.add(new ProcessorListener.AddNotification<>(pod));
}
Thread listenerThread = new Thread(listener);
listenerThread.setDaemon(true);
listenerThread.start();
cLatch.await();
assertEquals(count[0], 2000);
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class SharedProcessorTest method testListenerAddition.
@Test
public void testListenerAddition() throws InterruptedException {
SharedProcessor<V1Pod> sharedProcessor = new SharedProcessor<>();
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
ProcessorListener.Notification<V1Pod> addNotification = new ProcessorListener.AddNotification<V1Pod>(foo1);
ProcessorListener.Notification<V1Pod> updateNotification = new ProcessorListener.UpdateNotification<V1Pod>(null, foo1);
ProcessorListener.Notification<V1Pod> deleteNotification = new ProcessorListener.DeleteNotification<V1Pod>(foo1);
ExpectingNoticationHandler<V1Pod> expectAddHandler = new ExpectingNoticationHandler<V1Pod>(addNotification);
ExpectingNoticationHandler<V1Pod> expectUpdateHandler = new ExpectingNoticationHandler<V1Pod>(updateNotification);
ExpectingNoticationHandler<V1Pod> expectDeleteHandler = new ExpectingNoticationHandler<V1Pod>(deleteNotification);
sharedProcessor.addAndStartListener(expectAddHandler);
sharedProcessor.addAndStartListener(expectUpdateHandler);
sharedProcessor.addAndStartListener(expectDeleteHandler);
sharedProcessor.distribute(addNotification, false);
sharedProcessor.distribute(updateNotification, false);
sharedProcessor.distribute(deleteNotification, false);
// sleep 1s for notification distribution completing
Thread.sleep(1000);
assertTrue(expectAddHandler.isSatisfied());
assertTrue(expectUpdateHandler.isSatisfied());
assertTrue(expectDeleteHandler.isSatisfied());
}
use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method testReadTimeoutShouldThrowException.
@Test
public void testReadTimeoutShouldThrowException() {
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().readTimeout(1, // timeout everytime
TimeUnit.MILLISECONDS).build());
stubFor(get(urlEqualTo("/api/v1/namespaces/foo/pods/test")).willReturn(aResponse().withFixedDelay(99999).withStatus(200).withBody("")));
podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
try {
KubernetesApiResponse<V1Pod> response = podClient.get("foo", "test");
} catch (Throwable t) {
assertTrue(t.getCause() instanceof SocketTimeoutException);
return;
}
fail("no exception happened");
}
Aggregations