BATCH-845: fixed some transactinal issues in the samples showing up when running against a transactional db
This commit is contained in:
@@ -49,7 +49,7 @@ public class DatabaseShutdownFunctionalTests extends AbstractBatchLauncherTests
|
||||
this.jobOperator = jobOperator;
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class HibernateFailureJobFunctionalTests extends AbstractCustomerCreditIn
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
|
||||
setJobParameters(params);
|
||||
|
||||
@@ -31,6 +31,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.After;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -71,7 +72,12 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
simpleJdbcTemplate.update("delete from TRADE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception{
|
||||
super.testLaunchJob();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.batch.sample.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -18,6 +19,8 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
@@ -49,7 +52,7 @@ public class StagingItemReaderTests {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void onSetUpBeforeTransaction() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId,
|
||||
new JobParameters(), "testJob")));
|
||||
@@ -59,7 +62,7 @@ public class StagingItemReaderTests {
|
||||
reader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterTransaction
|
||||
public void onTearDownAfterTransaction() throws Exception {
|
||||
reader.close(null);
|
||||
simpleJdbcTemplate.update("DELETE FROM BATCH_STAGING");
|
||||
@@ -85,11 +88,15 @@ public class StagingItemReaderTests {
|
||||
|
||||
@Transactional @Test
|
||||
public void testUpdateProcessIndicatorAfterCommit() throws Exception {
|
||||
testReaderUpdatesProcessIndicator();
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
try {
|
||||
testReaderUpdatesProcessIndicator();
|
||||
} catch (Exception e) {
|
||||
fail("Unxpected Exception: " + e);
|
||||
}
|
||||
long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
jobId);
|
||||
String before =
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
@@ -85,7 +86,7 @@ public class JdbcJobRepositoryTests {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
job = new JobSupport("test-job");
|
||||
job.setRestartable(true);
|
||||
@@ -113,8 +114,9 @@ public class JdbcJobRepositoryTests {
|
||||
|
||||
@Transactional @Test
|
||||
public void testFindOrCreateJob() throws Exception {
|
||||
System.out.println("**** START ****");
|
||||
job.setName("foo");
|
||||
int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
int before = 0;
|
||||
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
|
||||
int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(before + 1, after);
|
||||
@@ -126,7 +128,7 @@ public class JdbcJobRepositoryTests {
|
||||
|
||||
job.setName("bar");
|
||||
|
||||
int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
int before = 0;
|
||||
assertEquals(0, before);
|
||||
|
||||
long t0 = System.currentTimeMillis();
|
||||
@@ -151,9 +153,11 @@ public class JdbcJobRepositoryTests {
|
||||
+ " - the second transaction did not block if this number is less than about 1000.");
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception {
|
||||
|
||||
job = new JobSupport("test-job");
|
||||
job.setRestartable(true);
|
||||
job.setName("spam");
|
||||
|
||||
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
|
||||
|
||||
Reference in New Issue
Block a user