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());
}
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();
}
}
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();
}
}
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();
}
}
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());
}
Aggregations