use of org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod in project flink by apache.
the class KubernetesResourceManagerDriverTest method testOnPodAdded.
@Test
public void testOnPodAdded() throws Exception {
new Context() {
{
final CompletableFuture<KubernetesPod> createPodFuture = new CompletableFuture<>();
final CompletableFuture<KubernetesWorkerNode> requestResourceFuture = new CompletableFuture<>();
flinkKubeClientBuilder.setCreateTaskManagerPodFunction((pod) -> {
createPodFuture.complete(pod);
return FutureUtils.completedVoidFuture();
});
runTest(() -> {
// request new pod
runInMainThread(() -> getDriver().requestResource(TASK_EXECUTOR_PROCESS_SPEC).thenAccept(requestResourceFuture::complete));
final KubernetesPod pod = new TestingKubernetesPod(createPodFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS).getName(), true, false);
// prepare validation:
// - complete requestResourceFuture in main thread with correct
// KubernetesWorkerNode
final CompletableFuture<Void> validationFuture = requestResourceFuture.thenAccept((workerNode) -> {
validateInMainThread();
assertThat(workerNode.getResourceID().toString(), is(pod.getName()));
});
// send onAdded event
getPodCallbackHandler().onAdded(Collections.singletonList(pod));
// make sure finishing validation
validationFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS);
});
}
};
}
use of org.apache.flink.kubernetes.kubeclient.resources.TestingKubernetesPod in project flink by apache.
the class KubernetesResourceManagerDriverTest method testRecoverPreviousAttemptWorkersPodTerminated.
@Test
public void testRecoverPreviousAttemptWorkersPodTerminated() throws Exception {
new Context() {
{
final KubernetesPod previousAttemptPod = new TestingKubernetesPod(CLUSTER_ID + "-taskmanager-1-1", true, true);
final CompletableFuture<String> stopPodFuture = new CompletableFuture<>();
final CompletableFuture<Collection<KubernetesWorkerNode>> recoveredWorkersFuture = new CompletableFuture<>();
flinkKubeClientBuilder.setGetPodsWithLabelsFunction((ignore) -> Collections.singletonList(previousAttemptPod)).setStopPodFunction((podName) -> {
stopPodFuture.complete(podName);
return FutureUtils.completedVoidFuture();
});
resourceEventHandlerBuilder.setOnPreviousAttemptWorkersRecoveredConsumer(recoveredWorkersFuture::complete);
runTest(() -> {
// validate the terminated pod from previous attempt is not recovered
// and is removed
assertThat(recoveredWorkersFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS), empty());
assertThat(stopPodFuture.get(TIMEOUT_SEC, TimeUnit.SECONDS), is(previousAttemptPod.getName()));
});
}
};
}
Aggregations