From 348b13b2aa1eec51503b2c208cbdfa540b01aa2f Mon Sep 17 00:00:00 2001 From: Fabio Massimo Ercoli Date: Tue, 3 Nov 2020 21:17:24 +0100 Subject: [PATCH] HSEARCH-4043 Fork Company used for RestartChunkIT --- .../jsr352/massindexing/RestartChunkIT.java | 22 +++---- .../entity/SimulatedFailureCompany.java | 57 +++++++++++++++++++ 2 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/entity/SimulatedFailureCompany.java diff --git a/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/RestartChunkIT.java b/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/RestartChunkIT.java index 2315712badb..99ac3e1cba7 100644 --- a/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/RestartChunkIT.java +++ b/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/RestartChunkIT.java @@ -21,7 +21,7 @@ import org.hibernate.search.batch.jsr352.core.massindexing.MassIndexingJob; import org.hibernate.search.integrationtest.batch.jsr352.util.JobTestUtil; -import org.hibernate.search.integrationtest.batch.jsr352.massindexing.entity.Company; +import org.hibernate.search.integrationtest.batch.jsr352.massindexing.entity.SimulatedFailureCompany; import org.hibernate.search.integrationtest.batch.jsr352.util.BytemanHelper; import org.hibernate.search.integrationtest.batch.jsr352.util.PersistenceUnitTestUtil; import org.hibernate.search.mapper.orm.Search; @@ -70,7 +70,7 @@ public void setup() { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); for ( int i = 0; i < DB_COMP_ROWS; i++ ) { - em.persist( new Company( str[i % 5] + "-" + i ) ); + em.persist( new SimulatedFailureCompany( str[i % 5] + "-" + i ) ); } em.getTransaction().commit(); em.close(); @@ -158,7 +158,7 @@ public void failureDuringNonFirstCheckpointBetweenTwoWrites_fullScope() throws I action = "simulateFailure()" ) public void failureBeforeFirstRead_hql() throws InterruptedException, IOException { - doTest( "select c from Company c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); + doTest( "select c from SimulatedFailureCompany c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); } @Test @@ -184,7 +184,7 @@ public void failureBeforeFirstRead_hql() throws InterruptedException, IOExceptio ) }) public void failureDuringFirstCheckpointBetweenTwoWrites_hql() throws InterruptedException, IOException { - doTest( "select c from Company c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); + doTest( "select c from SimulatedFailureCompany c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); } @Test @@ -210,22 +210,22 @@ public void failureDuringFirstCheckpointBetweenTwoWrites_hql() throws Interrupte ) }) public void failureDuringNonFirstCheckpointBetweenTwoWrites_hql() throws InterruptedException, IOException { - doTest( "select c from Company c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); + doTest( "select c from SimulatedFailureCompany c where c.name like 'Google%'", DB_COMP_ROWS / 5, DB_COMP_ROWS / 5 ); } private void doTest(String hql, long expectedTotal, long expectedGoogle) throws InterruptedException, IOException { - SearchWorkspace workspace = Search.mapping( emf ).scope( Company.class ).workspace(); + SearchWorkspace workspace = Search.mapping( emf ).scope( SimulatedFailureCompany.class ).workspace(); workspace.purge(); workspace.refresh(); workspace.flush(); - assertEquals( 0, JobTestUtil.nbDocumentsInIndex( emf, Company.class ) ); - List google = JobTestUtil.findIndexedResults( emf, Company.class, "name", "Google" ); + assertEquals( 0, JobTestUtil.nbDocumentsInIndex( emf, SimulatedFailureCompany.class ) ); + List google = JobTestUtil.findIndexedResults( emf, SimulatedFailureCompany.class, "name", "Google" ); assertEquals( 0, google.size() ); // start the job MassIndexingJob.ParametersBuilder builder = MassIndexingJob.parameters() - .forEntities( Company.class ); + .forEntities( SimulatedFailureCompany.class ); if ( hql != null ) { builder = builder.restrictedBy( hql ); } @@ -253,8 +253,8 @@ private void doTest(String hql, long expectedTotal, long expectedGoogle) throws assertEquals( BatchStatus.COMPLETED, getMainStepStatus( execId2 ) ); // search again - assertEquals( expectedTotal, JobTestUtil.nbDocumentsInIndex( emf, Company.class ) ); - google = JobTestUtil.findIndexedResults( emf, Company.class, "name", "google" ); + assertEquals( expectedTotal, JobTestUtil.nbDocumentsInIndex( emf, SimulatedFailureCompany.class ) ); + google = JobTestUtil.findIndexedResults( emf, SimulatedFailureCompany.class, "name", "google" ); assertEquals( expectedGoogle, google.size() ); } diff --git a/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/entity/SimulatedFailureCompany.java b/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/entity/SimulatedFailureCompany.java new file mode 100644 index 00000000000..24489663d83 --- /dev/null +++ b/integrationtest/mapper/orm-batch-jsr352/src/test/java/org/hibernate/search/integrationtest/batch/jsr352/massindexing/entity/SimulatedFailureCompany.java @@ -0,0 +1,57 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.batch.jsr352.massindexing.entity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; + +@Entity +@Indexed +public class SimulatedFailureCompany { + + @Id + @GeneratedValue + @DocumentId + private int id; + + @FullTextField + private String name; + + public SimulatedFailureCompany() { + } + + public SimulatedFailureCompany(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "SimulatedFailureCompany [id=" + id + ", name=" + name + "]"; + } + +}