Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed manual wiring of JsrJobOperator
While the JSR-352 provides only one way to access the JobOperator (BatchRuntime.getJobOperator()), it is useful for testing and embedding to be able to wire your own JsrJobOperator instance. This commit addresses previous issues with using the constructor that provided that functionality. Note: This is a breaking change in that there is a new parameter on the non-default constructor (adding a PlatformTransactionManager reference). Users using the JsrJobOperator through the BatchRuntime as previously mentioned should not be impacted. Since this is the *only* method perscribed by the JSR to consume that class, it is not expected to have a large impact. This fix partially addresses BATCH-2290.
- Loading branch information
Showing
4 changed files
with
140 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../org/springframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2014 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.configuration.xml; | ||
|
||
import java.util.Date; | ||
import java.util.Properties; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import javax.batch.operations.JobOperator; | ||
import javax.batch.runtime.BatchStatus; | ||
import javax.batch.runtime.JobExecution; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* @author Michael Minella | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration | ||
public class CustomWiredJsrJobOperatorTests { | ||
|
||
@Autowired | ||
JobOperator jobOperator; | ||
|
||
@Test | ||
public void testRunningJobWithManuallyWiredJsrJobOperator() throws Exception { | ||
Date startTime = new Date(); | ||
long jobExecutionId = jobOperator.start("jsrJobOperatorTestJob", new Properties()); | ||
|
||
JobExecution jobExecution = jobOperator.getJobExecution(jobExecutionId); | ||
|
||
long timeout = startTime.getTime() + 10000; | ||
|
||
while(!jobExecution.getBatchStatus().equals(BatchStatus.COMPLETED)) { | ||
Thread.sleep(500); | ||
jobExecution = jobOperator.getJobExecution(jobExecutionId); | ||
|
||
if(new Date().getTime() > timeout) { | ||
throw new TimeoutException("Job didn't finish within 10 seconds"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ringframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/> | ||
|
||
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> | ||
<property name="transactionManager" ref="transactionManager"/> | ||
</bean> | ||
|
||
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean"> | ||
<property name="repositoryFactory" ref="&jobRepository"/> | ||
</bean> | ||
|
||
<bean id="jobParametersConverter" class="org.springframework.batch.core.converter.DefaultJobParametersConverter"/> | ||
|
||
<bean id="jsrJobOperator" class="org.springframework.batch.core.jsr.launch.JsrJobOperator"> | ||
<constructor-arg ref="jobExplorer"/> | ||
<constructor-arg ref="jobRepository"/> | ||
<constructor-arg ref="jobParametersConverter"/> | ||
<constructor-arg ref="transactionManager"/> | ||
</bean> | ||
|
||
</beans> |