Skip to content

Commit

Permalink
Handle cases where an invalid platform is specified.
Browse files Browse the repository at this point in the history
Now SCDF will not throw a NPE

resolves spring-cloud#4575
  • Loading branch information
cppwfs authored and jvalkeal committed Jun 14, 2021
1 parent 80e5fcc commit a1a26fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ public long executeTask(String taskName, Map<String, String> taskDeploymentPrope
}
}
Launcher launcher = this.launcherRepository.findByName(platformName);
if(launcher == null) {
throw new IllegalStateException(String.format("No launcher was available for platform %s", platformName));
}
validateTaskName(taskName, launcher);
// Remove since the key for task platform name will not pass validation for app,
// deployer, or scheduler prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
Expand Down Expand Up @@ -938,6 +939,22 @@ public void getCFTaskLogByTaskIdOtherThanLatest() {
assertEquals("", this.taskExecutionService.getLog(platformName, taskDeploymentId));
}

@Test
@DirtiesContext
public void executeSameTaskDefinitionWithInvalidPlatform() {
initializeSuccessfulRegistry(appRegistry);
when(taskLauncher.launch(any())).thenReturn("0");

Map<String, String> deploymentProperties = new HashMap<>();
deploymentProperties.put(DefaultTaskExecutionService.TASK_PLATFORM_NAME, "noplatformhere");

IllegalStateException thrown = assertThrows(
IllegalStateException.class,
() -> this.taskExecutionService.executeTask(TASK_NAME_ORIG, deploymentProperties, new LinkedList<>())
);

assertTrue(thrown.getMessage().contains("No launcher was available for platform noplatformhere"));
}

@Test
@DirtiesContext
Expand Down

0 comments on commit a1a26fb

Please sign in to comment.