Skip to content

Commit

Permalink
HSEARCH-4043 Fork Company used for RestartChunkIT
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Nov 4, 2020
1 parent 0795a78 commit 348b13b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<Company> google = JobTestUtil.findIndexedResults( emf, Company.class, "name", "Google" );
assertEquals( 0, JobTestUtil.nbDocumentsInIndex( emf, SimulatedFailureCompany.class ) );
List<SimulatedFailureCompany> 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 );
}
Expand Down Expand Up @@ -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() );
}

Expand Down
@@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 + "]";
}

}

0 comments on commit 348b13b

Please sign in to comment.