Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Minor polish
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Jan 25, 2019
1 parent 1bfabeb commit c9f72cd
Showing 1 changed file with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void initializeTasklet() {
tasklet = new SystemCommandTasklet();
tasklet.setEnvironmentParams(null); // inherit from parent process
tasklet.setWorkingDirectory(null); // inherit from parent process
tasklet.setSystemProcessExitCodeMapper(new TestExitCodeMapper());
tasklet.setSystemProcessExitCodeMapper(new SimpleSystemProcessExitCodeMapper());
tasklet.setTimeout(5000); // long enough timeout
tasklet.setTerminationCheckInterval(500);
tasklet.setCommand("invalid command, change value for successful execution");
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testExecuteException() throws Exception {
*/
@Test
public void testExecuteTimeout() throws Exception {
String command = System.getProperty("os.name").toLowerCase().contains("win") ?
String command = isRunningOnWindows() ?
"ping 127.0.0.1" :
"sleep 3";
tasklet.setCommand(command);
Expand All @@ -158,7 +158,7 @@ public void testExecuteTimeout() throws Exception {
*/
@Test
public void testInterruption() throws Exception {
String command = System.getProperty("os.name").toLowerCase().contains("win") ?
String command = isRunningOnWindows() ?
"ping 127.0.0.1" :
"sleep 5";
tasklet.setCommand(command);
Expand Down Expand Up @@ -269,7 +269,7 @@ public void testStopped() throws Exception {

when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(), stepExecution.getJobExecution(), stoppedJobExecution);

String command = System.getProperty("os.name").toLowerCase().contains("win") ?
String command = isRunningOnWindows() ?
"ping 127.0.0.1 -n 5" :
"sleep 15";
tasklet.setCommand(command);
Expand All @@ -281,7 +281,7 @@ public void testStopped() throws Exception {
ChunkContext chunkContext = new ChunkContext(stepContext);
tasklet.execute(contribution, chunkContext);

assertEquals(contribution.getExitStatus().getExitCode(),ExitStatus.STOPPED.getExitCode());
assertEquals(ExitStatus.STOPPED.getExitCode(), contribution.getExitStatus().getExitCode());
}

private String getJavaCommand() {
Expand All @@ -294,29 +294,15 @@ private String getJavaCommand() {
command.append(fileSeparator);
command.append("java");

if(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
if(isRunningOnWindows()) {
command.append(".exe");
}

return command.toString();
}

/**
* Exit code mapper containing mapping logic expected by the tests. 0 means
* finished successfully, other value means failure.
*/
private static class TestExitCodeMapper implements SystemProcessExitCodeMapper {

@Override
public ExitStatus getExitStatus(int exitCode) {
if (exitCode == 0) {
return ExitStatus.COMPLETED;
}
else {
return ExitStatus.FAILED;
}
}

private boolean isRunningOnWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}

}

0 comments on commit c9f72cd

Please sign in to comment.