Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consider terminated a non existing DataFlow #4420

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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 @@ -31,6 +31,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -114,7 +115,10 @@ public boolean canHandle(TransferProcess transferProcess) {

@Override
public StatusResult<Void> suspend(TransferProcess transferProcess) {
return getClientForDataplane(transferProcess.getDataPlaneId())
return Optional.ofNullable(transferProcess.getDataPlaneId())
.map(StatusResult::success)
.orElse(StatusResult.failure(FATAL_ERROR, "DataPlane id is null"))
.compose(this::getClientForDataplane)
.map(client -> client.suspend(transferProcess.getId()))
.orElse(f -> {
var message = "Failed to select the data plane for suspending the transfer process %s. %s"
Expand All @@ -125,7 +129,12 @@ public StatusResult<Void> suspend(TransferProcess transferProcess) {

@Override
public StatusResult<Void> terminate(TransferProcess transferProcess) {
return getClientForDataplane(transferProcess.getDataPlaneId())
var dataPlaneId = transferProcess.getDataPlaneId();
if (dataPlaneId == null) {
return StatusResult.success();
}

return getClientForDataplane(dataPlaneId)
.map(client -> client.terminate(transferProcess.getId()))
.orElse(f -> {
var message = "Failed to select the data plane for terminating the transfer process %s. %s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

public class DataPlaneSignalingFlowControllerTest {
Expand Down Expand Up @@ -256,6 +257,20 @@ void shouldFail_whenDataPlaneNotFound() {

assertThat(result).isFailed().detail().contains("Failed to select the data plane for terminating the transfer process");
}

@Test // a null dataPlaneId means that the flow has not been started so it can be considered as already terminated
void shouldReturnSuccess_whenDataPlaneIdIsNull() {
var transferProcess = transferProcessBuilder()
.id("transferProcessId")
.contentDataAddress(testDataAddress())
.dataPlaneId(null)
.build();

var result = flowController.terminate(transferProcess);

assertThat(result).isSucceeded();
verifyNoInteractions(dataPlaneClient, dataPlaneClientFactory, selectorService);
}
}

@Nested
Expand Down Expand Up @@ -287,13 +302,26 @@ void shouldFail_whenDataPlaneDoesNotExist() {
.contentDataAddress(testDataAddress())
.dataPlaneId("invalid")
.build();
when(dataPlaneClient.suspend(any())).thenReturn(StatusResult.success());
when(dataPlaneClientFactory.createClient(any())).thenReturn(dataPlaneClient);
when(selectorService.findById(any())).thenReturn(ServiceResult.notFound("not found"));

var result = flowController.suspend(transferProcess);

assertThat(result).isFailed().detail().contains("Failed to select the data plane for suspending the transfer process");
verifyNoInteractions(dataPlaneClient, dataPlaneClientFactory);
}

@Test
void shouldFail_whenDataPlaneIdIsNull() {
var transferProcess = TransferProcess.Builder.newInstance()
.id("transferProcessId")
.contentDataAddress(testDataAddress())
.dataPlaneId(null)
.build();

var result = flowController.suspend(transferProcess);

assertThat(result).isFailed().detail().contains("Failed to select the data plane for suspending the transfer process");
verifyNoInteractions(dataPlaneClient, dataPlaneClientFactory, selectorService);
}

}
Expand Down
Loading