Fix TCK test JobOperatorTests.testJobOperatorRestartJobAlreadyAbandoned

* On restart if a previous JobExecution has a status of ABANDONED, throw a JobRestartException
* Ensure any previous JobParameters are merged with new parameters when creating a new job execution on restart
This commit is contained in:
Chris Schaefer
2013-09-04 20:18:08 -04:00
parent c4231c4cc8
commit 7f1130c9a2
5 changed files with 106 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ import java.util.Set;
import javax.batch.operations.JobExecutionIsRunningException;
import javax.batch.operations.JobOperator;
import javax.batch.operations.JobRestartException;
import javax.batch.operations.NoSuchJobException;
import javax.batch.operations.NoSuchJobExecutionException;
import javax.batch.operations.NoSuchJobInstanceException;
@@ -374,4 +375,40 @@ public class JsrJobOperatorTests {
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(finalExecutionId).getBatchStatus());
}
@Test(expected = JobRestartException.class)
public void testRestartAbandoned() {
jsrJobOperator = BatchRuntime.getJobOperator();
long executionId = jsrJobOperator.start("jsrJobOperatorTestRestartAbandonJob", null);
assertEquals(BatchStatus.FAILED, jsrJobOperator.getJobExecution(executionId).getBatchStatus());
jsrJobOperator.abandon(executionId);
jsrJobOperator.restart(executionId, null);
}
@Test
public void testGetNoRestartJobParameters() {
JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;
Properties properties = jobOperator.getJobRestartProperties(null, null);
assertTrue(properties.isEmpty());
}
@Test
public void testGetRestartJobParameters() {
JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;
JobExecution jobExecution = new JobExecution(1L,
new JobParametersBuilder().addString("prevKey1", "prevVal1").toJobParameters());
Properties userProperties = new Properties();
userProperties.put("userKey1", "userVal1");
Properties properties = jobOperator.getJobRestartProperties(userProperties, jobExecution);
assertTrue(properties.size() == 2);
assertTrue(properties.getProperty("prevKey1").equals("prevVal1"));
assertTrue(properties.getProperty("userKey1").equals("userVal1"));
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.jsr.step.batchlet;
import javax.batch.api.Batchlet;
/**
* <p>
* Test batchlet that always fails..
* </p>
*
* @author Chris Schaefer
*/
public class FailingBatchlet implements Batchlet {
@Override
public String process() throws Exception {
throw new RuntimeException("process failed");
}
@Override
public void stop() throws Exception {
}
}