|
1 |
| -package org.springframework.batch.integration.chunk; |
2 |
| - |
3 |
| -import static org.junit.Assert.assertEquals; |
4 |
| - |
5 |
| -import java.util.Collections; |
6 |
| - |
7 |
| -import org.junit.Before; |
8 |
| -import org.junit.Test; |
9 |
| -import org.junit.runner.RunWith; |
10 |
| -import org.springframework.batch.core.BatchStatus; |
11 |
| -import org.springframework.batch.core.Job; |
12 |
| -import org.springframework.batch.core.JobExecution; |
13 |
| -import org.springframework.batch.core.JobParameter; |
14 |
| -import org.springframework.batch.core.JobParameters; |
15 |
| -import org.springframework.batch.core.JobParametersBuilder; |
16 |
| -import org.springframework.batch.core.StepExecution; |
17 |
| -import org.springframework.batch.core.launch.JobLauncher; |
18 |
| -import org.springframework.beans.factory.annotation.Autowired; |
19 |
| -import org.springframework.messaging.Message; |
20 |
| -import org.springframework.messaging.PollableChannel; |
21 |
| -import org.springframework.test.annotation.DirtiesContext; |
22 |
| -import org.springframework.test.context.ContextConfiguration; |
23 |
| -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
24 |
| - |
25 |
| -@ContextConfiguration |
26 |
| -@RunWith(SpringJUnit4ClassRunner.class) |
27 |
| -public class RemoteChunkFaultTolerantStepJdbcIntegrationTests { |
28 |
| - |
29 |
| - @Autowired |
30 |
| - private JobLauncher jobLauncher; |
31 |
| - |
32 |
| - @Autowired |
33 |
| - private Job job; |
34 |
| - |
35 |
| - @Autowired |
36 |
| - private PollableChannel replies; |
37 |
| - |
38 |
| - @Before |
39 |
| - public void drain() { |
40 |
| - Message<?> message = replies.receive(100L); |
41 |
| - while (message!=null) { |
42 |
| - message = replies.receive(100L); |
43 |
| - } |
44 |
| - } |
45 |
| - |
46 |
| - @Test |
47 |
| - @DirtiesContext |
48 |
| - public void testFailedStep() throws Exception { |
49 |
| - JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
50 |
| - new JobParameter("unsupported")))); |
51 |
| - assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); |
52 |
| - StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
53 |
| - assertEquals(9, stepExecution.getReadCount()); |
54 |
| - // In principle the write count could be more than 2 and less than 9... |
55 |
| - assertEquals(7, stepExecution.getWriteCount()); |
56 |
| - } |
57 |
| - |
58 |
| - @Test |
59 |
| - @DirtiesContext |
60 |
| - public void testFailedStepOnError() throws Exception { |
61 |
| - JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
62 |
| - new JobParameter("error")))); |
63 |
| - assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); |
64 |
| - StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
65 |
| - assertEquals(9, stepExecution.getReadCount()); |
66 |
| - // In principle the write count could be more than 2 and less than 9... |
67 |
| - assertEquals(7, stepExecution.getWriteCount()); |
68 |
| - } |
69 |
| - |
70 |
| - @Test |
71 |
| - @DirtiesContext |
72 |
| - public void testSunnyDayFaultTolerant() throws Exception { |
73 |
| - JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
74 |
| - new JobParameter("3")))); |
75 |
| - assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); |
76 |
| - StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
77 |
| - assertEquals(9, stepExecution.getReadCount()); |
78 |
| - assertEquals(9, stepExecution.getWriteCount()); |
79 |
| - } |
80 |
| - |
81 |
| - @Test |
82 |
| - @DirtiesContext |
83 |
| - public void testSkipsInWriter() throws Exception { |
84 |
| - JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail") |
85 |
| - .addLong("run.id", 1L).toJobParameters()); |
86 |
| - // System.err.println(new SimpleJdbcTemplate(dataSource).queryForList("SELECT * FROM INT_MESSAGE_GROUP")); |
87 |
| - assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); |
88 |
| - StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
89 |
| - assertEquals(9, stepExecution.getReadCount()); |
90 |
| - assertEquals(7, stepExecution.getWriteCount()); |
91 |
| - // The whole chunk gets skipped... |
92 |
| - assertEquals(2, stepExecution.getWriteSkipCount()); |
93 |
| - } |
94 |
| -} |
| 1 | +package org.springframework.batch.integration.chunk; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.util.Collections; |
| 6 | + |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | +import org.springframework.batch.core.BatchStatus; |
| 11 | +import org.springframework.batch.core.Job; |
| 12 | +import org.springframework.batch.core.JobExecution; |
| 13 | +import org.springframework.batch.core.JobParameter; |
| 14 | +import org.springframework.batch.core.JobParameters; |
| 15 | +import org.springframework.batch.core.JobParametersBuilder; |
| 16 | +import org.springframework.batch.core.StepExecution; |
| 17 | +import org.springframework.batch.core.launch.JobLauncher; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.messaging.Message; |
| 20 | +import org.springframework.messaging.PollableChannel; |
| 21 | +import org.springframework.test.annotation.DirtiesContext; |
| 22 | +import org.springframework.test.context.ContextConfiguration; |
| 23 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 24 | + |
| 25 | +@ContextConfiguration |
| 26 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 27 | +public class RemoteChunkFaultTolerantStepJdbcIntegrationTests { |
| 28 | + |
| 29 | + @Autowired |
| 30 | + private JobLauncher jobLauncher; |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private Job job; |
| 34 | + |
| 35 | + @Autowired |
| 36 | + private PollableChannel replies; |
| 37 | + |
| 38 | + @Before |
| 39 | + public void drain() { |
| 40 | + Message<?> message = replies.receive(100L); |
| 41 | + while (message!=null) { |
| 42 | + message = replies.receive(100L); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + @DirtiesContext |
| 48 | + public void testFailedStep() throws Exception { |
| 49 | + JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
| 50 | + new JobParameter("unsupported")))); |
| 51 | + assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); |
| 52 | + StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
| 53 | + assertEquals(9, stepExecution.getReadCount()); |
| 54 | + // In principle the write count could be more than 2 and less than 9... |
| 55 | + assertEquals(7, stepExecution.getWriteCount()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + @DirtiesContext |
| 60 | + public void testFailedStepOnError() throws Exception { |
| 61 | + JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
| 62 | + new JobParameter("error")))); |
| 63 | + assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); |
| 64 | + StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
| 65 | + assertEquals(9, stepExecution.getReadCount()); |
| 66 | + // In principle the write count could be more than 2 and less than 9... |
| 67 | + assertEquals(7, stepExecution.getWriteCount()); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + @DirtiesContext |
| 72 | + public void testSunnyDayFaultTolerant() throws Exception { |
| 73 | + JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three", |
| 74 | + new JobParameter("3")))); |
| 75 | + assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); |
| 76 | + StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
| 77 | + assertEquals(9, stepExecution.getReadCount()); |
| 78 | + assertEquals(9, stepExecution.getWriteCount()); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + @DirtiesContext |
| 83 | + public void testSkipsInWriter() throws Exception { |
| 84 | + JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail") |
| 85 | + .addLong("run.id", 1L).toJobParameters()); |
| 86 | + assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); |
| 87 | + StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next(); |
| 88 | + assertEquals(9, stepExecution.getReadCount()); |
| 89 | + assertEquals(7, stepExecution.getWriteCount()); |
| 90 | + // The whole chunk gets skipped... |
| 91 | + assertEquals(2, stepExecution.getWriteSkipCount()); |
| 92 | + } |
| 93 | +} |
0 commit comments