Search in sources :

Example 1 with Watchable

use of io.kubernetes.client.util.Watchable 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();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) Watchable(io.kubernetes.client.util.Watchable) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 2 with Watchable

use of io.kubernetes.client.util.Watchable in project java by kubernetes-client.

the class ReflectorRunnableTest method testReflectorWatchConnectionCloseOnError.

@Test
public void testReflectorWatchConnectionCloseOnError() throws InterruptedException {
    Watchable<V1Pod> watch = new MockWatch<V1Pod>(new Watch.Response<V1Pod>(EventType.ERROR.name(), new V1Status().status("403")));
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, new ListerWatcher<V1Pod, V1PodList>() {

        @Override
        public V1PodList list(CallGeneratorParams params) throws ApiException {
            return new V1PodList().metadata(new V1ListMeta());
        }

        @Override
        public Watchable<V1Pod> watch(CallGeneratorParams params) throws ApiException {
            return watch;
        }
    }, deltaFIFO);
    try {
        Thread thread = new Thread(reflectorRunnable::run);
        thread.setDaemon(true);
        thread.start();
        Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).until(() -> ((MockWatch<V1Pod>) watch).isClosed());
    } finally {
        reflectorRunnable.stop();
    }
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) Watchable(io.kubernetes.client.util.Watchable) Watch(io.kubernetes.client.util.Watch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Aggregations

ApiException (io.kubernetes.client.openapi.ApiException)2 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)2 V1Pod (io.kubernetes.client.openapi.models.V1Pod)2 V1PodList (io.kubernetes.client.openapi.models.V1PodList)2 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)2 Watchable (io.kubernetes.client.util.Watchable)2 Test (org.junit.Test)2 V1Status (io.kubernetes.client.openapi.models.V1Status)1 Watch (io.kubernetes.client.util.Watch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1