use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DeltaFIFOTest method testDeltaFIFOResync.
@Test
public void testDeltaFIFOResync() {
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
Cache cache = new Cache();
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
// sync after add
cache.add(foo1);
deltaFIFO.resync();
Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> deltas = deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));
assertEquals(1, deltas.size());
assertEquals(foo1, deltas.peekLast().getRight());
assertEquals(DeltaFIFO.DeltaType.Sync, deltas.peekLast().getLeft());
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class DeltaFIFOTest method testDeltaFIFOReplaceWithDeleteDeltaIn.
@Test
public void testDeltaFIFOReplaceWithDeleteDeltaIn() throws InterruptedException {
V1Pod oldPod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1"));
V1Pod newPod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo2"));
Cache mockCache = mock(Cache.class);
doReturn(oldPod).when(mockCache).getByKey(Caches.deletionHandlingMetaNamespaceKeyFunc(oldPod));
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, mockCache);
deltaFIFO.delete(oldPod);
deltaFIFO.replace(Arrays.asList(newPod), "0");
deltaFIFO.pop((deltas) -> {
assertEquals(DeltaFIFO.DeltaType.Deleted, deltas.getFirst().getLeft());
assertEquals(oldPod, deltas.getFirst().getRight());
});
deltaFIFO.pop((deltas) -> {
assertEquals(DeltaFIFO.DeltaType.Sync, deltas.getFirst().getLeft());
assertEquals(newPod, deltas.getFirst().getRight());
});
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta 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.V1ObjectMeta 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.V1ObjectMeta 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);
}
Aggregations