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