Search in sources :

Example 21 with V1Pod

use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.

the class YamlTest method testLoadAsYamlCantConstructObjects.

@Test
public void testLoadAsYamlCantConstructObjects() {
    try {
        String data = Resources.toString(TAGGED_FILE, UTF_8);
        V1Pod pod = Yaml.loadAs(data, V1Pod.class);
    } catch (Exception ex) {
    // pass
    }
    assertFalse("Object should not be constructed!", TestPoJ.hasBeenConstructed());
}
Also used : V1Pod(io.kubernetes.client.openapi.models.V1Pod) IOException(java.io.IOException) Test(org.junit.Test)

Example 22 with V1Pod

use of io.kubernetes.client.openapi.models.V1Pod in project java by kubernetes-client.

the class ReflectorRunnableTest method testReflectorRunnableShouldCaptureListNon410ApiException.

@Test
public void testReflectorRunnableShouldCaptureListNon410ApiException() throws ApiException {
    ApiException expectedException = new ApiException(403, "noxu");
    AtomicReference<Throwable> actualException = new AtomicReference<>();
    when(listerWatcher.list(any())).thenThrow(expectedException);
    ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable = new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO, (apiType, t) -> {
        actualException.set(t);
    });
    try {
        Thread thread = new Thread(reflectorRunnable::run);
        thread.setDaemon(true);
        thread.start();
        Awaitility.await().atMost(Duration.ofSeconds(1)).pollInterval(Duration.ofMillis(100)).untilAtomic(actualException, new IsEqual<>(expectedException));
    } finally {
        reflectorRunnable.stop();
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 23 with V1Pod

use of io.kubernetes.client.openapi.models.V1Pod 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 24 with V1Pod

use of io.kubernetes.client.openapi.models.V1Pod 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();
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Status(io.kubernetes.client.openapi.models.V1Status) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) Test(org.junit.Test)

Example 25 with V1Pod

use of io.kubernetes.client.openapi.models.V1Pod 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());
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) Test(org.junit.Test)

Aggregations

V1Pod (io.kubernetes.client.openapi.models.V1Pod)99 Test (org.junit.Test)55 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)38 V1PodList (io.kubernetes.client.openapi.models.V1PodList)33 Type (java.lang.reflect.Type)22 ApiException (io.kubernetes.client.openapi.ApiException)20 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)15 ApiClient (io.kubernetes.client.openapi.ApiClient)12 Watch (io.kubernetes.client.util.Watch)10 V1Status (io.kubernetes.client.openapi.models.V1Status)9 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 JSON (io.kubernetes.client.openapi.JSON)7 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)7 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)4 V1Patch (io.kubernetes.client.custom.V1Patch)4 V1Container (io.kubernetes.client.openapi.models.V1Container)4