Author: sannegrinovero
Date: 2010-05-30 16:47:31 -0400 (Sun, 30 May 2010)
New Revision: 19633
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
Log:
HSEARCH-534 circular graphs of IndexedEmbedded might break MassIndexer
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java 2010-05-28
23:42:47 UTC (rev 19632)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java 2010-05-30
20:47:31 UTC (rev 19633)
@@ -60,7 +60,6 @@
private final Map<Class<?>, DocumentBuilderIndexedEntity<?>>
documentBuilders;
private final MassIndexerProgressMonitor monitor;
- private static final int CLEAR_PERIOD = 50;
private final CacheMode cacheMode;
private final CountDownLatch producerEndSignal;
@@ -104,7 +103,7 @@
private void indexAllQueue(Session session) {
try {
- for ( int cycle=0; true; cycle++ ) {
+ while ( true ) {
List<?> takeList = source.take();
if ( takeList == null ) {
break;
@@ -116,11 +115,7 @@
session.buildLockRequest( LockOptions.NONE ).lock( take );
index( take, session );
monitor.documentsBuilt( 1 );
- session.evict( take );
- if ( cycle == CLEAR_PERIOD ) {
- cycle = 0;
- session.clear();
- }
+ session.clear();
}
}
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java 2010-05-28
23:42:47 UTC (rev 19632)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java 2010-05-30
20:47:31 UTC (rev 19633)
@@ -66,7 +66,7 @@
@ManyToOne(fetch=FetchType.LAZY,optional=false)
@Fetch(FetchMode.SELECT)
- @IndexedEmbedded
+ @IndexedEmbedded(depth=3)
public Nation getFirstPublishedIn() {
return firstPublishedIn;
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-05-28
23:42:47 UTC (rev 19632)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-05-30
20:47:31 UTC (rev 19633)
@@ -24,6 +24,8 @@
*/
package org.hibernate.search.test.batchindexing;
+import java.util.List;
+
import junit.framework.TestCase;
import org.apache.lucene.search.MatchAllDocsQuery;
@@ -66,6 +68,7 @@
createMany( Book.class, BOOK_NUM );
createMany( Dvd.class, DVD_NUM );
createMany( AncientBook.class, ANCIENTBOOK_NUM );
+ storeAllBooksInNation();
}
@Override
@@ -102,6 +105,24 @@
}
}
+ /**
+ * Adds all stored books to the Nation.
+ * Needed to test for HSEARCH-534 and makes the dataset to index quite bigger.
+ */
+ private void storeAllBooksInNation() {
+ FullTextSession fullTextSession = builder.openFullTextSession();
+ try {
+ Transaction tx = fullTextSession.beginTransaction();
+ List<Book> allBooks = fullTextSession.createCriteria( Book.class ).list();
+ Nation italy = (Nation) fullTextSession.load( Nation.class, 1 );
+ italy.getLibrariesHave().addAll( allBooks );
+ tx.commit();
+ }
+ finally {
+ fullTextSession.close();
+ }
+ }
+
public void testBatchIndexing() throws InterruptedException {
verifyResultNumbers(); //initial count of entities should match expectations
purgeAll(); // empty indexes
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java 2010-05-28
23:42:47 UTC (rev 19632)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java 2010-05-30
20:47:31 UTC (rev 19633)
@@ -24,12 +24,20 @@
*/
package org.hibernate.search.test.batchindexing;
+import java.util.HashSet;
+import java.util.Set;
+
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchMode;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.IndexedEmbedded;
@Entity
public class Nation {
@@ -37,6 +45,7 @@
private Integer id;
private String name;
private String code;
+ private Set<Book> librariesHave = new HashSet<Book>();
public Nation() {}
@@ -71,6 +80,17 @@
public void setCode(String code) {
this.code = code;
}
+
+ @IndexedEmbedded
+ @OneToMany(fetch=FetchType.LAZY)
+ @Fetch(FetchMode.SELECT)
+ public Set<Book> getLibrariesHave() {
+ return librariesHave;
+ }
+ public void setLibrariesHave(Set<Book> librariesHave) {
+ this.librariesHave = librariesHave;
+ }
+
}
Show replies by date