Skip to content

Commit

Permalink
JBERET-154 Support restarting killed or crashed job execution: valida…
Browse files Browse the repository at this point in the history
…te restart mode value, and add and improve related tests in purgeJdbcRepository and purgeMongoRepository.
  • Loading branch information
chengfang committed Apr 22, 2015
1 parent fe2f860 commit 604775f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ public interface BatchMessages {
@Message(id = 647, value = "Restarting job execution %s, job name %s, batch status %s, restart mode %s, but it seems the original execution is still alive.")
JobRestartException restartRunningExecution(long executionId, String jobName, BatchStatus previousStatus, String restartMode);

@Message(id = 648, value = "Restarting job execution %s, job name %s, batch status %s, but restart mode %s is invalid. Valid values are %s")
JobRestartException invalidRestartMode(long executionId, String jobName, BatchStatus previousStatus, String restartMode, List<String> validRestartMode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -211,6 +212,9 @@ public long restart(final long executionId, final Properties restartParameters)
if (originalToRestart.getJobInstance().getUnsubstitutedJob() != null) {
throw MESSAGES.restartRunningExecution(executionId, originalToRestart.getJobName(), previousStatus, restartMode);
}
} else if (!restartMode.equalsIgnoreCase(PropertyKey.RESTART_MODE_FORCE)) {
throw MESSAGES.invalidRestartMode(executionId, originalToRestart.getJobName(), previousStatus, restartMode,
Arrays.asList(PropertyKey.RESTART_MODE_DETECT, PropertyKey.RESTART_MODE_FORCE, PropertyKey.RESTART_MODE_STRICT));
}

//update batch status in originalToRestart to FAILED, for previousStatus STARTING, STARTED, or STOPPING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,47 @@ protected void ctrlC() throws Exception {
startJobAndWait(chunkPartitionJobXml);
}

protected void invalidRestartMode() throws Exception {
final Properties restartParams = new Properties();
restartParams.setProperty(PropertyKey.RESTART_MODE, "auto");
restartKilled(restartParams);
}

protected void restartKilledStrict() throws Exception {
final Properties restartParams = new Properties();
restartParams.setProperty(PropertyKey.RESTART_MODE, PropertyKey.RESTART_MODE_STRICT);
restartKilled(restartParams);
}

protected void restartKilled() throws Exception {
final Properties restartParams = new Properties();
restartParams.setProperty("writer.sleep.time", "0");
restartKilled(restartParams);
restartKilled(null);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}

protected void restartKilledForce() throws Exception {
final Properties restartParams = new Properties();
restartParams.setProperty(PropertyKey.RESTART_MODE, PropertyKey.RESTART_MODE_FORCE);
restartParams.setProperty("writer.sleep.time", "0");
restartKilled(restartParams);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}

protected void restartKilledDetect() throws Exception {
final Properties restartParams = new Properties();
restartParams.setProperty(PropertyKey.RESTART_MODE, PropertyKey.RESTART_MODE_DETECT);
restartKilled(restartParams);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}

private void restartKilled(final Properties restartParams) throws InterruptedException {
final long originalJobExecutionId = getOriginalJobExecutionId(chunkPartitionJobXml);
params.putAll(restartParams);
params.setProperty("writer.sleep.time", "0");
if (restartParams != null) {
params.putAll(restartParams);
}
restartAndWait(originalJobExecutionId);
}



public static final class JobExecutionSelector1 implements JobExecutionSelector {
private JobContext jobContext;
private StepContext stepContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public void ctrlC() throws Exception {
super.ctrlC();
}

@Test(expected = JobRestartException.class)
@Ignore("run after ctrlC test has been killed with invalid restart mode, should fail")
public void invalidRestartMode() throws Exception {
super.invalidRestartMode();
}

@Test(expected = JobRestartException.class)
@Ignore("run after ctrlC test has been killed, should fail")
public void restartKilledStrict() throws Exception {
Expand All @@ -43,14 +49,19 @@ public void restartKilled() throws Exception {
super.restartKilled();
}

@Test
@Ignore("run after ctrlC test has been killed")
public void restartKilledDetect() throws Exception {
super.restartKilledDetect();
}

@Test
@Ignore("run after ctrlC test has been killed")
public void restartKilledForce() throws Exception {
super.restartKilledForce();
}



@Test
@Ignore("run it manually")
public void memoryTest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public void ctrlC() throws Exception {
super.ctrlC();
}

@Test(expected = JobRestartException.class)
@Ignore("run after ctrlC test has been killed with invalid restart mode, should fail")
public void invalidRestartMode() throws Exception {
super.invalidRestartMode();
}

@Test(expected = JobRestartException.class)
@Ignore("run after ctrlC test has been killed, should fail")
public void restartKilledStrict() throws Exception {
Expand All @@ -44,6 +50,12 @@ public void restartKilled() throws Exception {
super.restartKilled();
}

@Test
@Ignore("run after ctrlC test has been killed")
public void restartKilledDetect() throws Exception {
super.restartKilledDetect();
}

@Test
@Ignore("run after ctrlC test has been killed")
public void restartKilledForce() throws Exception {
Expand Down

0 comments on commit 604775f

Please sign in to comment.