Skip to content

Commit 457c4b2

Browse files
committed
Increased robustness of scheduled batch tests
Added extra wait for final step
1 parent 9f1d449 commit 457c4b2

File tree

6 files changed

+89
-23
lines changed

6 files changed

+89
-23
lines changed

batch/scheduling/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
43
<modelVersion>4.0.0</modelVersion>
54

65
<parent>
76
<groupId>org.javaee7</groupId>
87
<artifactId>batch</artifactId>
98
<version>1.0-SNAPSHOT</version>
10-
<relativePath>../pom.xml</relativePath>
119
</parent>
10+
1211
<artifactId>batch-scheduling</artifactId>
1312
<packaging>war</packaging>
1413
<name>Java EE 7 Sample: batch - scheduling</name>
14+
1515
<description>Scheduling a Batch Job</description>
1616

1717
<dependencies>
1818
<dependency>
1919
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
2020
<artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
2121
</dependency>
22+
<dependency>
23+
<groupId>org.javaee7</groupId>
24+
<artifactId>test-utils</artifactId>
25+
<version>${project.version}</version>
26+
</dependency>
2227
</dependencies>
2328
</project>

batch/scheduling/src/test/java/org/javaee7/batch/samples/scheduling/ManagedScheduledBatchTest.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package org.javaee7.batch.samples.scheduling;
22

3+
import static com.jayway.awaitility.Awaitility.await;
4+
import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
5+
import static com.jayway.awaitility.Duration.ONE_MINUTE;
6+
import static java.lang.System.out;
37
import static java.lang.Thread.sleep;
48
import static java.util.concurrent.TimeUnit.SECONDS;
9+
import static javax.batch.runtime.BatchRuntime.getJobOperator;
510
import static javax.batch.runtime.BatchStatus.COMPLETED;
11+
import static javax.batch.runtime.BatchStatus.STARTED;
12+
import static org.javaee7.Libraries.awaitability;
13+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
614
import static org.junit.Assert.assertEquals;
715

8-
import javax.batch.runtime.BatchRuntime;
16+
import java.util.concurrent.Callable;
17+
18+
import javax.batch.runtime.JobExecution;
919
import javax.inject.Inject;
1020

