[hibernate-commits] Hibernate SVN: r15531 - search/trunk/src/test/org/hibernate/search/test/worker/duplication.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Nov 7 06:58:00 EST 2008


Author: hardy.ferentschik
Date: 2008-11-07 06:58:00 -0500 (Fri, 07 Nov 2008)
New Revision: 15531

Modified:
   search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
Log:
HSEARCH-293 - added test case

Modified: search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java	2008-11-07 10:32:33 UTC (rev 15530)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java	2008-11-07 11:58:00 UTC (rev 15531)
@@ -2,6 +2,7 @@
 package org.hibernate.search.test.worker.duplication;
 
 import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexReader;
@@ -13,6 +14,13 @@
 import org.hibernate.Transaction;
 import org.hibernate.search.FullTextQuery;
 import org.hibernate.search.FullTextSession;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.backend.AddLuceneWork;
+import org.hibernate.search.backend.DeleteLuceneWork;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.impl.SearchFactoryImpl;
 import org.hibernate.search.reader.ReaderProvider;
 import org.hibernate.search.store.DirectoryProvider;
 import org.hibernate.search.test.SearchTestCase;
@@ -86,6 +94,44 @@
 		s.close();
 	}
 
+	/**
+	 * Tests that adding and deleting the same entity only results into a single delete in the work queue.
+	 * See HSEARCH-293.
+	 *
+	 * @throws Exception in case the test fails.
+	 */
+	@SuppressWarnings( "unchecked" )
+	public void testAddWorkGetReplacedByDeleteWork() throws Exception {
+		FullTextSession fullTextSession = org.hibernate.search.Search.getFullTextSession( openSession() );
+		SearchFactoryImpl searchFactory = ( SearchFactoryImpl ) fullTextSession.getSearchFactory();
+		DocumentBuilder builder = searchFactory.getDocumentBuilder( SpecialPerson.class );
+
+		// create test entity
+		SpecialPerson person = new SpecialPerson();
+		person.setName( "Joe Smith" );
+
+		EmailAddress emailAddress = new EmailAddress();
+		emailAddress.setAddress( "foo at foobar.com" );
+		emailAddress.setDefaultAddress(true);
+
+		person.addEmailAddress( emailAddress );
+
+		List<LuceneWork> queue = new ArrayList<LuceneWork>();
+
+		builder.addWorkToQueue( SpecialPerson.class, person, 1, WorkType.ADD, queue, searchFactory );
+
+		assertEquals("There should only be one job in the queue", 1, queue.size());
+		assertTrue("Wrong job type", queue.get(0) instanceof AddLuceneWork );
+
+		builder.addWorkToQueue( SpecialPerson.class, person, 1, WorkType.DELETE, queue, searchFactory );
+
+		assertEquals("There should only be one job in the queue", 1, queue.size());
+		assertTrue("Wrong job type. Add job should have been replaced by delete.", queue.get(0) instanceof DeleteLuceneWork );
+
+		fullTextSession.close();
+	}	
+
+
 	protected Class[] getMappings() {
 		return new Class[] { Person.class, EmailAddress.class, SpecialPerson.class };
 	}




More information about the hibernate-commits mailing list