Skip to content

Commit

Permalink
HSEARCH-2621 JSR-352: Switch to JBatch for JavaSE integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere authored and Sanne committed Oct 25, 2017
1 parent 62f524a commit 3f22db9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 69 deletions.
57 changes: 11 additions & 46 deletions jsr352/core/pom.xml
Expand Up @@ -70,56 +70,21 @@
<scope>test</scope>
</dependency>

<!-- The JBeret artifacts declare all the dependencies as provided, so we have to redeclare them ourselves... -->
<!-- JBeret minimal application dependencies -->
<!-- https://jberet.gitbooks.io/jberet-user-guide/content/set_up_jberet/#minimal-application-dependencies -->
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<groupId>com.ibm.jbatch</groupId>
<artifactId>com.ibm.jbatch-runtime</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<!--
JBatch requires a database in order to work, and it seems it uses SQL that won't work with H2.
Anyway, it uses an embedded Derby instance by default, so we just put the Derby driver in the classpath
so it won't complain.
-->
<dependency>
<groupId>org.jberet</groupId>
<artifactId>jberet-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling</artifactId>
<version>1.4.11.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>2.3.4.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-security-manager</artifactId>
<version>1.1.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>test</scope>
</dependency>

<!-- The JBeret artifacts declare all the dependencies as provided, so we have to redeclare them ourselves... -->
<!-- Additional dependencies for Java SE batch applications -->
<!-- https://jberet.gitbooks.io/jberet-user-guide/content/set_up_jberet/#additional-dependencies-for-java-se-batch-applications -->
<dependency>
<groupId>org.jberet</groupId>
<artifactId>jberet-se</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.3.4.Final</version>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.13.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -18,7 +18,6 @@
import javax.batch.runtime.BatchStatus;
import javax.batch.runtime.JobExecution;
import javax.batch.runtime.Metric;
import javax.batch.runtime.Metric.MetricType;
import javax.batch.runtime.StepExecution;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
Expand All @@ -28,6 +27,7 @@
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.hibernate.search.jsr352.logging.impl.Log;
import org.hibernate.search.jsr352.massindexing.impl.steps.lucene.StepProgress;
import org.hibernate.search.jsr352.massindexing.test.entity.Company;
import org.hibernate.search.jsr352.massindexing.test.entity.Person;
import org.hibernate.search.jsr352.massindexing.test.entity.WhoAmI;
Expand All @@ -51,12 +51,6 @@ public class BatchIndexingJobIT {

private static final int JOB_TIMEOUT_MS = 10_000;

// example dataset
private static final long DB_COMP_ROWS = 3;
private static final long DB_PERS_ROWS = 3;
private static final long DB_WHOS_ROWS = 3;
private static final long DB_TOTAL_ROWS = DB_COMP_ROWS + DB_PERS_ROWS + DB_WHOS_ROWS;

private JobOperator jobOperator;
private EntityManagerFactory emf;

Expand Down Expand Up @@ -268,17 +262,19 @@ public void hql() throws InterruptedException,

private void testBatchStatus(StepExecution stepExecution) {
BatchStatus batchStatus = stepExecution.getBatchStatus();
assertEquals( BatchStatus.COMPLETED, batchStatus );
switch ( stepExecution.getStepName() ) {
case "produceLuceneDoc":
for ( Metric m : stepExecution.getMetrics() ) {
if ( m.getType().equals( MetricType.READ_COUNT ) ) {
assertEquals( DB_TOTAL_ROWS, m.getValue() );
}
else if ( m.getType().equals( MetricType.WRITE_COUNT ) ) {
assertEquals( DB_TOTAL_ROWS, m.getValue() );
}
}
assertEquals( BatchStatus.COMPLETED, batchStatus );
/*
* We cannot check the metrics, which in JBatch are set to 0
* for partitioned steps (the metrics are handled separately for
* each partition).
* Thus we check our own object.
*/
StepProgress progress = (StepProgress) stepExecution.getPersistentUserData();
assertEquals( 1.0, progress.getProgress( Company.class.getName() ), 0.01 );
assertEquals( 1.0, progress.getProgress( Person.class.getName() ), 0.01 );
assertEquals( 1.0, progress.getProgress( WhoAmI.class.getName() ), 0.01 );
break;

default:
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Properties;

import javax.batch.operations.JobOperator;
import javax.batch.runtime.BatchStatus;
Expand Down Expand Up @@ -109,14 +110,15 @@ public void testJob() throws InterruptedException, IOException {
assertEquals( 0, people.size() );

// start the job
Properties parameters = MassIndexingJob.parameters()
.forEntities( Company.class, Person.class )
.entityManagerFactoryReference( PERSISTENCE_UNIT_NAME )
// must be smaller than ITEMS_BEFORE_SIMULATED_FAILURE to trigger the restart
.checkpointInterval( 10 )
.build();
long execId1 = jobOperator.start(
MassIndexingJob.NAME,
MassIndexingJob.parameters()
.forEntities( Company.class, Person.class )
.entityManagerFactoryReference( PERSISTENCE_UNIT_NAME )
// must be smaller than ITEMS_BEFORE_SIMULATED_FAILURE to trigger the restart
.checkpointInterval( 10 )
.build()
parameters
);
JobExecution jobExec1 = jobOperator.getJobExecution( execId1 );
JobTestUtil.waitForTermination( jobOperator, jobExec1, JOB_TIMEOUT_MS );
Expand All @@ -128,7 +130,11 @@ public void testJob() throws InterruptedException, IOException {
}

// restart the job
long execId2 = jobOperator.restart( execId1, null );
/*
* From the specs (v1.0, 10.8.1):
* Job parameter values are not remembered from one execution to the next.
*/
long execId2 = jobOperator.restart( execId1, parameters );
JobExecution jobExec2 = jobOperator.getJobExecution( execId2 );
JobTestUtil.waitForTermination( jobOperator, jobExec2, JOB_TIMEOUT_MS );
for ( StepExecution stepExec : jobOperator.getStepExecutions( execId2 ) ) {
Expand Down
@@ -0,0 +1,6 @@
# Let JBatch use an embedded Derby database (the default),
# since the SQL it generates doesn't seem to work on other DBs (H2 in particular)

# However, we still customize the database location
# (the default uses a "RUNTIMEDB" directory in the current working directory)
JDBC_URL=jdbc:derby:memory:jbatch;create=true
@@ -0,0 +1 @@
J2SE_MODE=true

0 comments on commit 3f22db9

Please sign in to comment.