1121
import org.jboss.arquillian.container.test.api.Deployment;
1222
import org.jboss.arquillian.junit.Arquillian;
13-
import org.jboss.shrinkwrap.api.ShrinkWrap;
1423
import org.jboss.shrinkwrap.api.asset.StringAsset;
1524
import org.jboss.shrinkwrap.api.spec.WebArchive;
1625
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
@@ -54,7 +63,7 @@ public class ManagedScheduledBatchTest {
5463
public static WebArchive createDeployment() {
5564
BeansDescriptor beansXml = Descriptors.create(BeansDescriptor.class);
5665

57-
WebArchive war = ShrinkWrap.create(WebArchive.class)
66+
WebArchive war = create(WebArchive.class)
5867
.addClasses(
5968
MyBatchlet.class,
6069
MyJob.class,
@@ -67,7 +76,8 @@ public static WebArchive createDeployment() {
6776
new StringAsset(beansXml.getOrCreateAlternatives().clazz(
6877
MyManagedScheduledBatchAlternative.class.getName()).up().exportAsString()),
6978
beansXml.getDescriptorName())
70-
.addAsResource("META-INF/batch-jobs/myJob.xml");
79+
.addAsResource("META-INF/batch-jobs/myJob.xml")
80+
.addAsLibraries(awaitability());
7181

7282
System.out.println(war.toString(true));
7383

@@ -93,13 +103,23 @@ public void testTimeScheduleBatch() throws Exception {
93103
assertEquals(3, MyJob.executedBatchs.size());
94104

95105
sleep(1000l);
106+
107+
final JobExecution lastExecution = getJobOperator().getJobExecution(MyJob.executedBatchs.get(2));
108+
109+
await().atMost(ONE_MINUTE)
110+
.with().pollInterval(FIVE_HUNDRED_MILLISECONDS)
111+
.until( new Callable<Boolean>() { @Override public Boolean call() throws Exception {
112+
return lastExecution.getBatchStatus() != STARTED; }}
113+
);
96114

97115
for (Long executedBatch : MyJob.executedBatchs) {
98-
System.out.println("ManagedScheduledBatchTest checking completed for batch " + executedBatch);
116+
117+
out.println("ManagedScheduledBatchTest checking completed for batch " + executedBatch);
118+
99119
assertEquals(
100120
"Outcome equal for batch " + executedBatch,
101121
COMPLETED,
102-
BatchRuntime.getJobOperator().getJobExecution(executedBatch).getBatchStatus());
122+
getJobOperator().getJobExecution(executedBatch).getBatchStatus());
103123
}
104124
}
105125
}

batch/scheduling/src/test/java/org/javaee7/batch/samples/scheduling/TimerScheduleBatchTest.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package org.javaee7.batch.samples.scheduling;
22

3+
import static com.jayway.awaitility.Awaitility.await;
4+
import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
5+
import static com.jayway.awaitility.Duration.ONE_MINUTE;
36
import static java.util.concurrent.TimeUnit.SECONDS;
47
import static javax.batch.runtime.BatchRuntime.getJobOperator;
58
import static javax.batch.runtime.BatchStatus.COMPLETED;
9+
import static javax.batch.runtime.BatchStatus.STARTED;
10+
import static org.javaee7.Libraries.awaitability;
611
import static org.javaee7.batch.samples.scheduling.MyStepListener.countDownLatch;
12+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
13+
import static org.jboss.shrinkwrap.api.asset.EmptyAsset.INSTANCE;
714
import static org.junit.Assert.assertEquals;
815

16+
import java.util.concurrent.Callable;
17+
18+
import javax.batch.runtime.JobExecution;
19+
920
import org.jboss.arquillian.container.test.api.Deployment;
1021
import org.jboss.arquillian.junit.Arquillian;
1122
import org.jboss.shrinkwrap.api.ArchivePaths;
12-
import org.jboss.shrinkwrap.api.ShrinkWrap;
13-
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
1423
import org.jboss.shrinkwrap.api.spec.WebArchive;
1524
import org.junit.Test;
1625
import org.junit.runner.RunWith;
@@ -46,15 +55,16 @@ public class TimerScheduleBatchTest {
4655
*/
4756
@Deployment
4857
public static WebArchive createDeployment() {
49-
WebArchive war = ShrinkWrap.create(WebArchive.class)
58+
WebArchive war = create(WebArchive.class)
5059
.addClasses(
5160
MyJob.class,
5261
MyBatchlet.class,
5362
MyStepListener.class,
5463
AbstractTimerBatch.class,
5564
MyTimerScheduleAlternative.class)
56-
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
57-
.addAsResource("META-INF/batch-jobs/myJob.xml");
65+
.addAsWebInfResource(INSTANCE, ArchivePaths.create("beans.xml"))
66+
.addAsResource("META-INF/batch-jobs/myJob.xml")
67+
.addAsLibraries(awaitability());
5868

5969
System.out.println(war.toString(true));
6070

@@ -75,10 +85,20 @@ public void testTimeScheduleBatch() throws Exception {
7585

7686
assertEquals(0, countDownLatch.getCount());
7787
assertEquals(3, MyTimerScheduleAlternative.executedBatchs.size());
88+
89+
final JobExecution lastExecution = getJobOperator().getJobExecution(MyTimerScheduleAlternative.executedBatchs.get(2));
90+
91+
await().atMost(ONE_MINUTE)
92+
.with().pollInterval(FIVE_HUNDRED_MILLISECONDS)
93+
.until( new Callable<Boolean>() { @Override public Boolean call() throws Exception {
94+
return lastExecution.getBatchStatus() != STARTED; }}
95+
);
7896

7997
for (Long executedBatch : MyTimerScheduleAlternative.executedBatchs) {
8098

81-
System.out.println("TimerScheduleBatchTest checking completed for batch " + executedBatch);
99+
System.out.println(
100+
"TimerScheduleBatchTest checking batch " + executedBatch +
101+
" batch statuc = " + getJobOperator().getJobExecution(executedBatch).getBatchStatus());
82102

83103
assertEquals(
84104
COMPLETED,

jca/pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
67
<groupId>org.javaee7</groupId>
78
<artifactId>samples-parent</artifactId>
89
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
1010
</parent>
11-
<groupId>org.javaee7</groupId>
11+
1212
<artifactId>jca</artifactId>
13-
<version>1.0-SNAPSHOT</version>
1413
<packaging>pom</packaging>
1514
<name>Java EE 7 Sample: jca</name>
1615

1716
<modules>
18-
<module>connector-simple</module>
19-
<module>mdb-filewatcher</module>
20-
</modules>
17+
<module>connector-simple</module>
18+
<module>mdb-filewatcher</module>
19+
</modules>
2120

2221
<dependencies>
2322
<dependency>

test-utils/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
67
<artifactId>samples-parent</artifactId>
78
<groupId>org.javaee7</groupId>
89
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
1010
</parent>
11+
1112
<artifactId>test-utils</artifactId>
1213
<name>Java EE 7 Sample: javaee7-samples - test-utils</name>
1314

@@ -21,5 +22,10 @@
2122
<groupId>org.jboss.arquillian.container</groupId>
2223
<artifactId>arquillian-container-test-api</artifactId>
2324
</dependency>
25+
<dependency>
26+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
27+
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
28+
</dependency>
2429
</dependencies>
30+
2531
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.javaee7;
2+
3+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
4+
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
5+
6+
public class Libraries {
7+
8+
public static JavaArchive[] awaitability() {
9+
return Maven.resolver()
10+
.loadPomFromFile("pom.xml")
11+
.resolve("org.assertj:assertj-core", "com.jayway.awaitility:awaitility")
12+
.withTransitivity()
13+
.as(JavaArchive.class);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)