Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBERET-521] Add test example for jberet se bom 1.4.x #166

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions test-apps/jberetSeBomTest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>test-apps</artifactId>
<groupId>org.jberet.test-apps</groupId>
<version>1.4.5.Final-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jberetSeBomTest</artifactId>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jberet</groupId>
<artifactId>jberet-se-bom</artifactId>
<version>1.4.5.Final-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.3_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling</artifactId>
</dependency>
<dependency>
<groupId>org.jberet</groupId>
<artifactId>jberet-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.jberet</groupId>
<artifactId>jberet-se</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bom.test;

import javax.batch.api.AbstractBatchlet;
import javax.batch.runtime.BatchStatus;
import javax.inject.Named;

@Named
public class SimpleBatchlet extends AbstractBatchlet {
@Override
public String process() throws Exception {
return BatchStatus.COMPLETED.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<job id="simpleBatchlet">
<step id="firstStep" >
<batchlet ref="simpleBatchlet"/>
</step>
</job>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<batch-artifacts xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/batchXML_1_0.xsd">
<ref id="arrayItemReader" class="org.jberet.support.io.ArrayItemReader" />
<ref id="mockItemWriter" class="org.jberet.support.io.MockItemWriter" />
</batch-artifacts>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
41 changes: 41 additions & 0 deletions test-apps/jberetSeBomTest/src/test/java/SimpleBatchletTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.junit.Assert;
import org.junit.Test;

import javax.batch.operations.JobOperator;
import javax.batch.runtime.BatchRuntime;
import javax.batch.runtime.BatchStatus;
import javax.batch.runtime.JobExecution;
import java.util.Properties;

import static javax.batch.runtime.BatchStatus.COMPLETED;

public class SimpleBatchletTest {
private static final int MAX_TRIES = 40;
private static final int THREAD_SLEEP = 1000;

@Test
public void givenBatchLetStarted_whenStopped_thenBatchStopped() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("simpleBatchlet", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);

jobExecution = keepTestAlive(jobExecution);

Assert.assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}

private JobExecution keepTestAlive(JobExecution jobExecution) throws InterruptedException {
int maxTries = 0;
while (!jobExecution.getBatchStatus().equals(COMPLETED)) {
if (maxTries < MAX_TRIES) {
maxTries++;
Thread.sleep(THREAD_SLEEP);
jobExecution = BatchRuntime.getJobOperator().getJobExecution(jobExecution.getExecutionId());
} else {
break;
}
}
Thread.sleep(THREAD_SLEEP);
return jobExecution;
}
}
1 change: 1 addition & 0 deletions test-apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<module>cassandraInject</module>
<module>jdbcBatchletReaderWriter</module>
<module>serialization</module>
<module>jberetSeBomTest</module>
</modules>
<parent>
<groupId>org.jberet</groupId>
Expand Down