Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.cloudfoundry.client.v3;

import static org.assertj.core.api.Assertions.assertThat;
import static org.cloudfoundry.client.v3.tasks.TaskState.RUNNING;
import static org.cloudfoundry.util.tuple.TupleUtils.function;

Expand Down Expand Up @@ -74,15 +75,23 @@ public void cancel() throws IOException {
.flatMap(
function(
(applicationId, dropletId) ->
createTaskId(this.cloudFoundryClient, applicationId)))
// A short command like "ls" can finish before the cancel
// request, which then fails with "Task state is SUCCEEDED
// and therefore cannot be canceled".
createLongRunningTaskId(
this.cloudFoundryClient, applicationId)))
.flatMap(
taskId ->
this.cloudFoundryClient
.tasks()
.cancel(CancelTaskRequest.builder().taskId(taskId).build())
.map(CancelTaskResponse::getState))
.as(StepVerifier::create)
.expectNext(TaskState.CANCELING)
// The Cloud Controller sets the task to CANCELING, cancels it in Diego and then
// reloads it for the response. If Diego has already reported the canceled task as
// FAILED by then, the response shows FAILED instead of CANCELING.
.consumeNextWith(
state -> assertThat(state).isIn(TaskState.CANCELING, TaskState.FAILED))
.expectComplete()
.verify(Duration.ofMinutes(5));
}
Expand Down Expand Up @@ -305,6 +314,20 @@ private static Mono<String> createTaskId(
return requestCreateTask(cloudFoundryClient, applicationId).map(CreateTaskResponse::getId);
}

private static Mono<String> createLongRunningTaskId(
CloudFoundryClient cloudFoundryClient, String applicationId) {
return cloudFoundryClient
.tasks()
.create(
CreateTaskRequest.builder()
.applicationId(applicationId)
.command("sleep 99")
.diskInMb(64)
.memoryInMb(67)
.build())
.map(CreateTaskResponse::getId);
}

private static Mono<String> getApplicationId(
CloudFoundryClient cloudFoundryClient, String applicationName) {
return PaginationUtils.requestClientV3Resources(
Expand Down
Loading